Polling vs SSE vs WebSocket for a live dashboard: bytes, delay, threads and proxies, measured
A monitoring page shows numbers that change on their own: requests per second, latency, GPU power, a sparkline per backend. The page has to learn about every new sample, and there are three common ways to do that. It can poll: ask for the whole status every few seconds. The server can keep a Server-Sent Events (SSE) stream open, a plain HTTP response that never ends, and write one event per sample. Or the page and server can open a WebSocket and the server writes one message per sample. (WebSocket vs SSE vs long-polling vs MQTT measures the transports themselves with small events; this article is about one real-sized dashboard.)
The starting point is a real page: a load balancer’s dashboard polls its status every 3 s and receives 299,618 bytes of uncompressed JSON each time, while the data under it changes every 5 s. The question is what keeps such a page smooth and cheap, measured on one dashboard with the same data sent every way.
Everything below was measured on one machine, in Docker, through nginx with TLS, against a status of the same size and shape. Every update carries its sequence number and the time its sample was taken. Two checks run on every client: the number of new samples each tab received in its measured window equals the number the server took (74,844 updates; the only cells short of it are proxy-default-buffering, the proxy misconfiguration below, where no update arrived at all), and on the change streams every event must follow the one before it, because a missing change would corrupt the page (35,532 changes, 0 out of order or missing). A poll that brings a sample the page already has is not an error; it is counted, and it is the waste polling is measured for.
| Setup | Details |
|---|---|
| Server | Python 3.13.9, standard library only: one ThreadingHTTPServer process, one thread per open connection, as small Python gateways are written · a sampler thread takes one sample every 5 s (and every 1 s in one section), serialises the full status and the change once, and wakes every open stream · /status for polling (with an ETag), /stream for SSE (Last-Event-ID resume), /ws for WebSocket: handshake, framing and permessage-deflate written by hand on zlib (the standard library has no WebSocket), about 130 lines · one core |
| Data | 16 backends × 10 metrics, each with a 334-point history ring: 299,471 B of JSON, 102.7 kB gzipped (level 6) · full: the whole status every sample · change: the new point of every ring and the current figures, 2.5 kB · values random-walk from a fixed seed |
| Proxy | nginx 1.28.0, one worker, TLS 1.3, ECDSA P-256, no session resumption · HTTP/1.1 on one port, HTTP/2 on another · nginx defaults unless a row says otherwise: proxy_http_version 1.0 to the upstream, proxy_buffering on, proxy_read_timeout 60s, gzip_comp_level 1 where gzip is on · one core |
| Clients | Go 1.26.10, net/http and github.com/coder/websocket v1.8.14 · every tab on its own TLS connection unless a row says it shares one · bytes counted on each TCP connection: TLS records and everything inside them, both directions; not the IP and TCP headers or bare acknowledgements · Chromium 158.0.8127.18 headless (Playwright 1.65.0) for the time to draw and the connection limit · 2 cores and their SMT siblings |
| CPU | AMD Ryzen AI Max+ 395, Linux 7.0 · cores 12–15 and their SMT siblings reserved: for the length of the run every other process on the machine, including the other work that kept running (a CI build among it), was limited to the other cores (systemd AllowedCPUs) · server on core 12, nginx on 13, clients on 14–15 · the SMT siblings of the server’s and nginx’s cores left idle |
| Method | Every cell is a fresh client process, run 3 times (the connection-limit and idle cells 4 times, the 20 s timeout check 3; the Chromium version is read once per browser launch, 2 launches) · a 30 s window that starts half a sample period after a sample, so it holds exactly 6 samples · reported value: the median of the runs’ own values (for delays: of the per-run medians), with the lowest and highest run where they differ · delay: the sample’s timestamp in the payload against the client’s clock, the same clock (one machine) · server CPU: the Python process’s own user + system time over the window · nginx CPU: its container’s cgroup over the same window |
The scoreboard
| One sample every 5 s | Poll 3 s | Poll 3 s, gzip + ETag (weak compare) | SSE, change | SSE, change, gzip | WebSocket, change, deflate |
|---|---|---|---|---|---|
| Bytes per second into one tab | 99,969 | 24,046 | 512 | 112 | 111 |
| Sample → parsed, median | 1.87 s | 1.95 s | 10.2 ms | 10.0 ms | 10.6 ms |
| Sample → drawn in Chromium, median | 1.40 s | not measured | 14.0 ms | 13.0 ms | 12.0 ms |
| Python CPU at 100 tabs | 0.9 % | 0.7 % | 0.3 % | 0.6 % | 0.6 % |
| Threads at 100 tabs | 3 | 3 | 103 | 103 | 103 |
| Back after 30 s offline | next poll | next poll | 16.5 kB, resumed | 104 kB, snapshot | 104 kB, snapshot |
| nginx needs | nothing | gzip_types | X-Accel-Buffering: no | same | Upgrade headers, a ping inside 60 s |
| Tabs per origin on HTTP/1.1 | 6 at a time, short | same | 6, the rest hang | same | 8 of 8 tried |
Pushing only the change is 195× cheaper in bytes than the poll the page started with, and shows a new sample 183× sooner. SSE and WebSocket are within a few bytes and a millisecond of each other in every measure; what tells them apart is what sits around them: reconnecting, proxies, and the browser’s connection limit.
Bytes per open tab
Each poll carries the whole status, and the page has no way to know that it has not changed: a 3 s poll moves 299,908 B every 3 s, 99,969 B/s, and a 1 s poll three times that, 299,677 B/s. With a new sample every 5 s, 4 of every 10 polls at 3 s bring a status the page already has, and 24 of every 30 at 1 s.
A stream sends the full status once, when the tab connects, and then only what changed: the newest point of every ring, 2,560 B per sample on SSE, 2,546 B on WebSocket, 512 and 509 B/s. The difference is SSE’s text framing (id: 7\ndata: and the blank line) against WebSocket’s 4-byte header. Streaming the full status every sample is possible too, and costs 60,082 B/s: the stream removes the polls that bring nothing, not the size of the payload. The size is removed by sending the change.
Compression helps both, by different amounts: the full status shrinks 2.9× (gzip level 6, 102,490 B per sample), the change 4.6× (558 B), because 32 kB of history is enough for zlib to find the metric names and the number patterns in every event.
The upstream direction is small everywhere: 40 B/s for the 3 s poll’s requests (119 B each from this Go client; a browser’s, with cookies, is often a kilobyte), nothing on a stream once it is open beyond TCP’s own acknowledgements, which are not counted here.
Polling with an ETag, and how nginx breaks it
A conditional poll sends back the ETag of the last status it got; the server answers 304 Not Modified with no body when the status has not changed. With a sample every 5 s and a poll every 3 s, 4 polls in 10 can be 304s.
| Poll every 3 s, 1 tab | Bytes/s | 304s / polls in a run (window and warm-up) | nginx CPU at 100 tabs |
|---|---|---|---|
| no ETag | 99,969 | 0 / 12 | 0.9 % |
| ETag, no gzip (the strict and the weak compare agree) | 60,001 | 4 / 12 | 0.7 % |
| gzip, no ETag | 40,077 | 0 / 12 | 8.1 % |
| gzip + ETag, server compares strictly | 40,039 | 0 / 12 | 8.1 % |
| gzip + ETag, server compares weakly | 24,046 | 4 / 12 | 4.9 % |
| poll every 1 s, gzip + ETag, weak | 24,112 | 27 / 35 | 6.0 % |
The poll counts cover the whole client run, the 30 s window and the polls before it; the bytes cover only the window. Inside the window the weak-compare rows carry 6 bodies, one per sample: 721,382 B in 30 s is 6 of nginx’s level-1 gzip bodies of 120,231 B.
The strict row is a trap that the first run of this benchmark fell into. nginx’s gzip filter changes the response, so it marks the ETag as weak on the way out: "41" becomes W/"41". The browser sends W/"41" back in If-None-Match, and a server that compares the strings byte for byte never matches: every poll gets the whole status, and nginx compresses every copy. For If-None-Match the HTTP specification (RFC 9110, 13.1.2) asks for the weak comparison, which ignores the W/ prefix. With it, a 304 costs nginx nothing to compress and the bytes fall to those of the polls that bring a new sample.
With a working ETag the poll interval stops costing bytes: polling every second moves the same 24,112 B/s as polling every 3 s, because the body is sent only once per sample either way. What remains is the requests themselves and the delay.
Delay from sample to screen
A pushed sample is parsed 10.2 ms after it was taken, and nearly all of that is the server: serialising the 299 kB full status for the next tab that connects takes 9.9 ms (9.1 ms–10.7 ms) of Python before the 2.5 kB change goes out, and the sampler does both before it wakes the streams. The transport adds about a millisecond, the same on SSE and WebSocket.
A poll sees a new sample at the next poll after it: on average half an interval later, at most a whole interval. Measured, 1.87 s at 3 s and 875 ms at 1 s. Within one run the poll timer and the sampler keep their phase, so the spread is between runs: at 1 s the run medians lie between 875 ms (847 ms–879 ms). The status changes every 5 s and the page asks every 3 s, so the gaps between changes on screen alternate between 3 s and 6 s.
In Chromium the same holds to the frame. From the sample being taken to the browser having painted it:
| Chromium, one tab | Sample → drawn, median | p95 | JSON.parse | apply + draw | Main thread busy per second |
|---|---|---|---|---|---|
| poll 3 s | 1.40 s | 2.39 s | 0.8 ms | 0.5 ms | 1.8 ms |
| poll 1 s, gzip + ETag | 640 ms | 681 ms | 0.8 ms | 0.6 ms | 2.2 ms |
| SSE, full status | 17.0 ms | 18.0 ms | 0.9 ms | 0.6 ms | 1.5 ms |
| SSE, change | 14.0 ms | 15.0 ms | 0.1 ms | 0.8 ms | 1.0 ms |
| SSE, change, gzip | 13.0 ms | 14.0 ms | 0.1 ms | 0.7 ms | 1.0 ms |
| WebSocket, full status | 15.0 ms | 17.0 ms | 0.9 ms | 0.5 ms | 1.3 ms |
| WebSocket, change | 14.0 ms | 15.0 ms | 0.1 ms | 0.8 ms | 1.0 ms |
| WebSocket, change, deflate | 12.0 ms | 13.0 ms | 0.0 ms | 0.8 ms | 0.9 ms |
The page’s own work is not where the time goes: V8 parses 299 kB of JSON in about a millisecond, and redrawing 16 rows and their sparklines takes another. On this machine the browser’s cost of the dashboard is a millisecond or two of main-thread time per second whichever way the data arrives; slower devices were not measured.
One, ten and a hundred tabs
| 100 tabs, one sample every 5 s | Python CPU | nginx CPU | Python threads | Python memory | Delay, median | Delay, p95 |
|---|---|---|---|---|---|---|
| poll 3 s | 0.9 % | 0.9 % | 3 | 31 MB | 1.96 s (1.94 s–1.97 s) | 3.01 s |
| poll 1 s | 2.0 % | 2.6 % | 3 | 31 MB | 941 ms (905 ms–1,000 ms) | 996 ms |
| poll 1 s, gzip + ETag (strict) | 2.1 % | 23.8 % | 3 | 27 MB | 308 ms (294 ms–1.10 s) | 378 ms |
| poll 1 s, gzip + ETag (weak) | 1.7 % | 6.0 % | 3 | 27 MB | 1.12 s (1.11 s–1.16 s) | 1.19 s |
| SSE, full status | 0.4 % | 0.7 % | 103 | 88 MB | 86.8 ms | 142 ms |
| SSE, change | 0.3 % | 0.1 % | 103 | 87 MB | 11.6 ms | 14.7 ms |
| SSE, change, gzip | 0.6 % | 0.1 % | 103 | 112 MB | 19.9 ms | 28.1 ms |
| SSE, full, gzip | 33.2 % | 0.4 % | 103 | 113 MB | 1.62 s | 1.97 s |
| WebSocket, full status | 0.4 % | 0.6 % | 103 | 59 MB | 99.7 ms | 155 ms |
| WebSocket, change | 0.3 % | 0.1 % | 103 | 59 MB | 11.5 ms | 13.2 ms |
| WebSocket, change, deflate | 0.6 % | 0.1 % | 103 | 82 MB | 20.2 ms | 28.6 ms |
| WebSocket, full, deflate | 36.5 % | 0.6 % | 103 | 82 MB | 1.82 s | 2.00 s |
A thread-per-connection server holds one thread per open stream: 3 of its own (main, sampler, the request being served) plus one per tab, 103 at 100 tabs. Each one sleeps in select() until the sampler wakes it, so a hundred of them cost a hundred stacks and nothing else: the Python process used 0.3 % of a core to push the change to 100 tabs. Polling holds no threads between requests, because nginx closes its upstream connection after each one (proxy_http_version 1.0), so each poll is a thread that lives for one response. A poll’s delay depends on where its timer falls between two samples, which changes from run to run; the polling rows show the lowest and highest run median in brackets.
Memory follows the threads and the compressors: 26 MB for one tab, 59 MB to 88 MB for 100 plain streams, and 82 MB to 113 MB once each stream has its own zlib state (about 0.25 MB per compressing stream, at zlib’s defaults).
The one expensive thing is compressing the full status once per tab. A stream’s compressor is its own, so the server gzips the same 299 kB a hundred times per sample: 33.2 % of a core in Python, and since Python’s threads take turns, the median tab gets its sample 1.62 s late. Compressing the 2.5 kB change instead costs 0.6 %. Polling avoids the problem differently: nginx compresses each response in C, at level 1, 8.1 % of a core for 100 tabs at 3 s and 23.8 % at 1 s, unless a working ETag stops it from compressing unchanged copies (6.0 %).
A sample every second
The dashboard’s next step is sampling every second. One sample per second, the same 2.5 kB change:
| One sample every 1 s | 1 tab: bytes/s | 1 tab: delay | 100 tabs: delay, median | 100 tabs: Python CPU | 100 tabs: nginx CPU |
|---|---|---|---|---|---|
| poll 1 s, gzip + ETag | 120,239 | 860 ms | 1.13 s | 2.6 % | 22.4 % |
| SSE, change | 2,565 | 11.5 ms | 12.7 ms | 1.5 % | 0.3 % |
| SSE, change, gzip | 542 | 11.7 ms | 19.8 ms | 2.9 % | 0.3 % |
| WebSocket, change, deflate | 531 | 11.8 ms | 20.1 ms | 2.9 % | 0.3 % |
At one sample per second nearly every 1 s poll brings a new status, so the ETag stops saving: the poll moves 120,239 B/s per tab, 5.0× as much as the 3 s poll with a sample every 5 s, and is still 860 ms behind. The stream moves 2,565 B/s, or 542 B/s compressed, and stays 11.5 ms behind. Python’s CPU for 100 tabs is 1.5 % to 2.9 % of a core, about five times the 5 s figure for five times the samples.
Compression on a stream
gzip and a stream fit together only if the compressor is told to finish each event. zlib keeps input back until it has enough for a good block; a stream that compresses without flushing delivers nothing for a while, and then several events at once. Here the server compresses every event and ends it with a sync flush (Z_SYNC_FLUSH), which empties zlib’s buffer at a byte boundary without ending the gzip stream; the browser decompresses each event as it arrives. WebSocket’s permessage-deflate (RFC 7692) does the same per message and strips the flush’s 4-byte trailer.
| Per sample, 5 s | Bytes per event | Delay, 1 tab | Python CPU, 100 tabs |
|---|---|---|---|
| SSE, change, uncompressed | 2,560 | 10.2 ms | 0.3 % |
| SSE, change, gzip, sync flush per event (in Python, level 6) | 558 | 10.0 ms | 0.6 % |
| SSE, change, nginx’s gzip filter (level 1) | 794 | 11.6 ms | 1 tab measured |
| WebSocket, change, permessage-deflate, context kept | 553 | 10.6 ms | 0.6 % |
| SSE, full, gzip, sync flush per event | 102,490 | 38.5 ms | 33.2 % |
| SSE, full, nginx’s gzip filter (level 1) | 122,835 | 19.7 ms | 1 tab measured |
| WebSocket, full, permessage-deflate | 102,055 | 30.1 ms | 36.5 % |
nginx’s gzip filter also works on a stream, as long as nothing buffers before it: with X-Accel-Buffering: no it compresses each event as it passes and flushes it, at its default level 1, at 794 B per change. Keeping the compression in nginx moves the CPU out of the Python process and into C, at a lower level and outside the GIL; nginx still compresses every stream separately, so for the full status it is the same per-tab work, only cheaper per byte. Only the change makes per-tab compression cheap.
permessage-deflate with the context kept compresses each message against the previous ones (a 32 kB window), so a change compresses as well as on the gzip stream. For the full status the window is too short to reach the previous copy, 299 kB back, and each full message compresses only against itself: 102,055 B, what gzip makes of it.
Reconnecting after a dropped connection
Connections drop: a laptop sleeps, Wi-Fi changes, a deploy restarts the proxy. The tab then reconnects and has to catch up. One tab, cut off after a few samples, back after 7 s (one sample missed) or 30 s (six missed), counted until it holds the newest sample:
| One tab, change stream | Back after 7 s | Back after 30 s | Missed samples delivered | Time to current |
|---|---|---|---|---|
SSE, Last-Event-ID | 3,727 B | 16,536 B | all, 0 gaps | 2.0 ms |
| SSE, new connection | 302,418 B | 302,175 B | none: a snapshot | 6.6 ms |
| SSE, new connection, gzip | 104,309 B | 104,336 B | none: a snapshot | 27.9 ms |
| WebSocket, new connection | 301,335 B | 301,164 B | none: a snapshot | 6.2 ms |
WebSocket, resume the app built (?since=) | 3,684 B | 16,381 B | all, 0 gaps | 2.1 ms |
| WebSocket, new connection, deflate | 104,114 B | 104,104 B | none: a snapshot | 28.9 ms |
Every row includes the new TLS handshake and request, 1,723–1,852 B up. The time is from the client dialling again to holding the newest sample; a browser first waits for the retry: delay or its own back-off. SSE has resuming built in: every event carries an id:, EventSource remembers the last one and sends it back as Last-Event-ID when it reconnects, by itself, after the retry: delay the server set (1 s here). The server replays the changes the tab missed, kept in a ring of the last 120, and the sparklines continue without a hole. WebSocket has no such field: the server here resumes only because the page puts the last sequence number in the URL it reconnects to (?since=41), and the page has to write the reconnect itself, with its own back-off. Without either, a reconnect costs one full status, 302 kB, or 104 kB compressed. A snapshot is also the honest answer when the tab was away longer than the server keeps changes.
Polling has nothing to resume: the next poll after the network returns brings the whole status, as every poll does.
What nginx in front needs
The streams run through nginx with its defaults, and three of them get in the way.
| Through nginx 1.28, defaults unless stated | Bytes/s into the tab | Updates parsed in 30 s | Delay |
|---|---|---|---|
SSE, change, default proxy_buffering on | 547 | 0 in all 3 runs | never |
SSE, full status, default proxy_buffering on | 60,151 | 6 | 5.02 s |
SSE, change, the app sends X-Accel-Buffering: no | 511 | 6 | 11.4 ms |
SSE, change, proxy_buffering off in the location | 511 | 6 | 11.2 ms |
WebSocket through a plain proxy_pass | — | 400: no Upgrade reaches the server | — |
WebSocket with proxy_http_version 1.1 and the Upgrade / Connection headers | 509 | 6 | 10.5 ms |
Buffering. By default nginx reads the upstream’s response into its buffers and passes it on in buffer-sized pieces. A stream of 2.5 kB events then arrives in chunks that cut events in half: bytes flowed, 547 B/s, but in 3 runs the tab never received one whole event. A stream of full statuses fares differently but no better: each 299 kB event fills the buffers and pushes out the previous one, so every sample arrived one sample late, 5.02 s. Both are fixed by the response header X-Accel-Buffering: no, which nginx reads from the upstream and obeys per response, so the application fixes it for every proxy configuration at once, or by proxy_buffering off in the location.
Upgrade. A WebSocket handshake is an HTTP/1.1 request with Upgrade: websocket and Connection: Upgrade. These are hop-by-hop headers, and nginx does not forward them unless told to; its default proxy_http_version 1.0 cannot upgrade at all. Through a generic proxy_pass the server sees an ordinary GET and answers 400, in all 3 runs. Every proxy, load balancer and CDN in front needs this configured, per location.
Idle timeout. nginx closes a proxied connection when the upstream has sent nothing for proxy_read_timeout, 60 s by default; load balancers and NAT routers have their own, often shorter, timers. A dashboard that samples every few seconds never goes quiet, but one that sends only on change, or a quiet night, does. With a server that had nothing to send for ten minutes, both streams were cut at 60.1 s; with the same location set to proxy_read_timeout 20s they were cut at 20.0 s, so the timer is nginx’s. A comment line (: hb) every 15 s kept SSE open, and a WebSocket ping every 15 s kept WebSocket open, through the 90 s the test lasted. EventSource reconnects by itself after such a cut (and resumes with Last-Event-ID); a WebSocket page has to notice the close and reconnect itself.
| A server with nothing to send for 10 minutes, through nginx (4 runs each) | The connection |
|---|---|
| SSE, nothing sent for 90 s | closed after 60.1 s |
SSE, a : hb comment every 15 s | still open at 90 s, the end of the test |
| WebSocket, nothing sent for 90 s | closed after 60.1 s (60.0–82.7 s across runs: in the run that caught the server’s 10-minute sample mid-run, the cut came 60 s after it) |
| WebSocket, a ping every 15 s | still open at 90 s, the end of the test |
SSE needs none of the WebSocket configuration: it is a GET with a long response, and any HTTP proxy passes it once buffering is off. The same is true for authentication: a cookie on a GET reaches an auth_request or a sign-in gate unchanged.
HTTP/2 and the six-connection limit
A browser opens at most six HTTP/1.1 connections to one origin (host and port), for every tab and window together. An SSE stream holds one of them for as long as it is open. In Chromium, eight tabs of the same dashboard over HTTP/1.1, then one more tab that fetches the status (4 runs each):
| Chromium, one browser, tabs on one origin | Tabs receiving updates | The extra tab’s fetch('/status') |
|---|---|---|
| SSE over HTTP/1.1, eight tabs | 6, the 7th and 8th never load | no answer within 15 s in 4 of 4 runs |
| SSE over HTTP/1.1, six tabs | 6 | no answer within 15 s in 4 of 4 runs |
| SSE over HTTP/2, eight tabs | 8 | 3.2 ms |
| WebSocket over HTTP/1.1, eight tabs | 8 | 3.2 ms |
| polling every 3 s over HTTP/1.1, eight tabs | 8 | 3.0 ms |
Six SSE tabs over HTTP/1.1 take every connection the browser allows to the origin: the seventh tab cannot even load its page, and every other request to that origin from any tab (a button’s POST, an image, an API call) waits until a stream closes. WebSocket connections are not counted against the six, and polling holds a connection only for the length of a response.
HTTP/2 removes the limit: all streams of a browser to one origin share one TCP connection, each SSE response is one HTTP/2 stream on it, and nginx allows 128 concurrent streams per connection by default. The cost on the wire is nothing measurable:
| HTTP/2, one sample every 5 s | Bytes/s into the tab | Up | Delay |
|---|---|---|---|
| poll 3 s, gzip | 40,124 | 476 | 1.88 s |
| SSE, change | 511 | 5 | 11.6 ms |
| SSE, change, gzip | 113 | 0 | 11.8 ms |
| ten tabs of one client on one connection, SSE change | 512 per tab | 6 per tab | 11.9 ms |
The 476 B/s up for HTTP/2 polling against 41 B/s on HTTP/1.1 is this Go client’s HTTP/2 flow-control frames (WINDOW_UPDATE) and request headers. For a dashboard behind TLS, turning on HTTP/2 in front is the fix for the six-connection limit, and nothing else about SSE changes.
Where WebSocket earns its place
On this page, which only listens, nothing measured here separates SSE from WebSocket: the same bytes to within a few per event, the same delay to the millisecond, the same threads, the same compression ratio. What separates them is everything around the bytes. SSE is a GET that EventSource reconnects and resumes by itself, that passes every HTTP proxy once buffering is off, that carries cookies like any request, and that a standard-library server writes in a dozen lines. WebSocket needs a frame codec (here about 130 lines including permessage-deflate), proxy configuration on every hop, a ping inside every idle timeout, and the application’s own reconnect and resume.
WebSocket is the right choice when the page talks back on the same connection at a rate a request per action does not suit (a shared editor, a game, a terminal), when the payload is binary (SSE is UTF-8 text, so binary needs base64, a third larger), or at message rates where per-event text framing and the HTTP/1.1 connection limit matter. A dashboard’s writes, a button or a form, are fine as ordinary POSTs next to the stream.
What this does not show
- Real networks. One machine, no added latency or loss. A round trip adds to every row equally, once; loss adds to TCP’s recovery, the same for all three. Polling on a slow link also pays a round trip per poll before any bytes arrive.
- Other servers. One Python process with one thread per connection, the kind of server in front of this dashboard. An event-loop server (asyncio, Node, Go) would hold 100 streams without 100 threads and would not serialise the per-tab compression behind one lock; the bytes, the proxies and the browser limits would not change.
- Browser behaviour in the background. Chromium throttles timers in hidden tabs, which slows polling there; stream events still arrive. The headless tabs here were all foreground.
- A quiet chip. The benchmark had its cores to itself, not its cache: cores 8–11 (and their SMT siblings) share the second core complex’s L3 cache and the memory bus with cores 12–15, and other work, a CI build among it, ran there during the run. The 100-tab CPU and delay rows may carry some of that contention; the bytes, the proxy behaviour and the browser limits do not depend on it.
- Slower devices. One fast desktop CPU for the browser; a phone parses and draws more slowly.
- Thousands of tabs. At 10,000 tabs a thread per connection costs 10,000 stacks and the full snapshot after a mass reconnect (a deploy) is 3 GB at once; neither was measured here.
- Gaps on full-status clients. Order is checked on the change streams; on the full-status streams and polls, which replace the whole page every time, the check is that each tab received one new sample per sample taken.
- Delta correctness beyond sequence. The client checks that it received every change in order; it does not rebuild the full status from the changes and compare it with a snapshot.
What the numbers say
- Pushing only the change costs 512 B/s per tab against 99,969 B/s for a 3 s poll of the full status, and shows a sample 10.2 ms after it is taken instead of 1.87 s.
- SSE and WebSocket deliver the same bytes and the same delay; their difference is reconnecting (built into
EventSource), proxies (WebSocket needs upgrade headers on every hop) and the browser’s six-connection limit on HTTP/1.1 (SSE needs HTTP/2 for more than six tabs). - On a thread-per-connection server, 100 open streams cost 100 sleeping threads and 0.3 % of a core; compressing the full status per stream costs 33.2 % of a core and 1.62 s of delay. Compress the change, or compress once and send the same bytes to every stream.
- nginx in front needs
X-Accel-Buffering: no(orproxy_buffering off) for SSE: with the default, change events never arrived at all. - A polling page behind nginx’s gzip needs a weak
If-None-Matchcomparison, or its ETag never matches. - After a drop, SSE resumed with 16.5 kB of missed changes instead of a 302 kB snapshot, with no gap in the sparklines.
Reproduce it
The harness is in the site’s repository under benchmarks/dashboard-push/: the Python server, the dashboard page, the nginx configuration, a Go client for any number of tabs, a Chromium script, and a driver that runs every cell:
./certs.sh # throwaway self-signed ECDSA P-256 certificate
docker build -t dashb-server -f Dockerfile.server . # runs the server's self-test
docker build -t dashb-tabs -f Dockerfile.tabs .
./isolate.sh on 12-15,28-31 0-11,16-27 # the benchmark's cores, everyone else's
DASH_SUBNET=<a free private /28> DASH_CGROUP=bench.slice DASH_SERVER_CPUS=12 DASH_NGINX_CPUS=13 \
DASH_CLIENT_CPUS=14,15,30,31 DASH_RUNS=3 DASH_WINDOW_S=30 DASH_OUT=results/run.jsonl \
./run.py tabs etag h2 period1 proxy reconnect browser idle
./isolate.sh off
./build.py results/run.jsonl results/run2.jsonl > article.md # every number and figure of this article
Each run appends one JSON line: bytes in each direction per tab, the delay percentiles, updates received against samples taken, change-stream order, the server’s threads, memory and CPU, and nginx’s CPU. The results behind this article are results/run.jsonl and results/run2.jsonl (the idle and connection-limit cells repeated, and the 20 s timeout check); every number and figure here is rendered from them by build.py.