epoll and io_uring
In short: epoll and io_uring are Linux interfaces that let a program serve thousands of connections or file operations efficiently at once.
In more detail: The classic way of blocking one thread per connection scales badly. Event-driven servers instead ask the kernel which connections are ready.
In Depth
- select/poll: Pass the whole list on every call and check it linearly, slow with many connections.
- epoll: The kernel remembers the watch list.
epoll_waitreturns only the ready connections, so the cost grows with the number of active, not all, connections. Basis of nginx, Node.js (libuv) and Redis. - io_uring: Two ring buffers between program and kernel (submission and completion). The program queues many operations and collects results without paying a system call per operation. Works for files too.
- Caution: io_uring has had some security problems, some environments disable it.
- Similar: kqueue (BSD, macOS) and IOCP (Windows).
- Consequence: One thread can hold tens of thousands of connections (the C10k problem).
See also: Sockets, Ring buffer