Receiving packets does it really need threading?

YEy i has custom title^_^
Joined
Sep 29, 2006
Messages
451
Reaction score
69
i was just wondering since the game server just forwards packets to handler which handles them shouldnt this make huge delays when there are multiple connections sending packets to server?
and if it have to be multithreaded aka each receive would have their own thread this would lead to massive ram usage right?

so is there any smart ways to do this, i really havent noticed any lag yet but theres only few peoples on the server at time but when theres like 50 it should lag right?
 
i was just wondering since the game server just forwards packets to handler which handles them shouldnt this make huge delays when there are multiple connections sending packets to server?
and if it have to be multithreaded aka each receive would have their own thread this would lead to massive ram usage right?

so is there any smart ways to do this, i really havent noticed any lag yet but theres only few peoples on the server at time but when theres like 50 it should lag right?

If what you're asking is thread-per-connection is bad, well the answer is yes.

select and poll are horribly inefficient and with even a small number of connections they begin chewing up CPU and the server's datarate tanks.

Yes, you want to multi-thread it, but only to match the number of independent cores available. Then, you want to make sure those threads have their affinity set properly so they don't get swapped between cores by the OS. And the method by which you retrieve packets needs to be asynchronous, with the assistance of the OS. IOCP on windows, epoll on linux, kqueue on bsd, etc.


http://people.freebsd.org/~jlemon/papers/kqueue.pdf
http://www.codeproject.com/KB/IP/iocp_server_client.aspx
http://www.theukwebdesigncompany.com/articles/iocp-thread-pooling.php

And if you want to do things quick and easy without dirtying your hands with implementing your own thread pool etc:

http://www.codeproject.com/KB/IP/iocp.aspx?msg=956268
http://msdn.microsoft.com/en-us/library/aa363484(VS.85).aspx

Do some research, you'll figure it out :).
 
Couldn't say it better.
You may also download Microsoft Platform SDK for Windows Server 2003 R2 where you can find examples of IOCP based server, in Samples\NetDS\WinSock\iocp directory. :P
 
Back