Setting the Send and Receive Window Sizes

A TCP data transfer isn't a one-way affair; the sending computer sends data packets but expects to hear back from the recipient about the success of the data transfer. Suppose that these operations were to occur in serial—that is, the sender sends a packet, the recipient acknowledges receipt of the packet, and only then does the sender send a second packet. In this scenario, the transmission would be slowed down by the latencies involved in the connection. For instance, consider a 1Mbps connection with a 100ms round-trip latency and a packet size of 1,500 bytes. At time 0, the sender begins sending the packet. At 50ms (half the ping time), the recipient begins to receive the packet, but at 1Mbps, a 1,500-byte packet takes 12ms to arrive. Assuming an instantaneous response, that means the recipient can begin to send a response at 62ms. That response arrives at the sender's system at 112ms. (The response is likely to be much shorter than 1,500 bytes, so we can assume it arrives much more quickly than 12ms.) If the sender can't send a packet until receiving a reply, the sender will end up spending 12ms of every 112ms actually sending data, reducing the 1Mbps link to a 107Kbps (0.107Mbps) connection.

The solution to this problem is the negotiation of a receive window, which is the number of bytes that a system will accept before sending an acknowledgment, and a send window, which is the number of bytes it will send before requiring an acknowledgment. By setting these values high enough, you enable the sender to deliver data more-or-less continuously. Unfortunately, the optimum window size depends on the latency and throughput between the two computers—it should be at least as many bytes as your system can receive during the round-trip latency (that is, the ping time) between the systems. Table 19.2 summarizes the minimum window sizes you should use for different speeds and latencies. Entries in this table are derived from the formula size = bandwidth x latency, where size is the window size in bits, bandwidth is the throughput speed in bits per second, and latency is the ping time in seconds. (Table 19.2's rows and columns specify latencies in milliseconds, throughput in megabits per second, and window size in kilobytes, though.)

Table 19.2: Minimum Send and Receive Window Sizes

Latency (ms)

1Mbps Throughput

2Mbps Throughput

4Mbps Throughput

8Mbps Throughput

50

6KB

12KB

24KB

49KB

100

12KB

24KB

49KB

98KB

150

18KB

37KB

73KB

146KB

200

24KB

49KB

98 KB

195KB

300

37KB

73KB

146KB

293KB

400

49KB

98KB

195KB

391KB

500

61KB

122KB

244KB

488KB

Linux's default window size is 64KB, which is enough for most connections. LAN speeds are off the chart as far as Table 19.2 is concerned, but consider a 100Mbps Ethernet network with 1 ms latencies. The size = bandwidth x latency formula suggests a minimum receive window size of 12.2KB, so a 64KB window size is quite adequate. On broadband and other always-on Internet connections, latencies for connections on the same continent are usually 100ms or less, and connections seldom exceed 4Mbps. If your Internet connection is unusually speedy, though, you may want to consider a larger receive window size. Another extreme case is a satellite connection, which has very high latencies. Assuming a typical 500ms latency, a 61KB window size should be adequate for a 1Mbps connection.

If you believe your system's performance is suffering because of a window size that's too small, you can adjust it in either of two ways:

Using route Options The route command adds routes to the Linux routing table. You can locate your system's call to route (most likely in one of the scripts referenced in Table 19.1) and modify that call to include the window W parameter, where Wis the window size in bytes.

Setting /proc Filesystem Options You can set the default and maximum send and receive window sizes using entries in the /proc/sys/net/core directory. Specifically, rmem_default and rmem_max set the default and maximum receive window sizes, while wmem_default and wmem_max set the default and maximum send window sizes. For instance, typing echo "131072" > /proc/sys/net/core/rmem_max sets the maximum receive window size to 128KB.

In order to be effective, both your system and the one with which it's communicating must support the larger size. For this reason, this adjustment may be ineffective if the remote system uses a 64KB or smaller window size.

0 0

Post a comment