The TURN Box Filled Up Before the SFU Did

Four steps of a WebRTC call: capture, signal, ICE connect, and encrypted stream
Capture, then your own signaling server, then ICE, then encrypted media. Step 2 is not part of WebRTC. Ours fell over on a Tuesday while the media tier sat idle, and the status page still said the calls were down.

The week the office closed, the calling tool went from a convenience to the only way a standup happened. It fell over on a Wednesday. The selective forwarding unit was bored. The TURN server was not. The shape of the system, the one we had written down in March, assumed a lot of peers would connect directly. Home routers disagreed.

Where the bits went

ICE tries a host candidate, then a server-reflexive candidate, then the relay. Most laptops on home routers never completed the first two. Every one of those calls landed on coturn.

Relayed video is counted twice on that box, once in and once out. A modest camera is about 1.2 Mbps. One relayed person is about 2.4 Mbps of NIC. Eighty of those, which is not a large company, is about 190 Mbps before audio, a second video layer, and the retransmits you pay when UDP is blocked and you fall down to TURN over TCP. The VM was sold as a gigabit. The NIC was the flat line on the graph. CPU was not.

We had been about to add SFU capacity. An SFU forwards packets. It does not decode them, and it was fine. The relay was the product that week, whether the architecture slide said so or not.

A camera processes video locally and relays only an alert through a TURN server
The right picture for a camera on a wall: analyze on the device, ship an alert, relay only when a person needs to look. A meeting is the opposite. The media itself is the product, and you will pay the relay for every unfriendly router. Budget as if every router is unfriendly.

The keyframe storm

When a packet is lost, the receiver asks for a new keyframe. The request is cheap to send and expensive to honor. Under loss, every subscriber asked at once, every encoder emitted a large frame at once, and the loss got worse. We capped those requests at one per second per stream. The picture dipped for a moment instead of collapsing for a minute.

The other cap was the room. One Janus videoroom thread was comfortable around 16 video publishers. The 17th goes to another process. We had been adding people to the same process because the UI showed a single room name.

What changed that week

  • TURN on 443/TCP and 443/TLS, not only on a high UDP port a home router drops.
  • Signaling, SFU, and TURN as three services, with three dashboards. "No signaling" and "no media" page different people.
  • Simulcast with three layers. The subscriber takes the layer their path can hold. We stopped sending a large frame to a phone on a weak uplink.
  • A hard cap on keyframe requests, and a hard cap of 16 publishers per videoroom process.
  • A join from a phone hotspot before we call a release done. The office network hides the bug.

A load test of the SFU on a wired link measures a path our users no longer have. Count the relayed bits first. Then decide whether the forwarding tier is actually the thing that is full.