15M Concurrent Web Servers on One VM: smoltcp, DPDK

Kapteko runs 15M HTTP servers on a 1 vCPU/10 GB VM using smoltcp userspace TCP stack with DPDK/AF_XDP zero-copy

Table of contents
  1. 1.Introduction & Key Highlights
  2. 2.Core Comparison & Parameter Table
  3. 3.Deep Dive & Implementation Details
  4. 3.1.From Sockets to Userspace Stack: Why Bypass the Kernel
  5. 3.2.DPDK vs AF_XDP: Engineering Trade-offs Between Two Kernel-Bypass Paths
  6. 3.3.Connection State Machine & Memory Model: Fitting 15M Connections
  7. 4.Scenario-Based Selection & Pitfall Checklist
  8. 5.FAQ
  9. 6.Sources & References
15M Concurrent Web Servers on One VM: smoltcp, DPDK

Introduction & Key Highlights

A recent technical write-up by Kapteko demonstrates running 15 million independent HTTP web server instances on a single virtual machine equipped with only 1 vCPU and 10 GB of RAM. The experiment is not merely a benchmark chase; it uses the extreme premise of “one web server per person on Earth” to stress-test the Linux kernel network stack’s hard limits. The core thesis: the standard kernel stack hits a ceiling early when handling massive concurrency due to syscall overhead, memory copies, lock contention, and port exhaustion. The solution employs smoltcp, a userspace TCP/IP stack written in Rust, combined with DPDK (Data Plane Development Kit) and AF_XDP zero-copy technologies to bypass the kernel entirely. This achieves extremely low per-connection memory footprint and high throughput efficiency. This article targets backend engineers and infrastructure researchers interested in high-performance network programming, kernel-bypass techniques, and large-scale concurrency architecture, dissecting technology choices, key configuration parameters, practical pitfalls, and applicability boundaries.

Core Comparison & Parameter Table

Dimension Standard Kernel Stack smoltcp + DPDK/AF_XDP Key Differences & Risks
Stack Processing Location Kernel space User space Bypasses kernel stack, eliminates syscall & context-switch overhead
Packet I/O Mode Socket API (recv/send) DPDK PMD / AF_XDP (zero-copy) Direct NIC queue manipulation; requires exclusive NIC or XDP-capable driver
Concurrent Connection Scale Limited by port range (~28k) & file descriptors 15,000,000 connections User-space connection state management breaks ip_local_port_range limit
Test Environment Specs 1 vCPU, 10 GB RAM 1 vCPU, 10 GB RAM Identical hardware; performance delta purely from software architecture
Per-Connection Memory ~few KB (sk_buff + sock structs) ~5 MB total / 15M conns ≈ 350 Bytes/conn Minimalist connection context, no kernel metadata overhead
Port Exhaustion Fix Tune net.ipv4.ip_local_port_range / SO_REUSEPORT User-space stack self-manages 4-tuples Independent of kernel port allocator; theoretically 2^32 connections per IP
Development Complexity Low (standard POSIX API) Extreme Must manually handle ARP, ICMP, TCP retransmission, congestion control, reassembly
Ecosystem Compatibility Perfect with all apps Only supports non-blocking/event-driven models Cannot run standard blocking apps directly; requires rewrite or wrapping

Deep Dive & Implementation Details

From Sockets to Userspace Stack: Why Bypass the Kernel

The article begins with a baseline C blocking-socket implementation: socket(), listen(), accept(), recv(), send(), close(). On a single core this model tops out around 65k RPS (Requests Per Second) and quickly exhausts port resources. The default sysctl net.ipv4.ip_local_port_range provides only 32768–60999 (~28k ephemeral ports). Even widening the range, enabling SO_REUSEPORT or tcp_tw_reuse cannot sustain million-scale concurrency. The root cause: the kernel maintains heavy per-connection structures (struct sock, sk_buff), and every packet traverses interrupt → softirq → protocol processing → copy to user buffer → wake process → context switch. smoltcp moves this logic to the application layer; paired with DPDK or AF_XDP it polls/fetches packets directly from NIC RX queues, achieving zero-copy, zero-interrupt, zero-lock-contention data plane.

DPDK vs AF_XDP: Engineering Trade-offs Between Two Kernel-Bypass Paths

The experiment evaluated both DPDK and AF_XDP as data-plane backends. DPDK uses UIO/VFIO to take full control of physical/virtual NICs, offering finest-grained control and peak performance, but demands exclusive NIC ownership, hugepage configuration, complex setup, and in virtualized environments requires device passthrough or vhost-user support. AF_XDP is a native Linux kernel eBPF/XDP extension allowing userspace programs to access driver-layer RX/TX queues via shared-memory rings without exclusive NIC ownership, better compatibility, and minimal overhead (few nanoseconds). The article ultimately favors AF_XDP: it retains kernel control-plane management while sinking the data plane. Key configuration steps: enable NIC multi-queue, load XDP program to redirect traffic to AF_XDP socket, userspace polls AF_XDP file descriptors via poll()/epoll(), and uses xsk_ring_cons__peek / xsk_ring_prod__reserve for batched frame TX/RX. Note: AF_XDP requires driver support (e.g., ixgbe, i40e, mlx5, virtio_net) and kernel 5.4+.

