Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1c49c02 authored by Dan Egnor's avatar Dan Egnor
Browse files

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.
parent 824838d7
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -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;
    }