Polling vs SSE vs WebSocket for a live dashboard: bytes, delay, threads and proxies, measured

Networking

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.

SetupDetails
ServerPython 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
Data16 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
Proxynginx 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
ClientsGo 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
CPUAMD 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
MethodEvery 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 sPoll 3 sPoll 3 s, gzip + ETag (weak compare)SSE, changeSSE, change, gzipWebSocket, change, deflate
Bytes per second into one tab99,96924,046512112111
Sample → parsed, median1.87 s1.95 s10.2 ms10.0 ms10.6 ms
Sample → drawn in Chromium, median1.40 snot measured14.0 ms13.0 ms12.0 ms
Python CPU at 100 tabs0.9 %0.7 %0.3 %0.6 %0.6 %
Threads at 100 tabs33103103103
Back after 30 s offlinenext pollnext poll16.5 kB, resumed104 kB, snapshot104 kB, snapshot
nginx needsnothinggzip_typesX-Accel-Buffering: nosameUpgrade headers, a ping inside 60 s
Tabs per origin on HTTP/1.16 at a time, shortsame6, the rest hangsame8 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

One open tab: polling every 3 s costs 100 kB/s; pushing only the change costs 512 B/s, 195× less. poll 1 s 300 kB/s, poll 3 s 100 kB/s, poll 3 s, gzip 40 kB/s, poll 3 s, gzip, weak ETag 24 kB/s, SSE, full status 60 kB/s, SSE, full, gzip 20 kB/s, SSE, change only 512 B/s, SSE, change, gzip 112 B/s, WS, full status 60 kB/s, WS, full, deflate 20 kB/s, WS, change only 509 B/s, WS, change, deflate 111 B/s One open tab: polling every 3 s costs 100 kB/s; pushing only the change costs 512 B/s, 195× less Bytes per second into one tab, TLS records and HTTP included, one sample every 5 s · log scale · whisker: lowest to highest run Polling SSE WebSocket 100 B/s 1.0 kB/s 10 kB/s 100 kB/s poll 1 s 300 kB/s poll 3 s 100 kB/s poll 3 s, gzip 40 kB/s poll 3 s, gzip, weak ETag 24 kB/s SSE, full status 60 kB/s SSE, full, gzip 20 kB/s SSE, change only 512 B/s SSE, change, gzip 112 B/s WS, full status 60 kB/s WS, full, deflate 20 kB/s WS, change only 509 B/s WS, change, deflate 111 B/s
Server → tab bytes per second over a 30 s window holding exactly 6 samples, median of 3 runs. Full status: the 299 kB JSON every time; change: the new point of every history ring and the current figures, 2.5 kB. gzip/deflate: compressed per stream with a flush after every event.
One open tab: polling every 3 s costs 100 kB/s; pushing only the change costs 512 B/s, 195× less. poll 1 s 300 kB/s, poll 3 s 100 kB/s, poll 3 s, gzip 40 kB/s, poll 3 s, gzip, weak ETag 24 kB/s, SSE, full status 60 kB/s, SSE, full, gzip 20 kB/s, SSE, change only 512 B/s, SSE, change, gzip 112 B/s, WS, full status 60 kB/s, WS, full, deflate 20 kB/s, WS, change only 509 B/s, WS, change, deflate 111 B/s One open tab: polling every 3 s costs 100 kB/s; pushing only the change costs 512 B/s, 195× less Bytes per second into one tab, TLS records and HTTP included, one sample every 5 s · log scale · whisker: lowest to highest run Polling SSE WebSocket 100 B/s 10 kB/s poll 1 s 300 kB/s poll 3 s 100 kB/s poll 3 s, gzip 40 kB/s poll 3 s, gzip, weak ETag 24 kB/s SSE, full status 60 kB/s SSE, full, gzip 20 kB/s SSE, change only 512 B/s SSE, change, gzip 112 B/s WS, full status 60 kB/s WS, full, deflate 20 kB/s WS, change only 509 B/s WS, change, deflate 111 B/s
Server → tab bytes per second over a 30 s window holding exactly 6 samples, median of 3 runs. Full status: the 299 kB JSON every time; change: the new point of every history ring and the current figures, 2.5 kB. gzip/deflate: compressed per stream with a flush after every event.

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 tabBytes/s304s / polls in a run (window and warm-up)nginx CPU at 100 tabs
no ETag99,9690 / 120.9 %
ETag, no gzip (the strict and the weak compare agree)60,0014 / 120.7 %
gzip, no ETag40,0770 / 128.1 %
gzip + ETag, server compares strictly40,0390 / 128.1 %
gzip + ETag, server compares weakly24,0464 / 124.9 %
poll every 1 s, gzip + ETag, weak24,11227 / 356.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 change is parsed 10.2 ms after the sample; a 3 s poll sees it 1.87 s late, half an interval plus the wait for a change. 1 tab: poll 1 s 875 ms, poll 3 s 1.87 s, poll 3 s, gzip 1.86 s, poll 3 s, gzip, weak ETag 1.95 s, SSE, full status 13.4 ms, SSE, full, gzip 38.5 ms, SSE, change only 10.2 ms, SSE, change, gzip 10.0 ms, WS, full status 16.3 ms, WS, full, deflate 30.1 ms, WS, change only 10.5 ms, WS, change, deflate 10.6 ms; 100 tabs: poll 1 s 941 ms, poll 3 s 1.96 s, poll 3 s, gzip 2.15 s, poll 3 s, gzip, weak ETag 2.19 s, SSE, full status 86.8 ms, SSE, full, gzip 1.62 s, SSE, change only 11.6 ms, SSE, change, gzip 19.9 ms, WS, full status 99.7 ms, WS, full, deflate 1.82 s, WS, change only 11.5 ms, WS, change, deflate 20.2 ms A pushed change is parsed 10.2 ms after the sample; a 3 s poll sees it 1.87 s late, half an interval plus the wait for a change Sample taken → parsed in the tab, median · log scale · whisker: lowest to highest run Polling SSE WebSocket 10.0 ms 100 ms 1.00 s 1 tab poll 1 s 875 ms poll 3 s 1.87 s poll 3 s, gzip 1.86 s poll 3 s, gzip, weak ETag 1.95 s SSE, full status 13.4 ms SSE, full, gzip 38.5 ms SSE, change only 10.2 ms SSE, change, gzip 10.0 ms WS, full status 16.3 ms WS, full, deflate 30.1 ms WS, change only 10.5 ms WS, change, deflate 10.6 ms 100 tabs poll 1 s 941 ms poll 3 s 1.96 s poll 3 s, gzip 2.15 s poll 3 s, gzip, weak ETag 2.19 s SSE, full status 86.8 ms SSE, full, gzip 1.62 s SSE, change only 11.6 ms SSE, change, gzip 19.9 ms WS, full status 99.7 ms WS, full, deflate 1.82 s WS, change only 11.5 ms WS, change, deflate 20.2 ms
Delay from the server taking a sample to the client holding it parsed: the median of the three per-run medians (each over one 30 s window). The same clock on both ends (one machine). At 100 tabs one Python process writes every stream in turn, so the last tab waits for the 99 before it.
A pushed change is parsed 10.2 ms after the sample; a 3 s poll sees it 1.87 s late, half an interval plus the wait for a change. 1 tab: poll 1 s 875 ms, poll 3 s 1.87 s, poll 3 s, gzip 1.86 s, poll 3 s, gzip, weak ETag 1.95 s, SSE, full status 13.4 ms, SSE, full, gzip 38.5 ms, SSE, change only 10.2 ms, SSE, change, gzip 10.0 ms, WS, full status 16.3 ms, WS, full, deflate 30.1 ms, WS, change only 10.5 ms, WS, change, deflate 10.6 ms; 100 tabs: poll 1 s 941 ms, poll 3 s 1.96 s, poll 3 s, gzip 2.15 s, poll 3 s, gzip, weak ETag 2.19 s, SSE, full status 86.8 ms, SSE, full, gzip 1.62 s, SSE, change only 11.6 ms, SSE, change, gzip 19.9 ms, WS, full status 99.7 ms, WS, full, deflate 1.82 s, WS, change only 11.5 ms, WS, change, deflate 20.2 ms A pushed change is parsed 10.2 ms after the sample; a 3 s poll sees it 1.87 s late, half an interval plus the wait for a change Sample taken → parsed in the tab, median · log scale · whisker: lowest to highest run Polling SSE WebSocket 10.0 ms 1.00 s 1 tab poll 1 s 875 ms poll 3 s 1.87 s poll 3 s, gzip 1.86 s poll 3 s, gzip, weak ETag 1.95 s SSE, full status 13.4 ms SSE, full, gzip 38.5 ms SSE, change only 10.2 ms SSE, change, gzip 10.0 ms WS, full status 16.3 ms WS, full, deflate 30.1 ms WS, change only 10.5 ms WS, change, deflate 10.6 ms 100 tabs poll 1 s 941 ms poll 3 s 1.96 s poll 3 s, gzip 2.15 s poll 3 s, gzip, weak ETag 2.19 s SSE, full status 86.8 ms SSE, full, gzip 1.62 s SSE, change only 11.6 ms SSE, change, gzip 19.9 ms WS, full status 99.7 ms WS, full, deflate 1.82 s WS, change only 11.5 ms WS, change, deflate 20.2 ms
Delay from the server taking a sample to the client holding it parsed: the median of the three per-run medians (each over one 30 s window). The same clock on both ends (one machine). At 100 tabs one Python process writes every stream in turn, so the last tab waits for the 99 before it.

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 tabSample → drawn, medianp95JSON.parseapply + drawMain thread busy per second
poll 3 s1.40 s2.39 s0.8 ms0.5 ms1.8 ms
poll 1 s, gzip + ETag640 ms681 ms0.8 ms0.6 ms2.2 ms
SSE, full status17.0 ms18.0 ms0.9 ms0.6 ms1.5 ms
SSE, change14.0 ms15.0 ms0.1 ms0.8 ms1.0 ms
SSE, change, gzip13.0 ms14.0 ms0.1 ms0.7 ms1.0 ms
WebSocket, full status15.0 ms17.0 ms0.9 ms0.5 ms1.3 ms
WebSocket, change14.0 ms15.0 ms0.1 ms0.8 ms1.0 ms
WebSocket, change, deflate12.0 ms13.0 ms0.0 ms0.8 ms0.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

