From Process-per-Connection to epoll: How I/O Multiplexing Tackles C10K

The C10K problem is about how a single server can hold ten thousand simultaneous network connections. That “10K” means concurrent connections, not ten thousand completed requests per second. By today’s standards, the number doesn’t sound extreme. In a process-per-connection server, though, more connections mean just as many processes, and the machine quickly spends most of its resources switching between them.

I/O multiplexing changes that model. Instead of dedicating a separate process to every connection, a small number of threads watch a large set of file descriptors at once and only work on the ones ready to read or write. select, poll, and epoll all solve this same problem, though they differ a lot in how much work it takes to find those ready events as connection counts climb.

Why process-per-connection struggles to reach 10,000

Early network servers often used a straightforward setup: a master process listens on a port and accepts incoming connections, and for every new connection it calls fork() to spawn a child process that handles all later reads and writes. Splitting connection acceptance from data handling kept code boundaries clear and isolated each connection.

Trouble starts when the connection count keeps climbing. Ten thousand connections can mean nearly ten thousand child processes, and a process is not a lightweight ID. Each one carries its own task struct, page tables, stack, and scheduling state, and the OS has to switch back and forth across all of them. Even when most connections are sitting idle with no data arriving, their processes still consume system resources.

Two details here need to be stated accurately. Linux’s fork() uses copy-on-write, so spawning a child doesn’t immediately copy all of the parent’s memory, though duplicating page tables and allocating kernel task structures still takes real work. An exited child process also doesn’t automatically leak resources forever; it only lingers as a zombie holding minimal metadata if the parent fails to reap its exit status with wait() or a similar call. Proper reaping fixes zombies, yet it does nothing about the creation, scheduling, and memory overhead of running thousands of processes in the first place.

Adding faster CPUs and more RAM rarely fixes this model. The more connections you add, the larger the slice of that extra hardware eaten by process management, and vertical scaling hits diminishing returns fast.

Most connections are waiting, so they don’t each need a process

Network connections behave very differently from continuous compute workloads. Much of the time, a connection is open with no data coming in. Calling a blocking read on it parks the thread until something arrives. The only moments your code actually needs to step in are when a socket becomes readable, writable, or hits an error.

On Unix and Linux, sockets are represented as file descriptors. I/O multiplexing lets a single thread wait on many file descriptors at once: as soon as any of them becomes ready, the wait call returns, and the program handles just those connections. The loop looks like this:

1
2
3
4
5
6
7
Register or submit the file descriptors to watch
↓
Wait for a batch of I/O events
↓
Handle only the ready connections
↓
Wait again

select, poll, and epoll all give you this primitive. They only report readiness: that doing a given I/O operation right now won’t block. They don’t read application data, parse protocols, or write responses for you. All of that still lives in user space.

select watches multiple connections, but scans the whole set every round

select tracks watched file descriptors in an fd_set. On each call, the program passes read, write, and exception sets into the kernel. The kernel inspects descriptors up to the specified range and modifies the sets in place so only the ready ones remain on return. Because those sets get overwritten, the program normally has to rebuild them before the next wait.

That breaks the “one process blocked on one connection” bottleneck, but under high concurrency it hits two clear limits.

The first limit is set size. In common Linux implementations, FD_SETSIZE is 1024, so select can only watch file descriptors numbered below 1024. That caps the descriptor number itself, not simply “up to 1024 connections.” Standard input, log files, and listening sockets all consume descriptor numbers too. For a server aiming at tens of thousands of connections, that cap rules it out right away.

The second limit is per-round scanning cost. Every call passes the full descriptor set to the kernel, the kernel checks across the entire range, and on return the application still has to scan through to see which descriptors were marked ready. If you’re watching 10,000 connections and only 10 have data at that moment, most of the work still scales with all 10,000 candidates. The larger the connection count and the lower the active ratio, the more wasted work piles up.

poll removes the fixed-size set, not the linear scan

