Throughput
A WebRTC connection is not a fixed-speed tunnel. It is a dynamic pipe that expands and contracts based on the network's health. Measuring throughput shows the limits of the browser's Transport Engine.
The Bottlenecks of Throughput
When you push data through an RTCDataChannel, you are fighting against three primary constraints:
| Constraint | Cause | Impact |
|---|---|---|
| CPU Overhead | DTLS Encryption | On older devices, the CPU becomes the bottleneck for 100Mbps+ streams. |
| Congestion Window | SCTP Algorithm | The browser starts slow and gradually "ramps up" to avoid flooding the link. |
| JS Main Thread | Data Serialization | If you send huge strings instead of binary, the UI will freeze. |
1. The SCTP Ramp-up
Unlike a simple UDP stream, SCTP uses a Congestion Control mechanism.
- Slow Start: The browser sends a few packets and waits for ACKs.
- Linear Growth: As ACKs arrive, the "Congestion Window" (cwnd) expands.
- Back-off: If a packet is lost, the window is cut in half instantly to protect the network from collapse.
2. Bandwidth Estimation (BWE)
Modern browsers use Google Congestion Control (GCC) to estimate the "available" bandwidth.
- Delay-based: If packets arrive slightly slower than they were sent, it's a sign that a router's queue is filling up.
- Loss-based: If packets are dropping, the pipe is definitely full.
3. In practice: Optimizing Throughput
To achieve "Fiber-speed" throughput in the browser, you must follow these rules:
Use ArrayBuffers
Avoid JSON or base64. Moving binary data directly from memory into the SCTP engine is the only way to reach Gigabit speeds.
Manage Backpressure
Monitor the bufferedAmount. If it exceeds 16MB, stop sending. Saturated buffers cause high latency and can lead to browser tab crashes.
MTU Optimization
A single WebRTC packet is typically limited to ~1200 bytes. If you send a 64KB chunk, the SCTP layer must fragment it. Optimal throughput is often found by sending chunks that align with the network's Maximum Transmission Unit (MTU).
Throughput is the total data sent, including headers and retransmissions. Goodput is the actual file data received by the application. In a high-loss network, your throughput might be 10Mbps while your goodput is only 2Mbps.
Study the Binary Chunking Guide for implementation patterns, or inspect the Network Resilience mechanisms that handle packet loss.