jump to navigation

Disable Nagle in Low Latency High Frequency network applications February 10, 2012

Posted by anywhereinfo in Linux, TCP.
Tags:
add a comment

Most of the low latency, high frequency network applications that i work with, disable Nagle Algorithm. The reason is that “Nagle Algo”,”Delayed ACKs” and “Application ACKs” do not work together nicely.

The concept behind delayed ACKs is to bet, when receiving some data from the net, that the local application will send a reply very soon. So there’s no need to send an ACK immediately; the ACK can be piggybacked on the next data going the other way. If that doesn’t happen, after a 500ms delay, an ACK is sent anyway.

The concept behind the Nagle algorithm is that if the sender is doing very tiny writes (like single bytes, from Telnet), there’s no reason to have more than one unacknowledged packet outstanding on the connection. This prevents slow links from choking with huge numbers of outstanding tinygrams.

With both enabled, you begin to see a fixed latency as below.

Application A gives the first packet to TCP. TCP Sends it, because there is no outstanding packet.The packet size does not matter

Application A gives the second packet to TCP. Here 2 possibilities are
1. Packet Size = MSS :- TCP Sends Packet.
2. Packet Size < MSS :- Nagle prevents TCP from sending packet

If Application A continues to pump data, then once Packet Size >= MSS, TCP will send the packet.
If Application A expects an application level ACK before handing more data after the second packet, the second packet is queued.

Receiver does not acknowledge the first packet, due to delayed ACK.

Finally, Delayed ACK timer indicates timeout and the receiver sends an ACK after 500 ms.

So from this we can conclude that
1. As long as Application Acknowledgments don’t impose additional constraints
2. The sender always has pending data to send
3. Receives has not set un-usual delayed ACK Settings, which causes sender TCP to execute re-transmissions
4. Network behaves normally
Nagle should have no impact.

In low latecny, high frequency, network applications pt 2 is normally not an issue. Pt3 is also a rare case. Pt4 impacts network applications and it requires its own blog. Pt1, is typically the main issue.
Sooner or later when your code runs into the scenario where sender despite having data to send, will not hand any data to sender TCP because of Application level Receiver acknowledgment, and the Receiver is waiting on sender to send data before it can send an ACK, you will experience the full delay from Delayed ACK timeout settings.

Impact of Application ACK with Nagle and Delayed Acks

About these ads

Common TCP/Socket Options in Linux February 10, 2012

Posted by anywhereinfo in TCP.
Tags: , ,
add a comment

Here is the list of most common tcp/socket options that i use.

These values can be used to override the system-wide setting in the file /proc/sys/net/ipv4/

TCP_KEEPCNT (since Linux 2.4)
The maximum number of keepalive probes TCP should send before dropping the connection.

TCP_KEEPIDLE (since Linux 2.4)
The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket.

TCP_KEEPINTVL (since Linux 2.4)
The time (in seconds) between individual keepalive probes.

TCP_NODELAY:- disables Nagle algorithm.

SO_REUSEADDR:- allows an application to explicitly deny subsequent bind subroutine to the port/address of the socket with SO_REUSEADDR set. This allows an application to block other applications from binding with the bindsubroutine.

SO_LINGER :- Lingers on a close subroutine if data is present. This option controls the action taken when an unsent messages queue exists for a socket, and a process performs a close subroutine on the socket.

SO_KEEPALIVE:- Monitors the activity of a connection by enabling or disabling the periodic transmission of ACK messages on a connected socket.

/PROC Interface
System-wide TCP parameter settings can be accessed by files in the directory /proc/sys/net/ipv4/

TCP_KEEPALIVE_TIME :- The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours).

TCP_KEEPALIVE_INTVL:- The number of seconds between TCP keep-alive probes. default:- 75 secs

TCP_KEEPALIVE_PROBES:- the number of unacknowledged probes to send before considering the connection dead and notifying the application layer. default:- 9secs

The core socket networking parameters can be accessed via files in the directory /proc/sys/net/core/

rmem_default :- contains the default setting in bytes of the socket receive buffer.

rmem_max:- contains the maximum socket receive buffer size in bytes which a user may set by using the SO_RCVBUF socket option.

wmem_default:- contains the default setting in bytes of the socket send buffer.

wmem_max:- contains the maximum socket send buffer size in bytes which a user may set by using the SO_SNDBUF socket option.

netdev_max_backlog:- Maximum number of packets in the global input queue.

How big is your byte? January 23, 2012

Posted by anywhereinfo in C++, Memory.
Tags:
add a comment

The size of the byte is hardware dependent and no standards exist that dictate it’s size. In C/C++ programming languages, byte is an “addressable unit of data storage large enough to hold any member of the basic character set of the execution environment” (3.6 of the C standard).
Here is an interesting C++ FAQ on Byte
This ambiguity is the main reason as to why IP Networks use “Octet” and not a “Byte” to describe their internal data such as IP Address.

Extract RPM without installing it January 23, 2012

Posted by anywhereinfo in Linux, rpm.
add a comment

While doing C++ development on RHEL Platform, i came across the need to extract code out of custom RPM. A single liner solution is

rpm2cpio custom_code.rpm | cpio -idmv

At time of writing this post, both the tools (rpm2cpio and cpio) are available via yum install.
The above command will typically produce 2 types of files

  1. custom_code.spec
  2. custom_code.tar.gz

You can extract the code in the point 2 by

tar -zxvf custom_code.tar.gz
Follow

Get every new post delivered to your Inbox.