Tech Support > Microsoft Windows > Development Resources > win32: each socket in its own thread ?
win32: each socket in its own thread ?
Posted by Coca Smythe on February 3rd, 2007


Hi,

Ive made a couple of tcp socket-servers, common for all of them is that they
use an array of handles for each socket so i normally can maintain
communication of <63 sockets pr thread (WaitForMultipleOjects etc. etc.)

Now this is just fine, but now i want to extend the idea i have here, its a
multipurpose socketserver where each socket can communicate with different
clients (each talking their own "protocol"/"language") - therefore i want to
extend my design so each different type of client can be placed in a DLL,
and then i assign the incoming socket-handling to an instance of this DLL.

The reason why i want to do this, is to keep somekind of "driver" level, so
i can do alot of communcation in the DLL, but have a clean and cut
interfacelevel to the rest of the application - besides this it gives me
some advantages to have each socket placed in its own thread, its easy to
control it via queues etc.

Then i came to think of putting each and every socket in its own thread,
instead of doing the more optimized way of handling <63 sockets pr thread.

But take in consideration that im working with possible100-200 active
sockets, and im wondering if that would be completely insain to put on a
windows-machine ? i know there shouldnt be an upper-limit for threads
(depending on memory) and as long as they just sit there and wait, i cant
see it would put load on the system.

But how do you feel ? would it be very bad design ? or can you recommend
other ideas ?


Posted by David Gravereaux on February 5th, 2007


On Sat, 3 Feb 2007 05:05:29 +0100, "Coca Smythe"
<dontwantspamhot@mailspamnothx.com> wrote:

IOCP, you'll only need one thread (or as many threads as processors that
you have). It scales great. I tested my server with 60K sockets once, it
didn't slow to a crawl. Only 30% CPU pushing full wire speed of 100mbps

Grab this: http://www.microsoft.com/mspress/nor.../book18802.htm

http://msdn.microsoft.com/msdnmag/issues/1000/Winsock/


Similar Posts