Chrome alarms unexpectedly synchronised with clock time

365 views
Skip to first unread message

Peter Bloomfield

unread,
May 9, 2024, 5:56:31 AM5/9/24
to Chromium Extensions
We've noticed an unexpected behaviour in the timing of Chrome alarms. Our extension uses an alarm to upload data to a server every 5 minutes. From reading the API documentation, it looks like it should trigger roughly every 5 minutes from when the alarm was created, or from when the extension last started, meaning the actual trigger times should generally vary from one device to the next.

However, it actually seems to tend towards 5 minute intervals according to the system clock. For example, it generally ends up triggering at about 1pm, 1.05pm, 1.10pm, and so on.

Is this intentional behaviour, and is there any way to prevent it from falling into that pattern?

This is causing us some issues at scale because it means our server is receiving a sudden spike of traffic every 5 minutes. The spike is short but very high. If we could prevent the alarm from falling into that pattern then the traffic would be more spread out.

Oliver Dunk

unread,
May 9, 2024, 6:12:55 AM5/9/24
to Peter Bloomfield, Chromium Extensions
Hi Peter,

I was just replying to another question about alarms when I saw this... seems that's the topic for the day!

I'm not aware of any behavior intended to align alarms. There are some interesting quirks with the API, though, which I could imagine causing this.

A couple of thoughts for possible candidates:
  • Starting in Chrome 123, alarms 'run' while a device is sleeping. It's possible many of your devices are asleep when an alarm is intended to fire, essentially queuing it up. Then many devices are started at the same time (say 9AM when the school day starts), they all fire, and the alarms are then aligned to that.
  • There is currently some behavior (which isn't ideal) where the throttling to avoid too many alarms at once can cause one alarm to influence another. Do you have any other alarms scheduled that do make sense with this sort of alignment? If so, perhaps they could be causing this.
Assuming one of these makes sense, perhaps you could add a random (short, less than 30 seconds) delay with setTimeout once an alarm fires to spread out the requests?
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/c1d9693f-32d7-4927-a748-9e9da9e6b0b4n%40chromium.org.

Jackie Han

unread,
May 9, 2024, 6:20:57 AM5/9/24
to Oliver Dunk, Peter Bloomfield, Chromium Extensions
Alarm has a fixed expected time (`alarm.scheduledTime`), although in practice there may be interference and delay. You can calculate the expected time like this

But I am not sure what is your extension behavior on different devices, anyway you can add a random delay to avoid it:

chrome.alarms.create(
    alarmName,
    {
        delayInMinutes: a-random-value // > 0.5 minute and < 5 minutes
        periodInMinutes: 5
    }
)

Peter Bloomfield

unread,
May 10, 2024, 11:46:31 AM5/10/24
to Chromium Extensions, Jackie Han, Peter Bloomfield, Chromium Extensions, Oliver Dunk
It turns out I was misinformed and the Chrome alarms aren't synchronising after all. The telemetry I was shown actually came from an unrelated system. Thanks for your replies though, and sorry for wasting your time.
Reply all
Reply to author
Forward
0 new messages