My send() socket call iis taking its own sweet time
Hi,
I have a TCP server that handles more than 100 clients.
I keep getting bottlenecks and i narrowed it down to the send() winsock function.
A send() winsock call sometimes takes 100~300ms to finish.
I i have no clue why but this block from other clients to be served.
Re: My send() socket call iis taking its own sweet time
Your code suggests that your architecture uses blocking sockets.
If so, well, blocking sockets by their very nature will block. The block can be frustrating, but it allows you to write code with a very simple and serialized flow logic.
If you cannot tolerate the block, there are two options: re-write using non-blocking sockets, or maintain the use of blocking sockets but re-write into a multithreaded code, with one thread per client.
Both will introduce complications, and you are in the best position to know which one might be more appropriate. For example, if there is significnat coordination amongst the clients, then multithreading might be too difficult.
Without knowing more, with only around 100 clients, the multithreaded approach might be easier than non-blocking sockets. As you start to exceed a few hundred threads, the context switching among threads makes the multithreaded approach impractical, so this architecture would not be easily extensible if you suddenly find that you need to service 1000 clients simultaneously.
Bookmarks