Thread: Threading

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Threading

    Hi,
    I presently have a network application which sends and receives data.. data can come in at any time (like a server).... Is it better to use different threads to send and receive data or it it better to use non blocking sockets instead.... and poll the send and receive continously.....

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Definitely go with non-blocking I/O. With a blocking I/O model you will experience a performance hit as when process hundred of thousands of sockets.

    Kuphryn

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well in the real world situtation my program will be creating around 400 sockets... I am presently using Non-blocking IO. and have two threads one for socket communication and the other as a controller.. I noticed that the system really gets slow but when I add a small delay in one of the threads the system is quite smooth... any reason for this...

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I wrote a server a couple months ago and I had it set up like this:

    The main thread would start the program, and then spawn another thread that just listened for requests. As soon as it got a request, it would spawn another thread to handle it, and then that same sceond thread would keep listening for requests and spawning new threads.

  5. #5
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    actually my program acts as a client(simulating VoIP phones)... so every phone I represent creates 3 threads.. to handle sockets, controller and another socket to receive remote commands...

    so when i represent 200 phones i will be ending up with 600 threads... with 400 threads handling sockets... (not sure if the system can run smooth with this load)... so I am trying different things to make things faster.... but have no idea why adding a small usleep in a thread makes the application run smoother..

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well it sounds to me like you're writing a server program. There's a difference between that and a server computer (in practice - not theory (who's sig is that?)). If you get the ones that are made to be servers, then they are equipped to run smoothly with that load. They'll have multiple CPU's, really advanced modems, and everything else they need to be doing several network-related things at once.

    With that in mind, it may be that no matter how good your code is, you're going to be limited by your computer and the rest of the network.

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well actually you are right in a way... my program will be both a server and a client.. Will connect to remote call managers as a client and will accept user commands as a server....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ threading
    By Anddos in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2005, 03:29 PM
  2. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 12:16 PM
  3. Problem with threading
    By osal in forum Windows Programming
    Replies: 6
    Last Post: 07-21-2004, 12:41 PM
  4. starting to learn multi threading
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2004, 01:44 PM
  5. Threading
    By threads in forum C# Programming
    Replies: 0
    Last Post: 01-17-2003, 11:50 PM