Connection State Machine & Memory Model: Fitting 15M Connections

Supporting 15M connections hinges on an ultra-lean connection context. smoltcp’s TcpSocketBuffer and SocketHandle store only sequence numbers, window size, timers, a few flags, and pointers to TX/RX ring buffers, stripping the vast statistics, crypto, debug, and congestion-control fields found in the kernel’s struct tcp_sock. The article cites ~5 MB total memory (interpreted as total or key structure footprint, not per-connection), yielding ~350 Bytes/connection. This requires: 1) disabling or minimizing TCP options (SACK, timestamps, window scaling); 2) fixed small buffers (256B–512B) instead of dynamic allocation; 3) timer-wheel for timeout management, avoiding per-connection timers; 4) pre-allocated array or lock-free hash table for connection table, index-as-connection-ID to avoid pointer chasing. Application logic must be purely async event-driven: accept registers connection, recv parses HTTP headers, send crafts fixed response frames into TX ring — never blocking. Any synchronous call (sleep, file I/O, locks) stalls the sole CPU core.

Scenario-Based Selection & Pitfall Checklist

  1. Suitable Scenarios: Extreme concurrency, long-lived connections, small packets, stateless services Examples: IoT gateway ingress, game heartbeat/state sync, real-time message push, DNS/HTTP reverse proxy frontends. These workloads have massive connection counts but low per-connection throughput and simple logic — ideal for userspace stacks.

  2. Unsuitable Scenarios: Large file transfer, complex TLS termination, kernel compatibility needs, multi-core scaling TLS handshake and crypto are compute-heavy; userspace implementations are complex and lack KTLS/hardware offload performance. High-throughput scenarios hit single-core CPU limits. Running standard Docker containers, Kubernetes pods, or relying on iptables/nftables/ebtables breaks when fully bypassing the kernel.

  3. Pitfall: NIC Passthrough & Driver Compatibility in Virtualized Environments Standard cloud VMs rarely expose physical NIC SR-IOV VFs; virtio_net AF_XDP support arrived late and underperforms bare metal. Production recommendation: bare-metal servers + XDP-capable high-performance NICs + dedicated isolated CPU cores.

  4. Pitfall: Protocol Stack Completeness & Robustness Gaps Lightweight stacks like smoltcp may not fully implement TCP edge cases (PAWS, FACK, complex retransmission storms, middlebox compatibility). For public-facing services, place a mature L4/L7 load balancer (HAProxy, Envoy, NGINX) in front for protocol compliance and security; attach userspace high-concurrency workers behind it.

  5. Pitfall: Observability Breakdown Standard tools (ss, netstat, tcpdump, bpftrace) become useless. Custom metrics collection, logging, and tracing infrastructure must be built; debugging difficulty rises exponentially.

FAQ

Why not just use SO_REUSEPORT + multi-process + epoll to solve C10M?

SO_REUSEPORT allows multiple listening sockets on the same port with kernel hash-based connection distribution; combined with edge-triggered epoll it improves multi-core scalability. However, this experiment uses only 1 vCPU — multi-process adds context-switch and lock overhead. More fundamentally, the kernel’s struct sock consumes ~1.5–2 KB per connection; 15M connections would need 22–30 GB RAM, far exceeding the 10 GB limit. The userspace stack’s minimalist structures (~350 Bytes/conn) make 15M connections fit in 10 GB.

What is the concrete performance gap between AF_XDP and DPDK in this experiment? Why was AF_XDP chosen?

The original article does not disclose specific RPS, latency, or CPU utilization comparisons. From an engineering perspective: AF_XDP avoids hugepages, driver binding, retains the kernel control plane, and runs on standard cloud VMs (AWS Nitro, Alibaba Cloud Dragon), yielding far lower deployment and ops cost. In a single-core, small-packet, extreme-connection-count scenario, AF_XDP’s zero-copy performance approaches DPDK; marginal gains do not justify DPDK’s complexity premium.

Can this architecture be used directly for production HTTPS services?

Strongly discouraged for direct production HTTPS termination. TLS 1.2/1.3 handshakes involve asymmetric crypto, certificate validation, key derivation — compute-intensive and logically complex. Userspace TLS libraries (e.g., rustls) are feasible but lack hardware acceleration (AES-NI, QAT, KTLS), making single-core performance a bottleneck. Recommended production architecture: front-end mature TLS termination layer (NGINX/Envoy/HAProxy + KTLS/hardware offload) → back-end userspace high-concurrency workers.

Sources & References

Spotted outdated pricing, stock, or expired coupons?See methodology & report an update →

Related articles