Delay with TCP ? Use TCP_NODELAY

When you have a TCP server dans client and you send small data you can have delay between sending and receiving data. This Is because TCP uses Nagle’s algorithm by default.

Nagle’s algorithm collect small data and send them all at once, consequently you can have a delay between you call the method send() and the data are really sent.

If you have this delay and wish to remove it, deactivate the Nagle’s algorithm. You can deactivate it on server side and client side.

On Python :

socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

On Java/Android :

socket.setTcpNoDelay(true);

There is also TCP_CORK, I didn’t enable it, consequently I have no experience with it. You can check this web page to get more information : https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/tcp_nodelay_and_small_buffer_writes

Tags:

No responses yet

Laisser un commentaire