A Linux socket costs about 3,300 bytes of kernel memory, even when idle. A userland network stack in Rust, together with a custom runtime, reached 16 million servers on one 10 GB VM. 🦀
The article "15 million web servers on one VM" by @kaptekoguid (kapteko) is a humorous but technically clear experiment: run one web server for every person on the planet, starting with 15 million on a single VM with 10 GB of RAM and one CPU core.
The path, step by step: → A plain C server hits the port limit first. AnyIP, which lets a machine listen on a whole subnet, solves the addressing → Each process then costs about 1.5 MB, so 15 million would need around 20 TB of RAM. The answer is a custom runtime that runs the servers as sandboxed guests in one process, using LFI for isolation, with about 16 bytes of scheduling state per guest. That runtime comes from earlier articles by the same author → The kernel finding: a socket call allocates about 3,300 bytes whether the socket is active, listening or doing nothing. The post breaks down 3,384 bytes: tcp_sock 2,240, socket_alloc 768, file 184 and dentry 192. The author's first assumption that idle listeners would cost zero memory was wrong, and the post says so
The fix is to go lower in the network stack. smoltcp, a Rust TCP/IP stack that needs no heap allocation, handles the protocol in userland. Packet I/O comes through TUN or TAP, DPDK, or AF_XDP: → DPDK takes the network device from the OS and uses a busy-looping core → AF_XDP leaves the device with the kernel and uses an eBPF filter to route packets to userspace, so SSH keeps working
The results, from the author's benchmark: → With the kernel network stack, memory runs out at around 2.5 million servers, and requests per second drop as the count grows → With smoltcp, an idle server costs about 620 bytes and an active one about 1 KB, and the run reached 16 million servers → DPDK is fastest, with AF_XDP just behind
🔗 kapteko.com/15-million-webservers
#RustLang #Networking #DPDK #Systems #Rust
