Skip to content

Commit 60e0b2a

Browse files
committed
wip nfc explain/assert random spread
1 parent c92bfb2 commit 60e0b2a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/model/store.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,16 @@ class PerAccountStore extends PerAccountStoreBase with
764764
// so as to fully pick up the new server's features.
765765

766766
if (_postRestartTimer != null) return;
767+
// Spread the reload out randomly in time, to avoid a thundering herd
768+
// of clients hitting the server with reload requests.
767769
const minWaitMs = 1 * Duration.millisecondsPerMinute;
768770
const maxWaitMs = 1 * Duration.millisecondsPerHour;
771+
// The random spread should cover at least 5 minutes;
772+
// see https://zulip.com/api/get-events#restart .
773+
assert(maxWaitMs - minWaitMs >= 5 * Duration.millisecondsPerMinute);
769774
final waitMs = minWaitMs + Random().nextInt(maxWaitMs - minWaitMs + 1);
770775
final waitDuration = Duration(milliseconds: waitMs);
776+
771777
_postRestartTimer = Timer(waitDuration, _postRestart);
772778
}
773779

0 commit comments

Comments
 (0)