Boost Socket Performance on Linux
In an article on IBM developerWorks, under Linux > Boost socket performance on
Linux, M. Tim Jones (mtj@mtjones.com), Senior Principal Software Engineer, gave
4 tips on how to code for better network performance in your applications.
Tip 1. Minimize packet transmit latency
Tip 2. Minimize system call overhead
Tip 3. Adjust TCP windows for the Bandwidth Delay Product
Tip 4. Dynamically tune the GNU/Linux TCP/IP stack
The important section, performancewiki.com thinks, is this:
"When you communicate through a TCP socket, the data are chopped into blocks
so that they fit within the TCP payload for the given connection. The size of
TCP payload depends on several factors (such as the maximum packet size along
the path), but these factors are known at connection initiation time. To achieve
the best performance, the goal is to fill each packet as much as possible with
the available data. When insufficient data exist to fill a payload (otherwise
known as the maximum segment size, or MSS), TCP employs the Nagle algorithm to
automatically concatenate small buffers into a single segment. Doing so
increases the efficiency of the application and reduces overall network
congestion by minimizing the number of small packets that are sent.
John Nagle's algorithm
works well to minimize small packets by concatenating them into larger ones, but
sometimes you simply want the ability to send small packets. A simple example is
the telnet application, which allows a user to interact with a remote system,
typically through a shell. If the user were required to fill a segment with
typed characters before the packet was sent, the experience would be less than
desirable.
Another example is the HTTP
protocol. Commonly, a client browser makes a small request (an HTTP request
message), resulting in a much larger response by the Web server (the Web
page)."
Disabling the Nagle algorithm for a TCP
socket
int sock, flag, ret;
/* Create new stream socket */
sock = socket( AF_INET, SOCK_STREAM, 0 );
/* Disable the Nagle (TCP No Delay) algorithm */
flag = 1;
ret = setsockopt( sock, IPPROTO_TCP,
TCP_NODELAY, (char *)&flag, sizeof(flag) );
if (ret == -1) {
printf("Couldn't setsockopt(TCP_NODELAY)\n");
exit(-1);
} |
http://www-128.ibm.com/developerworks/linux/library/l-hisock.html?mod=performancewiki.com-BoostSocket
for the original article.
Check out this section on this site for
Linux network tuning.
|