I am presently refactoring a windows deamon with an eye towards porting it to linux someday.
Presently the application uses a single background thread and asynchronous socket I/O to implement FTP and HTTP clients in a single switch statement (2000 lines and 100 cases just for the switch statement).
We need to be able to handle 4000 FTP/HTTP servers simultaneously (worst case).
I was going to rewrite this using synchonous socket I/O and lots of threads but I hear that this does not scale well.
Since this is presently a windows app, I was going to use BindIoCompletionCallback thinking that Microsoft implemented this function because they could do it more efficiently than I can (perhaps it is implemented in the kernel?). BindIoCompletion is a function that accepts a socket handle and a function pointer and automagically grabs a thread from a automagically managed thread queue and has the thread execute it when the I/O is complete.
Does the Linux/UNIX API have anything similar to this?
What is the recommmended approach in Linux/UNIX?
(1) A single thread and Async I/O
(2) Lots of threads and synch I/O?
(3) A few threads and async I/O?
Your main limit will be the number of file descriptors per process. If a process can only have 256 then you may only be able to have around 250 clients max with a few other fds doing other things (like stdio, listen/accept)
Don't use SIGIO, it's a pain to get right and you end up having to call select anyway.
Write a single threaded application that uses select to handle multiple connections, but run a number of copies and each have a listener bound to the same port (SO_REUSEADDR).
Use non-blocking IO so you never sit waiting for send/receive.