Ising model simulation
A first result from my little Javascript tinkering. Much to do but it’s always nice to have a working first thing.
4 posts in June 2023
A first result from my little Javascript tinkering. Much to do but it’s always nice to have a working first thing.
I’m writing a little browser toy where I calculate a model in the background and render it frequently. Think something like an animated cellular automaton.
Rendering is easy in modern browsers: you just use requestAnimationFrame and hopefully it’ll call your code once per screen refresh or at least as fast as it can manage.
But how do you do background compute work in Javascript in 2023? I want it to run as fast as possible (ie, 100% CPU for the browser tab) but still be smooth and responsive. I think the right answer is “web workers” but then that requires the overhead of passing the calculations back and forth via messages (and JSON serialization?!).
Here’s some other things I tried for background Javascript work. I tested using a calculate function which executes in well under 1ms.
setInterval to fire off the calculation: 4ms is the minimum allowed in modern browsers, limiting you to 250 calculations / second.setTimeout, but overhead means it’s more like 5.2ms in practice.requestIdleCallback. I had high hopes for this but in practice I’m getting called every 11.1ms or 90 updates / second. Turns out that’s my screen refresh rate and the idle callback rate changes if I update the display driver refresh. It’s like VBlank interrupts in 2023 only about nineteen layers removed from the hardware.I think in practice setInterval will work for me; my calculations are likely to take a few milliseconds and anyway I don’t want it to run “too fast” because it won’t be visible. Still kinda wacky this is so hard in 2023. Web workers are probably the right way if I need faster than 4ms.
// Calculation loop using idle callbacks
function calculate_idle() {
calculate();
window.requestIdleCallback(calculate_idle);
}
// Calculation loop using ersatz sleeps. Note 4ms is minimum here.
async function calculate_sleep(interval) {
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
while (1) {
calculate();
await new Promise(r => setTimeout(r, interval));
}
}
switch (mode) {
case "idle":
// Seems to be every 11ms per quick testing in Chrome
calculate_idle();
break;
case "interval":
// Browsers seem to make 4ms the minimum interval
setInterval(calculate, 1);
break;
case "spin":
while (1) {
calculate();
}
break;
case "sleep":
calculate_sleep(0);
break;
}
Ever since I started using Starlink I noticed that sometimes it drops out for 100-1000ms, maybe a couple of times an hour? I used to think it was just my site (I have some very minor obstructions, well under 1%) but enough other folks complain online about it now that I think these microoutages are just a weakness of Starlink’s Internet service.

That’s a graph of 24 hours of outages data, as reported via Dishy’s gRPC. It’s the same thing Starlink shows textually in its “Outages” mobile app tab. From what I’ve read the “Obstructed” tag doesn’t necessarily mean obstructed; it’s a catch all for “unexplained outage”. This graph shows 59s of obstructed, 30s of no pings, 50s of no downlink, and 12s of “no schedule” which is Starlink’s semi-regular 4am outage.
All told it adds up to 151 seconds of outages, or 99.8% uptime. Over a month I measured 99.3% uptime.
Two nines isn’t very impressive for an ISP, in my opinion, although it’s within the parameters promised by Starlink. Maybe it is impressive for a wireless ISP though, or a satellite one. I hope it improves but it’s not awful now.
The main way I notice is if I’m playing an online game; I’ll get a lag spike until the game recovers. Fortunately the outages don’t break TCP connections, either the packet shows up eventually or else TCP retransmits fix it. It also causes problem with live video and audio streams, like a Zoom call. But it’s only a second or two every 30 minutes, not terrible. You won’t notice it at all with web browsing and it will hardly affect bulk download speeds.
I have no idea what’s going wrong but could imagine many explanations. One common theory that seems wrong is that Starlink drops out every time it hands off satellites. I don’t think that’s the case. It’s potentially doing a handoff every 15 seconds, and seems to be every 5-10 minutes in ordinary usage. It’d be intolerable if every time it did that the Internet went away for a quarter second. Actual performance is much better than that. (IIRC Dishy is able to track a primary satellite and a backup, which probably helps with a smooth handoff.)
Not my own data, but a couple of Reddit threads (also) are users reporting being throttled to 50Mbps download after using a certain amount of bandwidth in a short time. I think I’ve seen this myself but haven’t tried to measure it. One user’s guess:
This is 100% a hard throttle that can be triggered at will and is repeatable. It slows entire starlink service down to 50mbit. Even if it’s middle of the night!!! It then resets after the hour and the cycle repeats as follows.
-Start download -download at 120 for 15 mins -drops to 50 for remaining 45 minutes -returns to full speed for 15 mins -drops to 50 for remaining 45 minutes.
Seems to be 1 hour cycles, 15 mins of full speed followed by the remaining 45 throttled.
A lot of folks are pointing out how clumsy this is, particularly at 2am when there’s spare capacity. I don’t think this explains the better performance I’ve been seeing since March. I think it was added newer and isn’t the most effective of measures they’re using. But I’m totally guessing here.
Update: I haven’t seen any evidence of this at my own site but I would have only noticed around June 12/13 when I did some big downloads. Diablo 4 downloaded 85GB at an average speed of 150Mbps, no evidence of throttling. (at 8am Tuesday the 13th, a quiet time). Some of the reports on Reddit have definitely looked like a 50Mbps cap, I believe them, but the reports aren’t consistent. Maybe it’s something they’re testing or only doing to some users.
Update 2: a Reddit thread of someone getting a response from Starlink Support (in Poland) saying they are throttled because they used too much data, over 1TB.