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.....
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.
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...
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.
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..
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.
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....:)