Accurately size server hardware and network capacity for real-time applications. Compare WebSocket, Server-Sent Events (SSE), and Long-Polling across Kernel Socket Buffers (`rmem`/`wmem`), Runtime Heap RAM, HTTP Framing Overhead, and Monthly Egress Bandwidth for up to 1,000,000 concurrent clients.
1. Concurrency & Infrastructure Parameters
2. Message Frequency & Payload Characteristics
Server Memory & Network Bandwidth Metrics
Protocol Performance & Resource Footprint Breakdown
| Architectural Feature | WebSocket | Server-Sent Events (SSE) | Long-Polling |
|---|---|---|---|
| Communication Channel | Full-Duplex Bidirectional | Unidirectional (Server -> Client) | Half-Duplex via HTTP cycles |
| Framing Overhead per Message | 2 - 4 bytes | ~7 bytes (`data: ...\n\n`) | 600 - 1,200 bytes (Headers) |
| HTTP/2 & HTTP/3 Multiplexing | Limited (RFC 8441 rarely deployed) | Native & Automatic | Separate HTTP/2 streams |
| Native Browser Auto-Reconnect | Requires custom JS library | Native (`EventSource` API) | Manual via loop polling |
| Corporate Proxy & Firewall Traversal | May require WSS to bypass DPI | Flawless (Standard HTTP/2) | Standard HTTP |
Mathematical Sizing Formulas & Engineering Mechanics
To calculate real server RAM consumption for persistent TCP sockets, the Linux operating system allocates kernel buffers alongside application runtime heap structures:
Bandwidth_egress = Conexiones × Frecuencia_msg_seg × (Payload_bytes + Framing_header_bytes) × 8 / 1,000,000 [Mbps]
- Kernel Socket Buffers (rmem + wmem): Configured via net.ipv4.tcp_rmem and net.ipv4.tcp_wmem. Default 32 KB allocations consume 3.2 GB in kernel space for 100,000 sockets.
- File Descriptor Overhead: Each connection allocates a kernel struct file of ~1 KB and counts against the ulimit -n boundary.
- Header Framing Cost: WebSocket adds a mere 2 bytes of server-to-client frame header. Long-polling re-transmits the entire HTTP request header set (600-1200 bytes) on every poll cycle.
Frequently Asked Questions: WebSocket vs SSE vs Polling
1. How much RAM does an idle WebSocket connection consume on Linux?
Between 14 KB and 45 KB per connection. In tuned Go/Rust runtimes with minimal socket buffers (4KB read + 4KB write) and offloaded TLS, 1M connections require 12-16 GB RAM. In untuned Node.js or Python environments with direct TLS, they exceed 50 GB.
2. When should I choose Server-Sent Events (SSE) over WebSocket?
Whenever data transmission is strictly unidirectional (server-to-client). It is the gold standard for LLM token streaming (ChatGPT, Claude), real-time dashboards, and stock tickers. It runs over standard HTTP/2 multiplexing without firewall traversal friction.
3. Why is Long-Polling obsolete for high-concurrency real-time systems?
Due to excessive HTTP header overhead. Each poll transmits 600-1200 bytes of cookies, user-agents, and tokens. For 100,000 clients polling every 5s, header overhead alone demands over 160 Mbps of continuous egress (50+ TB/month) without delivering application payload.
4. What Linux kernel parameters are required to sustain C1000K (1 million connections)?
Configure ulimit -n and fs.file-max to 1,500,000; net.ipv4.ip_local_port_range to 1024 65535; net.ipv4.tcp_rmem and net.ipv4.tcp_wmem to '4096 4096 16384'; and net.core.somaxconn to 65535 to eliminate listen queue backlog drops.