CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2002
    Posts
    107

    Design Issue: performance of hugh number of TCP sockets

    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

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Design Issue: performance of hugh number of TCP sockets

    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

  3. #3
    Join Date
    Oct 2002
    Posts
    107

    Re: Design Issue: performance of hugh number of TCP sockets

    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

  4. #4
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Design Issue: performance of hugh number of TCP sockets

    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!

  5. #5
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647

    Re: Design Issue: performance of hugh number of TCP sockets

    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.
    "UNIX is simple; it just takes a genius to understand its simplicity!"

  6. #6
    Join Date
    Apr 2001
    Posts
    514

    Re: Design Issue: performance of hugh number of TCP sockets

    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.

  7. #7
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: Design Issue: performance of hugh number of TCP sockets

    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. 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
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured