Reputation: 275
I have a situation that there will be 500 concurrent connection to server. In term of response time which method is faster? (asynchronous or synchronous) And what are the reasons behind?
I know asynchronous socket is like a list of connection, then it will ask each of the connection, do you have anything to send or receive. If the list is very long, then response time may take longer as well. Is this correct?
Upvotes: 3
Views: 287
Reputation: 101150
Asynchronous sockets will work better. They use IOCP internally which is a very effective way to handle pending IO operations.
If you have a few sockets, use threads since it's easier. Stick with asynchronous sockets otherwise.
Upvotes: 2
Reputation: 185852
If you use synchronous sockets, then 500 connections will requires 500 threads. Bad idea. The scheduling cost of that many threads will dwarf the overhead of keeping an eye on 500 asynchronous sockets.
BTW, you don't cycle over each socket, asking it if it's ready to transmit. You use async APIs such as select()
, or I/O completion ports.
Upvotes: 3