Servers: sockets, pauses, capacity
16 to 17 Nov 2026
- Competitive US West games now run on a $28-a-month box with one core and a real clock. At p99, a tick starts 1.6 to 2.4 ms late.
- We switched to uWebSockets.js and send each player one write per tick. The CPU cost of a game tick fell from 0.204 to 0.137 ms.
- The bots’ map data is now built ahead of time in 3 ms pieces. The box went from 4 to 8 games of 4 v 4 within our timing bar, and it was 23% busy.
- The TLS proxy uses 30 to 38% of the box’s CPU. A seat costs $28 ÷ 64 = about $0.44 a month, shared by everyone who plays in it.
On a small box the limit is the longest pause on the event loop, not the average CPU. Profile the pauses, and count messages rather than bytes.
Cloudflare’s rooms could not keep a 60 Hz game clock on time. A plain Node process on a small box can, because its timer follows real time. We moved competitive US West games to one box with one virtual CPU and 1.6 GB of memory for $28 a month. Everything else stayed on Cloudflare. Then we measured how many games one core can run. The wiki page Servers and deploys describes the setup as it is today.
Measured how: we ran the room benchmark and a load test on the box itself. The test used a spare copy of the live build behind its own copy of the TLS proxy, with scripted players running on the same box, 3 minutes per step. We threw away any window that had live players or a deploy in it. A run passed our timing bar if, at p99, ticks started less than 4 ms late and no tick was more than 16 ms late, if the time a step took met the same two limits, and if there was less than one gap over 50 ms per minute.
| Measured on the box | Before | After |
|---|
| CPU per game tick, 8 people (ws to uWebSockets.js, one write per player per tick) | 0.204 ms | 0.137 ms (0.82% of the core) |
| CPU per game tick, 1 person and 7 Expert bots | 0.368 ms | 0.252 ms |
| Garbage collections per minute, one game of 8 | 22 | 14 |
| Games of 4 v 4 within the timing bar (bot data built ahead between ticks) | 4 | 8 (box 23% busy, longest pause 14.3 ms) |
| Bot games within the bar | none | 4 (8 fail on one 32 ms collection) |
| Ticks late at p99, 4 to 16 games | | 1.6 to 2.4 ms |
One core, 16 and 17 Nov 2026. Everything sent hashed the same on ws and on uWebSockets.js. Every table is in the wiki: Server and room measurements.
CPU was never the limit. With 8 games running, the box was only a quarter busy. The limit was single long pauses on the one event loop that every game shares. Three things paused it: building the bots’ map data in one step when the map changed (20 to 258 ms), waiting for the core while sending, and garbage collection. The fix builds the next map’s bot data ahead of time, in 3 ms pieces between ticks.
The TLS proxy (Caddy) used 30 to 38% of the CPU. A seat’s cost is the box’s price divided by the seats it holds at once: $28 ÷ 64 (8 games of 8) = about $0.44 a month. Everyone who plays in that seat during the month shares it, so it is not a cost per player. Without the proxy, a one-core box passed the bar with 12 games of 8 on 17 Nov, which is $28 ÷ 96 = about $0.29 a seat. Each player uses 11.5 to 12 KB/s on the wire.
What didn’t work
- A larger young generation for the garbage collector: with bots there were still 34 to 40 minor collections a minute.
- Skipping the plain map’s physics hooks for each body: this saved about 2%, and each hook is guarded by state that a powerup can change.
- Smaller snapshots: they saved about 29% of the bytes, but the rounding broke prediction, and most of the bytes were headers anyway.
- The Rust prototype on the box: its build failed on the box’s newer C library header. That is fixed now; the numbers come when the run is finished.
Still failing: one piece of the bot data takes 14 to 29 ms, and with 8 bot games one garbage collection still pauses the box too long. Not measured yet: the round trip (the scripted players share the core with the server), more than one core, and real networks.
Reuse
- On one event loop, profile the longest pauses, not the average. One 30 ms step makes every game on the box miss its ticks.
- Count messages, not bytes. Sending one write per client per tick cut the sending cost more than any change to the encoding would have.
- Load-test on the real box with a spare process, and add a guard that gives way to live players.
All the numbers are in the wiki: Server and room measurements.