Click to See Complete Forum and Search --> : Design Issue: performance of hugh number of TCP sockets


Tiresias
September 16th, 2004, 12:03 PM
Hello Gurus,

i am trying to do a game application, and i am starting the last module which is the NPC/Creature Controller (non player character controller)...

This module is an independant module that will connect to a server. (socket tcp)
THIS MODULE AND THE SERVER WILL BE LOCATED LOCALLY ON THE SAME COMPUTER.

the purpose of the module is to "play" creatures (make them move, speak, fight etc), plenty of them, and to do that i would like (very much) to use one tcp socket PER creature ... why? because in term of code it would be much more simple because the server assumes that each message received from a client on a socket is associated to 1 and only one player/creature, and so if i respect that the change on the server side would be minimal. In contrary if my mob application opens ONLY one socket and send message for all the creature on this socket the change that i would have to do would be enormous ...

my question is : is that possible ? i expect this Mob Controller to create up to (in the worst case) 8000-10000 creatures ... which would mean the same number of local sockets .... is it completly stupid ? should i try to avoid that? what would be the performance in term of select() on the server side (would it be too slow to scan such number of fd) ?? as well in term of ressources-memory ? (i know NT can accept up to 32K sockets but its just a number). Actually even without focussing on the select(), how the system would deal with the management of such a big number of sockets?

i would appreciate very much ideas on this. I m starting this way because with the other method (one socket for all the creatures) i will have too much work to do on the server ...

thank you very much!
Tiresias

ahoodin
September 16th, 2004, 12:33 PM
Why dont you just broadcast/multicast the locations of all monsters using one socket for each connected client. To use one socket for every monster will become a real drag....literally, your TCP/IP will bog down as the socket limit is relatively low for that sort of thing.

You will start getting winsock errors like:
WSAEMFILE 10024 Too many open sockets. Each implementation may have a maximum number of socket handles available, either globally, per process, or per thread.

HTH,

ahoodin

Tiresias
September 16th, 2004, 01:05 PM
in fact there is one socket per player (real),
each player use a client software, connect to the server, and the server identifies the player from its socket (not always but in most of the case).

for me it would have been easier to just create a creature as it was a real player (opening socket etc), because in this case i can focus on my module, because for the server it would be no difference (player or creature same).


unfortunately you probably right, it will be too slow and ask for too much ressources ...

i m working on a virtual socket idea that seems to minimize my change (the npc ctrl will only open one socket in this case), i will go for that in this case unless someone tell me that the first idea is no problem ...!

thanks

ahoodin
September 16th, 2004, 03:20 PM
Additionally lag times between closing sockets and re-using sockets would be a problem. With Windows I have found that you need to use the event model to get any kind of throughput. If you would like I could give you the address of a very good site dedicated to winsock.

http://tangentsoft.net/wskfaq/articles/

this website got me on the right track with windows sockets. Hope it does the same for you.

hth,

ahoodin

PS if this helped rate me high!

dimm_coder
September 17th, 2004, 02:29 AM
Are your creatures considered to be created by the server side only or any user can create them too?
In any case, you may assign an unique identifier for each creature (and, probably a player too). Creatures being created by the server itself can share one socket (say, server_side_creatures_sck) and be distiguished by theit unique identifier. The same thing about the creatures being created by clients, except that they have a socket the same as a player who creates them. In any case, each creature and player may be identified by the following pair: socket + unique identifier.

That's just a quick idea without even brain-storming :) It may be irregular for your case because I don't know any further details of your game design.

Lee Peart
September 17th, 2004, 06:41 AM
I'd pretty much agree with dimm_coder...

Each charqacter, whether NPC or PC, should have a unique ID. Each PC will have they're own socket connection (no way round that) but the NPC server should only use a single socket to pass character events to the game server.

Character events should come in on a socket (doesn't matter which) and be placed on a queue for the game server to process in a seperate thread. The game server should not care whether the character event has been put on that queue by the actions of a real player or the NPC server.

Managing a pool of so many connections as with your original plan, will be too complex and the processing overheads will dramatically increase the chance for the whole system to suffer problems, whether from connections failing or server resources being overloaded.

BTW, You mention about the number of sockets NT can handle... Does this mean you are developing the server to run on NT? This is personal opinion, but if I was developing a game server of this magnitude I would develop it to run under UNIX as I believe it to be far more robust and more efficient in it's resource management than NT.

Mathew Joy
September 20th, 2004, 07:17 AM
Well actually I didn’t quite understand your requirement. Are you referring to connections between server and the client or server and module (which is on the same machine) or both? If it is on the same machine, you might be better off with LPC rather than socket, because for each socket connection there is a fixed overhead (in the form of NP memory) associated.

If you are talking about server and client, then 10000 is not too much, provided you use a proper method for handling winsock IO and IOCP is the best way. Do not even think of using select(), if you are using NT/2000. select() is OK only if you are using less than maybe a couple of thousand of connection. Since you are developing a game server, you should do the most efficient way. You can find some of the tricks discussed in this thread (http://www.codeguru.com/forum/showthread.php?t=295544). But the point is you should have only connection that are just sufficient for communication. (I think that was what dimm was saying.)

Hope that helps :thumb: