Re:Blocking I/O: it's not just for pansies
by IgorPartola on Monday May 10, 2010 @10:51AM
(#1334570)
Also, programming in C, it's very easy use thread-per-connection model especially if synchronization is not necessary. If you want a pool of threads it gets a bit more complex, but if you always spin up a new thread for each connection, it's easy as pie (and in my case doesn't matter since the time spent creating a new thread is negligible compared to the amount of time it'll spend doing useful work).
[ Parent
| on HN ]
If you want to keep the easy thread-per-connection model even with 1M connections you might have a look at Erlang - it takes the best of both worlds (threads and async IO) via its processes (so you get a process-per-connection). I read somewhere that the overhead of a process is just about 300 bytes.
Event loops are even easier, and the per-connection overhead is often a single struct. And if you want to do async disk IO, you can do it in another thread. (The IO::AIO module for Perl is a great example of this technique.)