I am in the middle of a multi-threaded TCP server design using Berkely SOCKET API under linux in system independent C language. The Server has to perform I/O multiplexing as the server is a centralized controller that manages the clients (that maintain a persistent connection with the server forever (unless a machine on which client is running fails etc)). The server needs to handle a minimum of 500 clients.
I have a 16 core machine, what I want is that I spawn 16 threads(one per core) and a main thread. The main thread will listen() to the connections and then dispatch each connection on the queue list to a thread which will then call accept() and then use the select() sys call to perform I/O multiplexing. Now the problem is how do I know that when to dispatch a thread to call accept() . I mean how do I find out in the main thread that there is a connection pending at the listen() so that I can assign a thread to handle that connection. All help much appreciated.
Thanks.
I am in the middle of a multi-threaded TCP server design using Berkely SOCKET
Share
Note that if each of your 16 threads is going to be running
select(or poll, or whatever) anyway, there is no problem with them all adding the server socket to their select sets.More than one may wake when the server socket has in incoming connection, but only one will successfully call
accept, so it should work.Pro: easy to code.
Con:
stats on number of accepted sockets handled by each thread, with
high-load threads removing the server socket from their select sets)