The Spectrum Dispatch News

technology

Running 15 Million Web Servers on One VM: A Deep Dive

An engineer explores the technical challenges of hosting billions of web servers on minimal hardware using custom runtimes and network tricks.

Running 15 Million Web Servers on One VM: A Deep Dive

A developer has outlined an ambitious technical challenge: running 15 million web servers on a single virtual machine with just 10GB of RAM and one CPU core. The motivation, as stated, is to eventually provide a web server for every human on Earth—solving cybersecurity by eliminating server scarcity.

Running 15 Million Web Servers on One VM: A Deep Dive

The basic web server requires just a handful of system calls: listen, accept, recv, send, and close. A simple C implementation using these syscalls achieves around 65,000 requests per second. However, scaling to 15 million instances reveals multiple constraints.

The Port Problem

Initially, the approach of simply spawning 15 million server processes fails because the kernel limits dynamic port allocation to a range of 32,768 to 60,999—only about 28,000 ports. The source explains that this range is intentionally small to prevent conflicts with applications like MySQL when making outbound connections.

The TCP standard itself caps ports at 65,535 (the limit of a 16-bit unsigned integer), even accounting for the fact that UDP and TCP can share the same port number. This yields roughly 128,000 unique port-protocol combinations. To bypass this, the author proposes using multiple IP addresses. Each listening server is identified by a (protocol, IP, port) tuple, so 450 additional network cards would provide enough unique IPs to reach 15 million addresses.

Alternatively, AnyIP allows listening on entire subnets. IPv6 provides 18 quintillion addresses on a single /64 subnet, making this the more practical software-only solution.

The Memory Problem

With each server process consuming roughly 1.5MB of RAM, 15 million instances would require 20 terabytes—far exceeding the 10GB constraint. The solution involves building a custom userland runtime that runs all servers in a single process, similar to how V8 handles millions of JavaScript guests.

Using a specialized scheduler, each guest requires minimal state preservation. The author calculates that only 16 bytes per guest are needed to store the program counter and two file descriptors (for server and client). This yields 220MB for scheduling state across 15 million guests.

Memory allocation for active connections presents the largest cost: assuming 1 million simultaneous connections consuming 5KB each yields 5GB—leaving 4.78GB for the runtime itself, instruction cache, and buffers. The article mentions technologies including smoltcp (a Rust TCP/IP stack), DPDK (a data plane development kit), and AF_XDP (a Linux socket family for high-performance networking), though detailed implementation specifics are not provided in the excerpt.

Key facts

  • A web server requires only five system calls: listen, accept, recv, send, and close
  • The kernel’s default dynamic port range (32,768-60,999) supports only about 28,000 ports
  • TCP limits ports to 65,535 due to the 16-bit port number constraint
  • Multiple IP addresses can be assigned to the same port, allowing 15M unique (protocol, IP, port) tuples
  • A custom userland runtime can reduce per-guest memory overhead to 16 bytes for scheduling state
  • The author estimates 220MB needed for scheduling state across 15 million guests and 5GB for 1 million active connections

Sources

← All posts