At 100 tabs nobody's CPU is the problem until something compresses the full status per tab. Python server (ThreadingHTTPServer): poll 1 s 2.0 %, poll 3 s 0.9 %, poll 3 s, gzip 0.9 %, poll 3 s, gzip, weak ETag 0.7 %, SSE, full status 0.4 %, SSE, full, gzip 33.2 %, SSE, change only 0.3 %, SSE, change, gzip 0.6 %, WS, full status 0.4 %, WS, full, deflate 36.5 %, WS, change only 0.3 %, WS, change, deflate 0.6 %; nginx (TLS, gzip): poll 1 s 2.6 %, poll 3 s 0.9 %, poll 3 s, gzip 8.1 %, poll 3 s, gzip, weak ETag 4.9 %, SSE, full status 0.7 %, SSE, full, gzip 0.4 %, SSE, change only 0.1 %, SSE, change, gzip 0.1 %, WS, full status 0.6 %, WS, full, deflate 0.6 %, WS, change only 0.1 %, WS, change, deflate 0.1 % At 100 tabs nobody's CPU is the problem until something compresses the full status per tab CPU of one core over the window, 100 tabs, one sample every 5 s · whisker: lowest to highest run Polling SSE WebSocket 0 % 10 % 20 % 30 % Python server (ThreadingHTTPServer) poll 1 s 2.0 % poll 3 s 0.9 % poll 3 s, gzip 0.9 % poll 3 s, gzip, weak ETag 0.7 % SSE, full status 0.4 % SSE, full, gzip 33.2 % SSE, change only 0.3 % SSE, change, gzip 0.6 % WS, full status 0.4 % WS, full, deflate 36.5 % WS, change only 0.3 % WS, change, deflate 0.6 % nginx (TLS, gzip) poll 1 s 2.6 % poll 3 s 0.9 % poll 3 s, gzip 8.1 % poll 3 s, gzip, weak ETag 4.9 % SSE, full status 0.7 % SSE, full, gzip 0.4 % SSE, change only 0.1 % SSE, change, gzip 0.1 % WS, full status 0.6 % WS, full, deflate 0.6 % WS, change only 0.1 % WS, change, deflate 0.1 %
Python: the process's own user + system time (os.times) over the window. nginx: its container's cgroup usage over the same window. 100 % = one core.
At 100 tabs nobody's CPU is the problem until something compresses the full status per tab. Python server (ThreadingHTTPServer): poll 1 s 2.0 %, poll 3 s 0.9 %, poll 3 s, gzip 0.9 %, poll 3 s, gzip, weak ETag 0.7 %, SSE, full status 0.4 %, SSE, full, gzip 33.2 %, SSE, change only 0.3 %, SSE, change, gzip 0.6 %, WS, full status 0.4 %, WS, full, deflate 36.5 %, WS, change only 0.3 %, WS, change, deflate 0.6 %; nginx (TLS, gzip): poll 1 s 2.6 %, poll 3 s 0.9 %, poll 3 s, gzip 8.1 %, poll 3 s, gzip, weak ETag 4.9 %, SSE, full status 0.7 %, SSE, full, gzip 0.4 %, SSE, change only 0.1 %, SSE, change, gzip 0.1 %, WS, full status 0.6 %, WS, full, deflate 0.6 %, WS, change only 0.1 %, WS, change, deflate 0.1 % At 100 tabs nobody's CPU is the problem until something compresses the full status per tab CPU of one core over the window, 100 tabs, one sample every 5 s · whisker: lowest to highest run Polling SSE WebSocket 0 % 20 % Python server (ThreadingHTTPServer) poll 1 s 2.0 % poll 3 s 0.9 % poll 3 s, gzip 0.9 % poll 3 s, gzip, weak ETag 0.7 % SSE, full status 0.4 % SSE, full, gzip 33.2 % SSE, change only 0.3 % SSE, change, gzip 0.6 % WS, full status 0.4 % WS, full, deflate 36.5 % WS, change only 0.3 % WS, change, deflate 0.6 % nginx (TLS, gzip) poll 1 s 2.6 % poll 3 s 0.9 % poll 3 s, gzip 8.1 % poll 3 s, gzip, weak ETag 4.9 % SSE, full status 0.7 % SSE, full, gzip 0.4 % SSE, change only 0.1 % SSE, change, gzip 0.1 % WS, full status 0.6 % WS, full, deflate 0.6 % WS, change only 0.1 % WS, change, deflate 0.1 %
Python: the process's own user + system time (os.times) over the window. nginx: its container's cgroup usage over the same window. 100 % = one core.
100 tabs, one sample every 5 sPython CPUnginx CPUPython threadsPython memoryDelay, medianDelay, p95
poll 3 s0.9 %0.9 %331 MB1.96 s (1.94 s–1.97 s)3.01 s
poll 1 s2.0 %2.6 %331 MB941 ms (905 ms–1,000 ms)996 ms
poll 1 s, gzip + ETag (strict)2.1 %23.8 %327 MB308 ms (294 ms–1.10 s)378 ms
poll 1 s, gzip + ETag (weak)1.7 %6.0 %327 MB1.12 s (1.11 s–1.16 s)1.19 s
SSE, full status0.4 %0.7 %10388 MB86.8 ms142 ms
SSE, change0.3 %0.1 %10387 MB11.6 ms14.7 ms
SSE, change, gzip0.6 %0.1 %103112 MB19.9 ms28.1 ms
SSE, full, gzip33.2 %0.4 %103113 MB1.62 s1.97 s
WebSocket, full status0.4 %0.6 %10359 MB99.7 ms155 ms
WebSocket, change0.3 %0.1 %10359 MB11.5 ms13.2 ms
WebSocket, change, deflate0.6 %0.1 %10382 MB20.2 ms28.6 ms
WebSocket, full, deflate36.5 %0.6 %10382 MB1.82 s2.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 s1 tab: bytes/s1 tab: delay100 tabs: delay, median100 tabs: Python CPU100 tabs: nginx CPU
poll 1 s, gzip + ETag120,239860 ms1.13 s2.6 %22.4 %
SSE, change2,56511.5 ms12.7 ms1.5 %0.3 %
SSE, change, gzip54211.7 ms19.8 ms2.9 %0.3 %
WebSocket, change, deflate53111.8 ms20.1 ms2.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 sBytes per eventDelay, 1 tabPython CPU, 100 tabs
SSE, change, uncompressed2,56010.2 ms0.3 %
SSE, change, gzip, sync flush per event (in Python, level 6)55810.0 ms0.6 %
SSE, change, nginx’s gzip filter (level 1)79411.6 ms1 tab measured
WebSocket, change, permessage-deflate, context kept55310.6 ms0.6 %
SSE, full, gzip, sync flush per event102,49038.5 ms33.2 %
SSE, full, nginx’s gzip filter (level 1)122,83519.7 ms1 tab measured
WebSocket, full, permessage-deflate102,05530.1 ms36.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:

