title: Strange lags while app syncing
body: <p>I am developing big app which every X minutes(for tests say 5 minutes) is calling by AlarmManger:</p>
  
  <pre><code>mAlarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextSyncTime.getMillis(), PendingIntent.getBroadcast(this, INTERVAL_SYNC_SERVICE_REQ_CODE, new Intent(SYNC_ACTION), PendingIntent.FLAG_UPDATE_CURRENT));
  </code></pre>
  
  <p>Class ScheduledRecevier is listening for SYNC_ACTION and launching IntentService. During this service are called multiple (around 25) API using retrofit2 to the same server. One by one - when one is finished with downloading and writing to Datebase another is launched. And so on. </p>
  
  <p>My problem is that while I am not using device this process last different periods. I mean: most of if time it is about 2 minutes, max 3, but sometimes (8-16 times per day) it last about 10 minutes :O</p>
  
  <p>Here is log:</p>
  
  <pre><code>11:23:09.064 8388-8388/myApp V/ScheduledReceiver: Sync from alarm
  11:23:09.154 8388-9007/myApp V/SynchronizationService: Sync started
  11:23:10.474 8388-9007/myApp V/Sync1: Sync completed
  11:23:10.604 8388-9007/myApp V/Sync2: Sync completed
  11:23:10.724 8388-9007/myApp V/Sync3: Sync completed
  11:23:11.555 8388-9007/myApp V/Sync4: Sync completed
  11:23:11.766 8388-9007/myApp V/Sync5: Sync completed
  11:24:18.248 8388-9007/myApp V/Sync6: Sync completed
  11:24:18.496 8388-9007/myApp V/Sync7: Sync completed
  11:25:19.813 8388-8399/myApp I/art: Background sticky concurrent mark sweep GC freed 127447(6MB) AllocSpace objects, 3(204KB) LOS objects, 37% free, 11MB/19MB, paused 1.257ms total 104.434ms
  11:26:27.355 8388-9007/myApp V/Sync8: Sync completed
  11:31:20.562 8388-8388/myApp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2d78961 time:67843774
  11:31:22.592 8388-8388/myApp I/Timeline: Timeline: Activity_launch_request id:com.santander.msantander time:67845808
  11:31:22.722 8388-8388/myApp D/SecWifiDisplayUtil: Metadata value : SecSettings2
  11:31:22.852 8388-8388/myApp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@efae967 time:67846063
  11:31:24.642 8388-8388/myApp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2d78961 time:67847852
  11:31:30.302 8388-9007/myApp V/Sync9: noUpdate
  11:31:30.472 8388-8399/myApp I/art: Background sticky concurrent mark sweep GC freed 245773(8MB) AllocSpace objects, 0(0B) LOS objects, 29% free, 20MB/28MB, paused 1.481ms total 156.454ms
  11:31:30.982 8388-9007/myApp V/Sync10: Sync completed
  
  BEGIN_DATE  
  2017-02-24 11:23:07.617
  END_DATE
  2017-02-24 11:31:32.303
  
  11:36:35.162 8388-8388 /myApp V/ScheduledReceiver: Sync from alarm
  11:36:35.172 8388-13586/myApp V/SynchronizationService: Sync started
  11:36:37.202 8388-13586/myApp V/Sync1: Sync completed
  11:36:37.392 8388-13586/myApp V/Sync2: Sync completed
  11:36:37.572 8388-13586/myApp V/Sync3: Sync completed
  11:36:38.232 8388-13586/myApp V/Sync4: Sync completed
  11:36:38.482 8388-13586/myApp V/Sync5: Sync completed
  11:36:39.812 8388-13586/myApp V/Sync6: Sync completed
  11:36:40.072 8388-13586/myApp V/Sync7: Sync completed
  11:36:40.632 8388-13586/myApp V/Sync8: Sync completed
  11:36:49.432 8388-8399/ myApp I/art: Background sticky concurrent mark sweep GC freed 266493(10MB) AllocSpace objects, 1(68KB) LOS objects, 40% free, 15MB/26MB, paused 1.661ms total 125.890ms
  11:36:54.392 8388-8399/ myApp I/art: Background partial concurrent mark sweep GC freed 301387(10MB) AllocSpace objects, 1(68KB) LOS objects, 50% free, 15MB/31MB, paused 1.572ms total 145.270ms
  11:36:56.992 8388-13586/myApp V/Sync9: noUpdate
  11:36:57.172 8388-13586/myApp V/Sync10: Sync completed
  
  
  BEGIN_DATE
  2017-02-24 11:36:34.180
  END_DATE
  2017-02-24 11:37:00.540
  </code></pre>
  
  <p>For simplicity I called called to APIs SyncX to show that this is the same path in both cases. I omitted rest of syncing and pasted what logged to datebase as syncing start time and end time.</p>
  
  <p>As you can see in first case at 11:23 sync beginned from alarm and ended at 11:31. In the second case it has started at 11:36 and ended at 11:37</p>
  
  <p>In both cases there was the same portion of data. All syncs have similar process: drop table, create table, insert new data (collection delete is not working in such big portion of data to exchange). Sync7,Sync8,Sync9 are not different in this.</p>
  
  <p>Anyone has any idea how to improve this to have short times? All calls are with login and password from local database and needs to be called directly from the app to reach the server (secure work space).</p>