hwasin
hwasin

Reputation: 1

Lowest TCP receive window size

What is the lowest possible TCP receive window size can be announced by Linux kernel TCP/IP stack impl and how can i configure to make it announce such one? My goal is to achieve low latency and sacrificing throughput?

Upvotes: 0

Views: 926

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136525

Right now my test client application reads about 128 bytes each second from buffer and TCP stack waits till there are free SO_RCVBUF/2 bytes space before notifying server about new window size. I'd like to make my client announce window size lower than SO_RCVBUF/2 if its possible.

I do not think that changing the receive window size will have any effect on latency.

However, since your messages are small (128 bytes), you may like to disable Nagle algorithm in the sender that makes the sender wait when sending TCP payload smaller than MSS:

Applications that expect real-time responses and low latency can react poorly with Nagle's algorithm. Applications such as networked multiplayer video games or the movement of the mouse in a remotely controlled operating system, expect that actions are sent immediately, while the algorithm purposefully delays transmission, increasing bandwidth efficiency at the expense of latency. For this reason applications with low-bandwidth time-sensitive transmissions typically use TCP_NODELAY to bypass the Nagle delay.

On the receiver you may like to disable TCP delayed acknowledgements:

The additional wait time introduced by the delayed ACK can cause further delays when interacting with certain applications and configurations. If Nagle's algorithm is being used by the sending party, data will be queued by the sender until an ACK is received. If the sender does not send enough data to fill the maximum segment size (for example, if it performs two small writes followed by a blocking read) then the transfer will pause up to the ACK delay timeout. Linux 2.4.4+ supports a TCP_QUICKACK socket option that disables delayed ACK.

C++ code:

void disableTcpNagle(int sock) {
    int value = 1;
    if(::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof value)) 
        throw std::system_error(errno, std::system_category(), "setsockopt(TCP_NODELAY)");
}

void enableTcpQuickAck(int sock) {
    int value = 1;
    if(::setsockopt(sock, IPPROTO_TCP, TCP_QUICKACK, &value, sizeof value)) 
        throw std::system_error(errno, std::system_category(), "setsockopt(TCP_QUICKACK)");
}

Upvotes: 1

Related Questions