After 30 s offline, resuming costs 16.5 kB and a fresh start 302 kB, 18× more, and loses the missed points. Back after 7 s, 1 sample missed: SSE, Last-Event-ID 3.7 kB, WS, app resume 3.7 kB, SSE, new, gzip 104.3 kB, WS, new, deflate 104.1 kB, SSE, new connection 302.4 kB, WS, new connection 301.3 kB; Back after 30 s, 6 samples missed: SSE, Last-Event-ID 16.5 kB, WS, app resume 16.4 kB, SSE, new, gzip 104.3 kB, WS, new, deflate 104.1 kB, SSE, new connection 302.2 kB, WS, new connection 301.2 kB After 30 s offline, resuming costs 16.5 kB and a fresh start 302 kB, 18× more, and loses the missed points Bytes into the tab from reconnecting until it holds the newest sample, TLS handshake included · log scale SSE WebSocket 1 kB 10 kB 100 kB Back after 7 s, 1 sample missed SSE, Last-Event-ID 3.7 kB WS, app resume 3.7 kB SSE, new, gzip 104.3 kB WS, new, deflate 104.1 kB SSE, new connection 302.4 kB WS, new connection 301.3 kB Back after 30 s, 6 samples missed SSE, Last-Event-ID 16.5 kB WS, app resume 16.4 kB SSE, new, gzip 104.3 kB WS, new, deflate 104.1 kB SSE, new connection 302.2 kB WS, new connection 301.2 kB
One tab on a change stream, cut off after 3 messages, reconnected on a new TLS connection. Resume: SSE's Last-Event-ID, or the sequence number the page puts in the WebSocket URL; the server replays the missed changes from a ring of 120. New: no resume, the server sends the full status. Median of 3 runs.
After 30 s offline, resuming costs 16.5 kB and a fresh start 302 kB, 18× more, and loses the missed points. Back after 7 s, 1 sample missed: SSE, Last-Event-ID 3.7 kB, WS, app resume 3.7 kB, SSE, new, gzip 104.3 kB, WS, new, deflate 104.1 kB, SSE, new connection 302.4 kB, WS, new connection 301.3 kB; Back after 30 s, 6 samples missed: SSE, Last-Event-ID 16.5 kB, WS, app resume 16.4 kB, SSE, new, gzip 104.3 kB, WS, new, deflate 104.1 kB, SSE, new connection 302.2 kB, WS, new connection 301.2 kB After 30 s offline, resuming costs 16.5 kB and a fresh start 302 kB, 18× more, and loses the missed points Bytes into the tab from reconnecting until it holds the newest sample, TLS handshake included · log scale SSE WebSocket 1 kB 10 kB 100 kB Back after 7 s, 1 sample missed SSE, Last-Event-ID 3.7 kB WS, app resume 3.7 kB SSE, new, gzip 104.3 kB WS, new, deflate 104.1 kB SSE, new connection 302.4 kB WS, new connection 301.3 kB Back after 30 s, 6 samples missed SSE, Last-Event-ID 16.5 kB WS, app resume 16.4 kB SSE, new, gzip 104.3 kB WS, new, deflate 104.1 kB SSE, new connection 302.2 kB WS, new connection 301.2 kB
One tab on a change stream, cut off after 3 messages, reconnected on a new TLS connection. Resume: SSE's Last-Event-ID, or the sequence number the page puts in the WebSocket URL; the server replays the missed changes from a ring of 120. New: no resume, the server sends the full status. Median of 3 runs.
One tab, change streamBack after 7 sBack after 30 sMissed samples deliveredTime to current
SSE, Last-Event-ID3,727 B16,536 Ball, 0 gaps2.0 ms
SSE, new connection302,418 B302,175 Bnone: a snapshot6.6 ms
SSE, new connection, gzip104,309 B104,336 Bnone: a snapshot27.9 ms
WebSocket, new connection301,335 B301,164 Bnone: a snapshot6.2 ms
WebSocket, resume the app built (?since=)3,684 B16,381 Ball, 0 gaps2.1 ms
WebSocket, new connection, deflate104,114 B104,104 Bnone: a snapshot28.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 statedBytes/s into the tabUpdates parsed in 30 sDelay
SSE, change, default proxy_buffering on5470 in all 3 runsnever
SSE, full status, default proxy_buffering on60,15165.02 s
SSE, change, the app sends X-Accel-Buffering: no511611.4 ms
SSE, change, proxy_buffering off in the location511611.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 headers509610.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 sclosed after 60.1 s
SSE, a : hb comment every 15 sstill open at 90 s, the end of the test
WebSocket, nothing sent for 90 sclosed 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 sstill 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 originTabs receiving updatesThe extra tab’s fetch('/status')
SSE over HTTP/1.1, eight tabs6, the 7th and 8th never loadno answer within 15 s in 4 of 4 runs
SSE over HTTP/1.1, six tabs6no answer within 15 s in 4 of 4 runs
SSE over HTTP/2, eight tabs83.2 ms
WebSocket over HTTP/1.1, eight tabs83.2 ms
polling every 3 s over HTTP/1.1, eight tabs83.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 sBytes/s into the tabUpDelay
poll 3 s, gzip40,1244761.88 s
SSE, change511511.6 ms
SSE, change, gzip113011.8 ms
ten tabs of one client on one connection, SSE change512 per tab6 per tab11.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

What the numbers say

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.

Questions? Let's Chat :)

protocols