Turn On/Off Nagel algorithm?

RCF support and general discussion.
Post Reply
hyok
Posts: 1
Joined: Fri Jul 26, 2013 7:19 am

Turn On/Off Nagel algorithm?

Post by hyok »

Can we turn on/off Nagel algorithm? IOW, how we can set the socket TCP_NODELAY with True(1)/False(0) option for client and server side?

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Turn On/Off Nagel algorithm?

Post by jarl »

RCF allows you to access the underlying socket of both the client and the server transport:

http://www.deltavsoft.com/doc/rcf_user_ ... vel_access

I'm not sure what the rules are on when you can set the TCP_NODELAY socket option. If it is OK to set it after a socket is connected, then you'll be fine with the code in the link above.

If you need to set the socket option before the socket is connected, then we'll need to work out something else for you.
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

KonstantinUtkin
Posts: 1
Joined: Mon Feb 02, 2015 4:16 am

Re: Turn On/Off Nagel algorithm?

Post by KonstantinUtkin »

Greetings!

I have encountered the same issue: we are strongly in need for TCP_NODELAY option for TCP socket.
But setsockoption (for sock=tcpSessionState.getNativeHandle(); in your server example) failed with -EFAULT when connection is already running.
Is it possible to pre-set TCP_NODELAY for all connections of selected transport?
I guess, I can just modify the library itself and recompile it, but maybe there is any simpler way.

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Turn On/Off Nagel algorithm?

Post by jarl »

Unfortunately it's currently not possible in RCF to set socket options before the socket is connected... I'll put a fix in for that for the next release, and for now you'll have to modify the code itself to set this option.

For client side code, you'll want to modify TcpClientTransport::setupSocket() , in src\RCF\TcpClientTransport.cpp .

For server side code, I think you'll want to add code to the TcpNetworkSession constructor in src\RCF\TcpServerTransport.cpp :

Code: Select all

    
    TcpNetworkSession::TcpNetworkSession(
        TcpServerTransport &transport,
        AsioIoService & ioService) :
            AsioNetworkSession(transport, ioService),
            mSocketPtr(new AsioSocket(ioService)),
            mWriteCounter(0)
    {
        // Call setsockopt() here, after socket has been created but before it has been connected.
    }
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

falk
Posts: 9
Joined: Fri Mar 30, 2012 2:31 pm

Re: Turn On/Off Nagel algorithm?

Post by falk »

Hello,
sorry for hijacking this thread. But i think that this is an extension to the original question relating to set TCP_NODELAY.
We have a Publisher/Subscriber implementation here. And on Win7 we can see delays of 200 ms.
The delays are observed on subscriber-side when the publisher tries to send small data packets in a time window smaller than 200 ms. The subscriber sends no ACK of the first packet back to the publisher because of the Tcp delayed ACK algorithm https://en.wikipedia.org/wiki/TCP_delay ... owledgment in Winsock. And because of the Nagle algorithm https://en.wikipedia.org/wiki/Nagle%27s_algorithm further packets are delayed on publisher until the 200 ms ACKs delaying timeout is hit and the subscriber sends the ACK of the first packet.
According to Microsoft https://support.microsoft.com/en-us/kb/214397, in TCP it should be avoided to make a unidirectional used tcp connection with small data packets:
If possible, avoid socket connections with unidirectional data flow. Communications over unidirectional sockets are more easily impacted by the Nagle and delayed acknowledgment algorithms. If the communication follows a request and a response flow, you should use a single socket to do both sends and recvs so that the ACK can be piggybacked on the response.
And this is what happens in our scenario. A publisher which publishs small messages in intervals smaller than 200 ms.
Attached is a patch which fixes the issue in the MultiCastClientTransport class used in the RCF Publisher.
Is it possible to make the socket option an opt-in for Publishers and maybe also for RCF Clients and Servers?

Kind regards
Falk
Attachments
MulticastClientTransport.cpp.patch
(1.17 KiB) Downloaded 449 times

Post Reply