Trying to optimize small packets sending
Posted: Tue 08 Oct 2013 13:50
Hello,
I have setup a SSH client using TScSSHClient and TScSSHChannel classes with TClientSocket class as underlying socket.
Packet data exchanged are :
- commands consisting of text less than 100 bytes size.
- binary data of 512 bytes size.
I have read that when packets are less than 1460 bytes size a timer is set for 200ms until the underlying buffer reaches that minimum size (Nagle algorithm).
I do not have this 200ms extra delay when using the same socket without SSH activated.
Possible solutions are:
1) increase packet size (with stuffing bytes) to this minumum so underlying buffer always reaches that minimum size
2) Set NODELAY option on socket so the Nagle algorithm does not get involved
I plan to use 1) for binary data.
I have used solution 2) for commands:
BOOL disabled = TRUE;
// Make sure delay for small packets is removed
setsockopt((SOCKET)ClientSocket->Socket->SocketHandle, IPPROTO_TCP, TCP_NODELAY,
(char*)&disabled, sizeof(BOOL));
I checked that NODELAY was set to true with getsockopt().
Even though I do not see any improvement.
Is there any option in TScSSHClient and TScSSHChannel instances that would prevent this improvement ?
Thanks
I have setup a SSH client using TScSSHClient and TScSSHChannel classes with TClientSocket class as underlying socket.
Packet data exchanged are :
- commands consisting of text less than 100 bytes size.
- binary data of 512 bytes size.
I have read that when packets are less than 1460 bytes size a timer is set for 200ms until the underlying buffer reaches that minimum size (Nagle algorithm).
I do not have this 200ms extra delay when using the same socket without SSH activated.
Possible solutions are:
1) increase packet size (with stuffing bytes) to this minumum so underlying buffer always reaches that minimum size
2) Set NODELAY option on socket so the Nagle algorithm does not get involved
I plan to use 1) for binary data.
I have used solution 2) for commands:
BOOL disabled = TRUE;
// Make sure delay for small packets is removed
setsockopt((SOCKET)ClientSocket->Socket->SocketHandle, IPPROTO_TCP, TCP_NODELAY,
(char*)&disabled, sizeof(BOOL));
I checked that NODELAY was set to true with getsockopt().
Even though I do not see any improvement.
Is there any option in TScSSHClient and TScSSHChannel instances that would prevent this improvement ?
Thanks