Socket ping-pong performance

Posted by Kamil_H on Stack Overflow See other posts from Stack Overflow or by Kamil_H
Published on 2010-05-14T14:59:15Z Indexed on 2010/05/14 15:04 UTC
Read the original article Hit count: 293

Filed under:
|
|

I have written two simple programs (tried it in C++ and C#).

This is pseudo code:

-------- Client ---------------

for(int i = 0; i < 200.000; i++)  
{  
    socket_send("ping")  
    socket_receive(buff)  
}  

--------- Server -------------

while(1)  
{  
    socket_receive(buff)  
    socket_send("pong")  
}  

I tried it on Windows.

Execution time of client is about 45 seconds. Can somebody explain me why this takes so long? I understand that if there were real network connection between client and server the time of one 'ping-pong' would be: generate_ping + send_via_network + generate_pong + send_via_network but here everything is done in 'local' mode.

Is there any way to make this inter process ping-pong faster using network sockets (I'm not asking about shared memory for example :) )

© Stack Overflow or respective owner

Related posts about sockets

Related posts about Performance