Use setRepeating() rather than setInexactRepeating() for backup scheduling,
and add some random fuzz to the scheduling times, to make sure we aren't creating hour-aligned server load spikes. See bug 2226553 for details & Dr. No information.
This commit is contained in:
@ -76,6 +76,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
class BackupManagerService extends IBackupManager.Stub {
|
||||
private static final String TAG = "BackupManagerService";
|
||||
@ -85,6 +86,9 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
// trigger an immediate pass.
|
||||
private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR;
|
||||
|
||||
// Random variation in backup scheduling time to avoid server load spikes
|
||||
private static final int FUZZ_MILLIS = 5 * 60 * 1000;
|
||||
|
||||
// The amount of time between the initial provisioning of the device and
|
||||
// the first backup pass.
|
||||
private static final long FIRST_BACKUP_INTERVAL = 12 * AlarmManager.INTERVAL_HOUR;
|
||||
@ -1949,9 +1953,15 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
}
|
||||
|
||||
private void startBackupAlarmsLocked(long delayBeforeFirstBackup) {
|
||||
long when = System.currentTimeMillis() + delayBeforeFirstBackup;
|
||||
mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, when,
|
||||
BACKUP_INTERVAL, mRunBackupIntent);
|
||||
// We used to use setInexactRepeating(), but that may be linked to
|
||||
// backups running at :00 more often than not, creating load spikes.
|
||||
// Schedule at an exact time for now, and also add a bit of "fuzz".
|
||||
|
||||
Random random = new Random();
|
||||
long when = System.currentTimeMillis() + delayBeforeFirstBackup +
|
||||
random.nextInt(FUZZ_MILLIS);
|
||||
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when,
|
||||
BACKUP_INTERVAL + random.nextInt(FUZZ_MILLIS), mRunBackupIntent);
|
||||
mNextBackupPass = when;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user