| < Day Day Up > |
|
In trying to increase the performance of certain networked applications, reducing latency can go a long way in this endeavor. This particular topic has a number of caveats; it’s not a panacea for nonperforming applications.
Consider an Application layer protocol that emits smaller requests to a peer. As the TCP layer receives these requests, it buffers them up for at most 200 ms before emitting them as an aggregated datagram. This means that in the worst case, 200 ms will pass before the request is finally emitted from the stack, from the point when it was introduced by the Application layer. From a performance perspective, the introduction of this latency can have very drastic effects on the throughput of this particular connection.
To resolve the latency problem, the TCP_NODELAY option can be used. Recall from Chapter 5, Socket Options, that TCP_NODELAY is used to disable the Nagle algorithm (used to minimize the number of small packets that are emitted on the network). Small packets are also bad for performance, but in this particular case, sending a smaller packet is not as bad as holding it for 200 ms (especially when considering higher bandwidth Gigabit connections). Therefore, we’ll forego the inefficiency of smaller packets for the sake of getting them out on the wire quickly.
Consider the example shown in Figure 7.1. In this illustration, we see a maximum of 200 ms between the introduction of the data at the Sockets layer until the data is emitted from the TCP layer (to IP).
Figure 7.1: Example of the potential latency from TCP’s Nagle algorithm.
In Figure 7.2, with Nagle disabled (via TCP_NODELAY), much less time elapses, as there is no aggregation to minimize small packets. In most cases, the data is pushed through to the IP layer immediately.
Figure 7.2: Example of improved (reduced) latency through disabling Nagle.
The purpose of TCP’s Nagle algorithm was to minimize small packets on the network that induced poor performance. For certain applications, in which we know we’ll only be emitting a small amount of data before awaiting a response, disabling Nagle can yield significant performance improvement. If the application sends numerous data in a number of unique write calls, this option can lead to much degraded performance, and should be avoided.
| < Day Day Up > |
|