mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
analytics: Slew record reporting by up to 10 minutes.
This reduces the giant load spike at 5 minute past the hour, when all remote servers currently attempt to submit their records. We do not wish to slew over a full hour, because we want to ensure that we do not hold the lock when the next hour's analytics runs. It is also not necessary to have that much variation; 10 minutes is picked as an arbitrary "long enough" time to spread requests over.
This commit is contained in:
committed by
Tim Abbott
parent
85cc8b6a20
commit
b363999d19
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import os
|
||||
import time
|
||||
from argparse import ArgumentParser
|
||||
@@ -96,4 +97,13 @@ class Command(BaseCommand):
|
||||
logger.info("Finished updating analytics counts through %s", fill_to_time)
|
||||
|
||||
if settings.PUSH_NOTIFICATION_BOUNCER_URL and settings.SUBMIT_USAGE_STATISTICS:
|
||||
# Skew 0-10 minutes based on a hash of settings.ZULIP_ORG_ID, so
|
||||
# that each server will report in at a somewhat consistent time.
|
||||
assert settings.ZULIP_ORG_ID
|
||||
delay = int.from_bytes(
|
||||
hashlib.sha256(settings.ZULIP_ORG_ID.encode()).digest(), byteorder="big"
|
||||
) % (60 * 10)
|
||||
logger.info("Sleeping %d seconds before reporting...", delay)
|
||||
time.sleep(delay)
|
||||
|
||||
send_analytics_to_push_bouncer()
|
||||
|
||||
Reference in New Issue
Block a user