Skip to content
/
Suscribirse Subscribe

Detrás del telón hay sistemas, no magia. Arquitectura de software, IA y computación de bajo nivel para las trincheras de producción.

Behind the curtain there are systems, not magic. Software architecture, AI, and systems engineering from the production trenches.

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

10,000
1,000 (C1K) 50,000 (C50K) 200,000 (C200K) 500,000 (C500K)

2. Message Frequency & Payload Characteristics

512 B

Server Memory & Network Bandwidth Metrics

WebSocket (WSS) Bidirectional
RAM Total: 0.41 GB
Bandwidth (Mbps): 8.22 Mbps
Egress Mensual: 2.7 TB/mes
Server-Sent Events (SSE) HTTP/2 Stream
RAM Total: 0.39 GB
Bandwidth (Mbps): 8.30 Mbps
Egress Mensual: 2.7 TB/mes
Long-Polling (HTTP/1.1) High Header Overhead
RAM en Servidor: 0.48 GB
Bandwidth (Mbps): 24.5 Mbps
Egress Mensual: 8.1 TB/mes
SRE Capacity Recommendation: A standard 16 GB VPS server comfortably handles these concurrent clients using WebSocket or SSE with Go/Rust.

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:

RAM_total = Conexiones × (RAM_kernel_socket + RAM_runtime_heap + RAM_TLS_session + Overhead_FD)
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.

Suscribirse Subscribe