poll solves the same problem as select, except it describes watched file descriptors with a dynamically sized array of pollfd structs instead of a fixed-size fd_set. You’re still bound by system limits like the per-process open file limit and available memory, not by a hard-coded FD_SETSIZE cap in the API.

Switching to a dynamic array removes the capacity ceiling, but it doesn’t change the pattern of submitting and scanning the entire watched set every round. As the array grows, the kernel still walks through its elements linearly, and user space still has to scan the returned array to find the ones with events. So poll can hold a much larger descriptor set than select, while still slowing down as total connections grow.

Moving from select to poll mainly changed how many descriptors fit in the set. Making high concurrency scale meant stopping the repeated full-set scan on every wait.

epoll keeps the interest list in the kernel and returns only ready events

epoll maintains an instance inside the kernel. Seen from user space, that instance tracks two collections: an interest list of descriptors registered by the program, and a ready list of descriptors that have actually seen I/O activity.

The program uses epoll_ctl() to add, modify, or remove watched file descriptors, then calls epoll_wait() to wait for events. If nothing is ready yet, epoll_wait() can block; once connections become ready, the kernel hands back only the entries from the ready list. As long as the watched set hasn’t changed, the application never has to re-submit every file descriptor on each wait, nor scan the entire set to find the active ones.

1
2
3
4
5
                             ┌→ socket A
Interest list: A, B, C, D, E ┼→ socket C has event → Ready list: C, E
└→ socket E has event

epoll_wait() returns C, E; the application handles only those two connections

That doesn’t mean every epoll operation is constant-time, or that adding more connections is free. Registering and removing descriptors, maintaining kernel data structures, and copying ready events to user space all take work. The real advantage is that waiting for events scales primarily with the number of ready connections rather than scanning every watched connection each round. When a server holds lots of open connections and only a small fraction are active at any moment, that difference matters a lot.

LT vs. ET isn’t just about fewer notifications

epoll supports two trigger modes: level-triggered (LT, the default) and edge-triggered (ET).

In LT mode, as long as a file descriptor remains ready, subsequent epoll_wait() calls can keep notifying you. If unread bytes are still sitting in a socket’s receive buffer, the socket is still readable. If you didn’t drain it completely on the first pass, you’ll get another chance on the next round. That makes LT intuitive and forgiving.

ET watches state transitions instead. For reads, an event fires when the buffer transitions from “no data” to “data available.” If your code only reads part of what’s there, the buffer stays readable, so you won’t necessarily get another edge notification. Using ET properly usually means putting the file descriptor into non-blocking mode and looping on reads until you hit EAGAIN, so you know you’ve drained everything currently available.

1
2
LT: buffer still has data → may keep notifying
ET: state changes → notifies once → read until EAGAIN

ET can cut down redundant notifications and let a single wakeup drain more data in a batch, but it isn’t an automatic speedup regardless of workload. The read/write loops get trickier, and missing the “drain until EAGAIN“ rule can stall a connection indefinitely. Picking ET means weighing event frequency, per-event work, and code correctness together.

Using epoll doesn’t solve C10K by itself

I/O multiplexing solves one specific question: how to efficiently discover which connections are ready for reads or writes. Being able to manage thousands of connections in an event loop does not mean you can run slow operations inside it. If a ready event kicks off heavy computation, blocking disk I/O, or a sluggish downstream call, it can stall the dispatch thread and leave every other ready connection waiting.

Real servers still have to deal with open file descriptor limits, per-connection buffers and application state, mismatches between receive and send speeds, and how to hand work off across worker threads. epoll removes the primary scaling roadblock of process-per-connection, not the rest of those operational boundaries.

What makes C10K worth remembering is the shift in server architecture, not the number ten thousand: moving from giving every connection its own execution context to waiting centrally for readiness events and spending limited CPU time only on connections that actually need work. select first made multi-descriptor waiting possible, poll lifted the fixed set-size cap, and epoll kept the interest list and ready list in the kernel so the server stopped scanning every connection on every single turn.