Let's imaging the case where tcp buffers have a size of 1000000 bytes, what's size of initial tcp window would be in the case on Linux?
Assistant
The initial TCP window size, which is also known as the TCP receive window size, is determined by the TCP window scaling factor and the default size set for the system. In Linux, this initial window size is not directly set to the size of the TCP buffers, rather it is determined by the kernel based on standard defaults and potentially any system tuning parameters that may have been set.
User
Tell me the exact value based on latest default system settings you know.
Assistant
The exact initial TCP window size can vary between different Linux distributions and kernel versions. However, as of my last update, many Linux systems use an initial TCP window size that is based on the TCP Maximum Segment Size (MSS).
A common default for the initial window size was 10 times the MSS, which could be found in more recent Linux kernels following an update in accordance with RFC 6928. Since a common MSS is 1460 bytes (this is derived from an Ethernet MTU of 1500 bytes minus the standard TCP and IP header sizes), the initial TCP window size would often default to 10 * 1460 = 14,600 bytes.
This value was a tradeoff: large enough to allow decent performance on fast networks without being so large as to increase the risk of congestion collapse on the network. However, please be aware this value can also depend on the Linux kernel version and specific system settings, and you should check the system configuration to determine the current settings.
User
What's the option that represent the value if 10? answer shortly
Assistant
The option that represents the value of 10 in the context of TCP MSS (Maximum Segment Size) related to the initial TCP window size is the tcp_slow_start_after_idle sysctl parameter, but it does not directly represent the '10 MSS' value. Instead, it controls whether TCP slow start is used after a connection goes idle.
For setting the initial TCP window size to 10 times the MSS, you would typically configure the behavior through kernel code or system tuning parameters. There's no single option with a value of '10' that you can set to specify the initial window size. The initial window size is an outcome of kernel behavior and standards compliance, not a direct sysctl setting.
User
If tcp_slow_start_after_idle is 10, then the sender will send 10 tcp packets at once or receiver will advertised its initial tcp window size as 10*MSS?
Assistant
I apologize for the confusion earlier. The tcp_slow_start_after_idle sysctl parameter does not actually have a value that represents a multiple of MSS. Rather, it is a boolean parameter that enables or disables slow start after a TCP connection has been idle. It takes the value of 0 or 1, where:
0 means TCP slow start is disabled after idle periods.
1 means TCP will use slow start after the connection has been idle.
The initial congestion window size, which may be set to a value like 10*MSS, is not directly configured through sysctl settings or a parameter that you can simply set to '10'. The initial congestion window size is hardcoded into the TCP implementation based on the standard at the time of the kernel's release or may be influenced by certain TCP-related algorithms or patches.
To reiterate, the initial window size of 10MSS is not a value that you can set directly through a single sysctl parameter. Instead, it is defined by the TCP implementation within the kernel. The RFC that recommended an increase to 10MSS is RFC 6928, and kernel versions after this RFC's release may follow this recommendation by default in the TCP stack implementation, but this is not guaranteed as it can vary between systems.
User
You are about receiver window size? answer briefly
Assistant
No, the tcp_slow_start_after_idle parameter does not determine the receiver window size.
The receiver window size is typically set by the net.ipv4.tcp_rmem sysctl parameter, with the second value indicating the default receive window size. It is not directly associated with the tcp_slow_start_after_idle parameter.
User
I am about 10*MSS is RFC 6928
Assistant
Yes, RFC 6928 suggests an increased initial TCP congestion window size, which can be around 10 times the MSS (Maximum Segment Size), to improve the performance of TCP connections, especially over high-latency networks. This larger initial window allows more data to be sent by the sender before waiting for an acknowledgment, thereby utilizing the available bandwidth more efficiently. However, this is related to the congestion window (cwnd), which is part of the congestion control algorithm in TCP, and it is not the same as the receiver's advertised window size.
User
what's an initial receiver’s advertised window size?
Assistant
The initial receiver's advertised window size, also simply referred to as the initial TCP window size, is the amount of data in bytes that the receiver is willing to accept before requiring an acknowledgment from the sender. It is set when a TCP connection is established and indicates how much buffer space the receiver has allocated for the connection.
In the context of Linux and many other operating systems, the default initial window size has evolved over time based on ongoing research and changes in network conditions. Historically, this size was quite small but has increased to better utilize the capacity of modern networks.
As of the latest updates prior to my knowledge cutoff in 2023, many systems have adopted initial window sizes around 10 times the Maximum Segment Size (MSS), which might typically be 14,600 bytes if the MSS is assumed to be 1460 bytes (the standard MSS for Ethernet without options). This is in line with recommendations from RFC 6928 for faster startup of TCP connections.
User
If I set SO_RCVBUF option to tcp socket, then its initial window size will be equal to the value I set?
Assistant
When you set the SO_RCVBUF socket option to a specific value for a TCP socket, you are requesting a change in the size of the receive buffer for that socket. The operating system may accommodate this request, potentially after applying some scaling factors or constraints.
The initial window size, which the receiver advertises to the sender, is not necessarily set exactly to the value specified by SO_RCVBUF. The operating system uses the value specified by SO_RCVBUF to determine the maximum size of the receive buffer for the socket, but the initial window size advertised in TCP may be smaller than this limit for various reasons, including:
User
Is it hardcoded?
Assistant
The initial window size is not hardcoded in the sense of being an immutable fixed value in the Linux kernel; rather, it can be influenced by various system parameters and dynamic conditions. However, certain default behaviors for setting the initial window size are preset within the kernel, and unless these are altered by system administrators or overridden on a per-socket basis, the system will use these defaults when establishing new TCP connections.
The initial window size is determined by a combination of system-wide settings (often found in /proc/sys/net/ipv4/ or accessible via sysctl) and any socket-specific options set via setsockopt() with SO_RCVBUF. The kernel may also apply its internal logic to ensure that the window size advertised does not exceed reasonable or safe limits, which might involve using a fraction of the SO_RCVBUF value or clamping it within a certain range.
The initial advertised window size is not strictly "hardcoded" because it can be adjusted, but the algorithm or method by which it is determined is part of the compiled kernel, hence it might be seen as "built-in" unless modifications to the kernel or system parameters are made.
User
I mean that it depends on buffer size and there isn't an option so specify it apart from tcp buffer size?
Assistant
Correct, the initial receiver's advertised window size in TCP is determined by the receive buffer size, and there isn't a separate, distinct option specifically for setting the initial TCP window size independently of the receive buffer size in the socket options.
When you set the SO_RCVBUF option for a TCP socket, you're effectively setting the size of the receive buffer, which can influence the window size that the receiver advertises. The TCP stack uses the receive buffer size to determine how much unacknowledged data it can handle at one time, and this is reflected in the advertised window size.
Thus, the initial window size that the receiver advertises is inherently related to the receive buffer size configured for the socket, and other than setting this buffer size, there's no dedicated socket option specifically for the initial window size.
The receive buffer size (and therefore, indirectly, the initial window size) can generally be tuned by setting:
SO_RCVBUF socket option, on a per-socket basis.
User
Are you sure?
Assistant
Yes, I am sure of the general principle that in TCP, the initial receiver's advertised window size is influenced by the size of the receive buffer that you set with the SO_RCVBUF socket option. There is no separate standard socket option specifically for setting the initial TCP window size independently of the receive buffer size in standard TCP implementations in operating systems like Linux.
When you set the receive buffer size via SO_RCVBUF, you are indicating to the kernel the amount of buffer space that can be used for incoming data on that socket. The TCP stack takes this buffer size into consideration when advertising the window size in the SYN and subsequent segments for flow control.
User
If so, what's the reason to limit tcp scaling factor to 2^14 having maximum buffer size of 2^32, If initial window size can correspond to a free total buffer size? If so, than scaling factor could also be 2^16 to fit the total maximum biffer size by multiplying with 2^16 of window size.
Assistant
The TCP window scaling factor is indeed limited to a maximum value of 2^14 primarily due to the way TCP window scaling is specified in RFC 7323 (which obsoleted RFC 1323). This limitation is not directly related to the maximum buffer size that modern operating systems can handle, which can indeed be up to 2^32 bytes or more.
Here's why the limitation exists:
User
Can tcp window size be equal to tcp buffer size if the buffer is empty?
Assistant
Yes, the TCP window size can be equal to the TCP buffer size when the buffer is empty, assuming window scaling is appropriately configured (when necessary) and there are no other flow control constraints.
The TCP window size effectively tells the sender how much data the receiver is currently willing to accept and can buffer. When the TCP receive buffer on the receiver side is completely empty, the window size advertised in the TCP header will generally be the size of the receive buffer because there is currently no other data in the buffer awaiting processing.
User
Is it possible to set minimum window size on Linux?
Assistant
As of my last update, there is no direct sysctl setting or socket option provided by the Linux kernel that allows you to set a strict minimum window size for TCP connections. However, there are a few indirect ways that the effective minimum window size can be influenced:
Receive Buffer Tuning: By adjusting the sysctl setting, you indirectly influence the minimum window size. The first value in is the minimum TCP read buffer space allocated for each TCP socket. If the window size indicated by the buffer space falls below this minimum value for any reason, the kernel will ensure that the advertised window size doesn't go below it.
User
Can tcp window size be large than 0 and lesser than 4096? answer shortly
Assistant
Yes, the TCP window size can be larger than 0 and less than 4096 bytes.
User
Why you said than first value of net.ipv4.tcp_rmem set the minimum window size? Was it correct?
Assistant
I apologize for any confusion caused by my previous response. The first value of net.ipv4.tcp_rmem does not specifically set the minimum window size. It sets the minimum size of the receive buffer for TCP sockets.
To clarify:
net.ipv4.tcp_rmem controls the minimum, default, and maximum sizes of the receive buffer for each TCP socket. The three values are space-separated in the format "min default max."
The first value (minimum) does not directly correspond to the minimum TCP window size, but it sets a lower limit for the size of the receive buffer that is allocated for a TCP socket.
The actual window size advertised may be smaller than the receive buffer if the data is filling up the buffer or based on other flow control considerations.
The initial window size a receiver advertises can indeed be smaller than the default receive buffer size and can also be smaller than 4096 bytes based on dynamic conditions and the behavior of the TCP congestion control algorithms. The minimum buffer size as specified by tcp_rmem is more about ensuring there is a minimum amount of memory available for incoming data on a socket, rather than setting a floor for the TCP window size.
User
Is it possible that tcp window size fits tcp buffer size and all packets within the window is received and acknowledged except the first packet? How can it impact performance?
Assistant
User
I meant that if all the window us acknowledged except the first packet than application lavel will not be able to read the buffer, right?
Assistant
Correct, at the application level, data is read from the TCP receive buffer in sequence. If all packets within the TCP window are acknowledged except the first one, the application will not be able to read those packets from the buffer until the missing packet—the one that would fill the gap—is received and acknowledged.
This is because TCP guarantees in-order delivery of data to the application layer. Even if the subsequent packets have been received and are sitting in the buffer, TCP will not deliver out-of-order data to the application. The missing data at the front of the buffer represents a gap in the byte stream that must be filled before the application can process the data.
This situation can impact performance, as it causes a delay in data processing at the application level. Known as "head-of-line blocking," it can negatively affect the throughput of a TCP connection, because the receiver is essentially stuck waiting for the missing packet before it can do anything with the already-received data that follows it.
In practice, TCP implementations utilize the SACK option (if enabled and supported) to inform the sender about received, out-of-order packets, so that only the lost packets need to be retransmitted, rather than the entire sequence of packets following the lost one. Once the missing data arrives, TCP can then deliver the full sequence of data to the application without any gaps.
User
If a tcp window size if large and can be covered by 1000 packets, can sender sent all of these 1000 packets it once in parallel?
Assistant
In TCP, the term "parallel" isn't typically used in the way it might be in other contexts, such as parallel computing, because TCP is inherently a serial protocol—packets are sent one after the other and are expected to be received and processed in order. However, when talking about sending multiple packets "at once," what we really mean is that the sender can dispatch many packets sequentially but very quickly, one right after the other, without waiting for an acknowledgment for each individual packet before sending the next. This is because TCP is a streaming protocol that allows for a continuous flow of data.
User
If sender's congestion window is 999 of packets, receiver's window is the size that can be filled with 1000 of packets, reciever got and acknowledged 999 of packets except the first in its window, then the receiver's buffer size is freed in the size of 100 of packets so receiver has got a free buffer space after its window that can be filled with additional 100 of packets. Can the sender try to send more than the single missing packet? Can the receiver advertise the rest of its freed buffer space or it will wait until the first packet will be received?
Assistant
In the scenario you've described, where the sender's congestion window allows sending 999 packets and the receiver's window can accommodate 1000 packets, if 999 packets are received and acknowledged except for the first one, the receiver cannot advance its cumulative acknowledgment number past the sequence number of the missing packet. This is because TCP acknowledgments are cumulative, meaning it acknowledges all bytes received up to the first missing byte in the stream.
User
If sender’s congestion window is 1100 of packets, receiver’s window is the size that can be filled with 1000 of packets, reciever got and acknowledged 999 of packets except the first in its window, then the receiver’s buffer size is freed in the size of 100 of packets so receiver has got a free buffer space after its window that can be filled with additional 100 of packets. The sender and receiver uses SACK algorithm. Can the sender try to send more than the single missing packet? Can the receiver advertise the rest of its freed buffer space or it will wait until the first packet will be received?
Assistant
In the scenario where both the sender and receiver use the Selective Acknowledgment (SACK) algorithm, the sender's congestion window is larger than the receiver's advertised window, and the receiver has acknowledged all but the first packet, the situation becomes a bit more complex.
User
You said that the sender knows vis SACK that there is space in receiver's buffer, but how can the sender know it if the receiver will not advertise additional buffer space until the missing data is filled?
Assistant
I apologize for any confusion in my previous explanation. Let's clarify the situation.
With SACK (Selective Acknowledgment), the receiver can tell the sender about non-contiguous blocks of data that have been received. This means the sender knows about the gap where the first packet is missing, as well as the fact that subsequent packets have been received. However, the SACK mechanism does not directly inform the sender about the exact amount of free buffer space on the receiver's side.
User
If "The receiver’s advertised window size, which is still based on the traditional cumulative acknowledgment field in the TCP header, reflects the amount of contiguous space available in the receiver’s buffer starting from the last correctly received in-order byte." is true in the case of SACK then you are correct. Is it true?
Assistant
Yes, it is true. In TCP with SACK (Selective Acknowledgment) enabled, the receiver's advertised window size (rwnd) is still based on the traditional cumulative acknowledgment field in the TCP header. The advertised window size reflects the amount of contiguous space available in the receiver’s buffer starting from the last correctly received in-order byte.
Even though SACK allows the receiver to acknowledge the receipt of out-of-order packets, it does not change how the advertised window size is determined or communicated. The receiver's advertised window size tells the sender how much more contiguous data, starting after the highest byte that has been cumulatively acknowledged, it is prepared to receive. It's based on the amount of available space in the receiver's buffer for in-order data.
To sum up:
The cumulative acknowledgment field indicates the byte up to which all data has been received in order without any gaps.
User
But why the receiver cannot set a new window as 1+100? It doesn't have to shift the amount of data received in the sequence before this missing packet. Cannot it split its window?
Assistant
In TCP, the advertised window size cannot be split. The receiver can only advertise a single contiguous window of data that it is prepared to accept starting from the highest in-order byte (the cumulative acknowledgment point). TCP does not have the capability to advertise separate, discontiguous windows ahead of the current acknowledgment point because the design of the TCP header only allows for a single window size value to be communicated.
User
But un theory the receiver can enlarge its window without shifting it from the first unaccented package. Why not?
Assistant
In theory, the receiver could specify additional available space beyond the current window if TCP supported some mechanism to advertise non-contiguous windows. However, as per the TCP protocol defined by the IETF standards, this is not possible because of these reasons:
User
What's the default congestion window in Linux? Hiw does it calculated?
Assistant
As of my knowledge cutoff in 2023, the default initial congestion window size in Linux is typically 10 times the size of the maximum segment size (MSS). This default follows the recommendations from RFC 6928, which suggested increasing the initial congestion window from the previously recommended 3 or 4 MSS to about 10 MSS.
The initial congestion window (cwnd) is a crucial parameter of TCP's congestion control algorithms. It determines the amount of data, in bytes or segments, that the sender can send before requiring an acknowledgment in the start of a TCP connection. This value influences the efficiency of TCP sessions, particularly during the start of data transfer.
The actual initial congestion window size in the Linux kernel can be set using the initcwnd parameter that can be adjusted using the ip route command. Here's an example command that sets the initial congestion window to 10 MSS for traffic going to a specific IP:
User
Cannot congestion window be fixed during entire communication?
Assistant
No, the congestion window (cwnd) cannot be fixed during the entire communication for standard TCP connections. The congestion window is a core component of TCP's congestion control mechanisms, which dynamically adjust how much data can be sent by the sender before requiring an acknowledgment from the receiver.
TCP congestion control algorithms – such as NewReno, CUBIC, and BBR – automatically adjust the size of the congestion window over time based on various signals, including:
User
Can I turn the congestion control off? answer shortly
Assistant
No, you cannot entirely turn off congestion control in standard TCP implementations, as it is a fundamental part of the protocol. However, you can select different congestion control algorithms that may behave differently under various network conditions.
User
How to adapt congestion control to maintain throughput of 400 000 000 000 bit per second with RTT of 10 msec?
Assistant
User
If I need to maintain throughput of 400 gigabit per tsp connection with RTT of 1 ms or less, what's better congestion control algorithm would be employed on Linux?
Assistant
For a high-speed TCP connection aiming to achieve a throughput of 400 gigabits per second with an RTT of 1 ms or less, the BBR (Bottleneck Bandwidth and Round-trip propagation time) congestion control algorithm is a strong candidate to use on Linux.
BBR, developed by Google, is designed to react to actual network conditions rather than only packet loss, which is how traditional congestion control algorithms like Cubic or Reno work. This allows BBR to make better use of available bandwidth, especially on high-speed networks with low latency.
BBR estimates the bottleneck bandwidth and minimum RTT to determine the appropriate rate at which to send data. It does not rely solely on packet loss as an indicator of congestion, which can be particularly useful on paths with a high bandwidth-delay product (BDP) and where packet loss isn't necessarily reflective of congestion (e.g., random loss on undersea cables, wireless networks, etc.).
User
What's better congestion control algorithm with throughput of 50000000 bit per second and RTT of 250 msec?
Assistant
For a lower throughput of 50 megabits per second (50,000,000 bits per second) with a high RTT of 250 milliseconds, you would likely want a congestion control algorithm that is more conservative and can handle long delays effectively. The Cubic algorithm could be a good choice for this situation.
Cubic is designed to perform well in networks with high bandwidth-delay products (BDP) and long-distance links, which often exhibit high RTT. It is less aggressive than some other algorithms in terms of increasing the window size after a congestion event, like packet loss or timeout. This gradual increase allows Cubic to probe the network more carefully, which is suitable for connections with high RTTs, as large and sudden increases in the window size can lead to queuing delays and additional packet loss.
User
What’s better congestion control algorithm with throughput of 500000 bit per second and RTT of 250 msec?
Assistant
With a throughput goal of 500 kilobits per second (500,000 bits per second) and a high RTT of 250 milliseconds, the ideal congestion control algorithm should be one that copes well with high latency and potentially varying bandwidths, while still aiming to fully utilize the available bandwidth.
BBR might still be a good choice for this scenario. It is designed to estimate the network's bottleneck bandwidth and RTT to maximize network utilization while minimizing congestion. BBR's approach to congestion control is not based on packet loss, and it can adapt quickly to changing network conditions, which makes it suitable for networks with large RTTs and where maintaining consistent throughput is crucial.
User
Can you list best congestion control algorithms for special cases, for example for different throughput, RTT and packet loss? Can you compare them and tell about efficiency of using system resources of system that uses that algorithm?
Assistant
User
Which algorithm would be better for YouTube?
Assistant
For a service like YouTube, which streams video content to users over a wide range of network conditions and requires high throughput with minimal buffering delays, a TCP congestion control algorithm that can handle high bandwidth-delay products (BDPs) and minimize latency would be desirable. Google's BBR (Bottleneck Bandwidth and Round-trip propagation time) algorithm is well-suited for this scenario.
User
Which algorithm would be better for Wikipedia?
Assistant
For a website like Wikipedia, which primarily serves text, images, and occasionally other multimedia content, and where the goals include consistent performance, network stability, low latency, and fairness to other users, a well-rounded and proven congestion control algorithm like might be suitable.
User
Which algorithm would be better for online gaming?
Assistant
Online gaming typically requires low latency, fast reaction to network changes, and smooth delivery of small amounts of data. The priority for online gaming is not raw throughput, but rather minimizing jitter (variance in latency) and maintaining a consistent low-latency connection. Given that most online games use UDP for player movements and actions to reduce latency, if TCP is used (for example, for non-time-critical data such as chat or game state updates), then a congestion control algorithm that is responsive and minimizes delay would be beneficial.
User
Which is better for dns over tls service?
Assistant
User
NewReno vs cubic? pros and cons?
Assistant
User
BBR vs CUBIC? Pros and cons?
Assistant
User
What algorithm is the default on Windows, MacOS, Linux, OpenBSD, NetBSD and FreeBSD?
Assistant
User
Is there a Linux option allowing to send duplicated packages before acknowledgment is received? In a case of network with high packet loss for example.
Assistant
User
How to achieve the proactive packet duplication on Linux?
Assistant
On Linux, there is no built-in TCP mechanism for proactive packet duplication. TCP itself is designed to avoid sending duplicates proactively due to the negative impact this would have on network congestion and overall efficiency. However, if you need to proactively duplicate packets to account for a network with extremely high packet loss, you can either do this at the application layer or employ a network-layer solution.
User
How to make MPTCP?
Assistant
User
Is the default Linux settings with manual tuning sizes of sender and reciever's buffer sizes and setting right congestion control algorithm the best and sufficient way to achieve the maximum tcp throughput?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
As of my knowledge cutoff in 2023, the initial window size in Linux is typically set by the following sysctl settings:
net.ipv4.tcp_window_scaling: Enables window scaling as defined in RFC 1323, which must be enabled for window sizes larger than 65535 bytes (the maximum representable in the TCP header without scaling).
net.core.rmem_default: Specifies the default OS receive buffer size for all types of connections.
net.ipv4.tcp_rmem: Defines the minimum, default, and maximum buffer space allocated for TCP sockets' receive buffers.
The tcp_rmem setting has three space-separated values, which specify the minimum, default, and maximum sizes of the receive window. For example, if this setting was 4096 131072 6291456, it would represent 4KB minimum, 128KB default, and 6MB maximum.
The initial window size would typically be based on the default value of this setting, modified by any active window scaling. RFC 6928 allows for a larger initial congestion window (often 10 times the maximum segment size, or MSS), which can improve performance for high-bandwidth, high-latency networks, but the actual value used may be influenced by the kernel version and any modifications by Linux distributors or system administrators.
To get the current values in your Linux system, you can run the following commands:
For your case, if the buffer size is set to a maximum of 1,000,000 bytes, you would need to check the current sysctl settings to understand what the initial window size would be. It's likely to be set at the default unless you have customized your system to increase it up to the buffer size limit. Remember that just because the buffer has the capacity for 1,000,000 bytes doesn't automatically mean that the initial window would be set to that size, especially if the system is using the defaults.
You can check the current initial TCP window size settings on your system by examining the net.ipv4.tcp_rmem sysctl parameter:
sysctl net.ipv4.tcp_rmem
This will return something like:
net.ipv4.tcp_rmem = 4096 131072 6291456
Where the second value (131072 in the example above) is the default receive buffer size, which is used for the initial window size unless there's a different specific setting or policy in place.
Please bear in mind that actual systems you're using in the future may have different defaults. Always refer to the documentation or configuration of the particular system and kernel version you're working with for the most accurate information.
However, this is not standardized and can vary depending on the operating system, kernel version, and specific system configurations. The actual initial window size can be tuned via system configuration settings, such as those available with the net.ipv4.tcp_rmem sysctl setting in Linux.
To find the exact initial receiver window size on a particular Linux system, you would check the current configured values via:
sysctl net.ipv4.tcp_rmem
This will output something like:
net.ipv4.tcp_rmem = 4096 131072 6291456
In this example, 131072 is the default value in bytes which could be used as the initial advertised window size. However, it is not directly related to the value of 10*MSS, which is a measure typically used for the congestion window (cwnd), not the receiver's advertised window.
Kernel Adjustments: The kernel might adjust the buffer size request based on internal minimum and maximum limits.
Window Scaling: If TCP window scaling is enabled (which is likely for buffer sizes larger than 65,535 bytes), the initial window size will be dependent on how window scaling is negotiated during the TCP three-way handshake.
TCP Options and Extensions: The use of certain TCP options and extensions might change how the window size is communicated and utilized.
As such, setting SO_RCVBUF indicates to the system the size that the application wants for the receive buffer. However, the actual initial window size may be influenced by the network stack's algorithms and constraints, particularly in how it adheres to TCP standards and congestion control mechanisms.
To reliably determine the initial window size that will be advertised, you may need to consult the system's TCP implementation details or conduct empirical testing, such as capturing network traffic with tools like tcpdump or Wireshark and observing the TCP window size advertised in the SYN-ACK packet during the TCP three-way handshake.
net.ipv4.tcp_rmem sysctl setting, which defines the default system-wide values for the minimum, default, and maximum receive buffer size for TCP sockets.
However, it's important to note that the actual advertised window size is subject to TCP's flow control mechanisms and may vary during the lifetime of the connection as the sender and receiver exchange data and acknowledgments.
However, there are a couple of nuanced points to keep in mind:
Kernel Modifications: The kernel might adjust the buffer size you set with SO_RCVBUF upwards or downwards, based on its internal minimum and maximum buffer size thresholds.
TCP Window Scaling: For window sizes larger than 65,535 bytes (the maximum that can be directly represented in the TCP header without scaling), TCP window scaling must be negotiated during connection establishment if the window size exceeds this value. The tcp_window_scaling sysctl setting enables or disables this feature.
Thus, while setting the SO_RCVBUF socket option can influence the initial window size, the kernel and TCP protocol mechanisms can also play roles in determining the actual value advertised in the SYN-ACK during the TCP three-way handshake.
Remember, once the connection is established, the advertised window size can dynamically change throughout the life of the connection as part of TCP's flow control mechanism, which aims to match the sender's rate to the receiver's ability to process incoming data.
Field Size: The TCP window scale option uses a 3-bit shift count field. This field specifies how much the window size field in the TCP header should be left-shifted (multiplied by 2^N) to get the actual window size. Since this field is 3 bits, the maximum shift count is therefore 2^3 - 1 = 7, allowing scaling factors from 2^0 to 2^(2^3 - 1) = 2^7 = 128.
Multiplication with the Maximum TCP Window Size: The maximum value of the TCP window field in the header is 2^16 - 1 bytes because it is a 16-bit field. If you apply the maximum scaling factor of 128, you end up with (2^16 - 1) * 128 = 2^24 - 128, which falls well short of 2^32.
RFC 7323 further limits the effective window size by specifying that the scale factor may be used to provide a total window size of up to 1,073,725,440 bytes (2^30), even though the maximum theoretical window (with a shift count of 7) would be slightly larger than this. The window scale option was standardized to accommodate modern high-speed and high-latency networks, known as Long Fat Networks (LFNs), without overhauling the existing 16-bit window size field in the TCP header.
By limiting the TCP window scaling option to 2^14, the goal was to provide sufficient window sizes for contemporary networks without making drastic changes to the TCP protocol. An attempt to support a maximum TCP window size of exactly 2^32 bytes (4 GB) would not only require a larger window scale option field but would also bring additional considerations, such as potential performance issues in handling such large windows on many systems and challenges in efficiently using such large amounts of memory. The limitation to 2^14 provides a practical balance between supporting high-performance networks and maintaining broad compatibility and stability.
This is TCP's way of performing flow control: as data is received and the buffer fills up, the window size is reduced to prevent buffer overflow, telling the sender to slow down. Conversely, as the receiver processes data and frees up buffer space, the window size is increased, allowing the sender to send more data.
Certain circumstances, however, might lead to situations where the window size does not match the buffer size, even if the buffer is empty:
Window Scaling: If the buffer size is larger than 65,535 bytes (the maximum representable value in the TCP window without scaling), TCP window scaling must be used. The actual window size advertised would be the scaled-down value that fits within the 16-bit window field, requiring the sender to apply the scaling factor to determine the real window size.
Minimum Window Size: Some TCP implementations might enforce a minimum window size to maintain a level of network efficiency, so that the window size doesn't become excessively small.
Zero Window Probing: If the receiver has advertised a zero window size because the buffer was previously full, and the buffer becomes empty, the receiver needs to send a window update to the sender to indicate the new available space. Until this update is received, the sender may think the window size is still zero.
In summary, under normal circumstances, the TCP window size can indeed reflect the available space in the receiver's buffer, which is the intended behavior for flow control. However, specific details regarding the TCP window can depend on additional factors like the implementation details of the TCP stack in use, the current state of the connection, and any relevant TCP options like window scaling.
net.ipv4.tcp_rmem
tcp_rmem
sysctl net.ipv4.tcp_rmem
This would output something similar to the following, where the first number is the minimum size in bytes:
net.ipv4.tcp_rmem = 4096 87380 6291456
Minimum Window Size in Slow Start: Although not a minimum window size setting per se, the tcp_base_mss sysctl setting can affect the initial size of the window during the slow start phase. It's used as a reference for the initial congestion window upon establishing a new connection.
Zero Window Probing: TCP automatically handles situations when the window size becomes zero due to a full receive buffer by using zero window probes. The kernel handles these scenarios internally to manage flow control and eventually open the window again when the buffer frees up.
Manual Socket Configuration: By setting SO_RCVBUF using setsockopt(), you can request a specific buffer size for the receive buffer of a socket. This also indirectly affects the advertised window size. The kernel ensures a reasonable amount of the buffer space is always available, which might indirectly set a lower bound.
While there's no explicit setting to enforce a strict minimum window size, these mechanisms can all influence the minimum value of the advertised window size under various conditions. It's important to note that these values are primarily used for the managing of buffer space rather than directly controlling the window size advertised in TCP segments.
Yes, it is theoretically possible for the TCP window size to fit the TCP buffer size and for all packets within the window to be received and acknowledged except the first one. This scenario describes a situation known as "selective acknowledgment" or SACK, which TCP can use to handle situations where packets arrive out of order or specific packets are lost while others following them are received correctly.
Here's how it works:
Selective Acknowledgment (SACK) Option: If both the sender and receiver support the SACK option (RFC 2018), the receiver can inform the sender about which packets have been received successfully, even if they have been received out of order. The SACK option allows the sender to retransmit only the missing segments, rather than all the segments that might follow it, as would be required in simple cumulative acknowledgment.
TCP Performance Impact: If a TCP segment is lost (as in the case with the first packet not being acknowledged), TCP must recover from this situation. TCP uses retransmission timeouts (RTOs) to detect lost packets and resend them. SACK greatly improves efficiency in such cases by allowing the sender to retransmit only the specific missing segments without waiting for a timeout or resending segments that have already been successfully received.
Without SACK, if the first packet in the window is lost, the receiver cannot advance the cumulative acknowledgment pointer beyond this lost packet, and no matter how many subsequent packets are received, the sender will not be aware of them. This is because the standard acknowledgment in TCP is cumulative, acknowledging all data up to the first missing byte. This can lead to a situation known as "head-of-line blocking", which affects performance as the sender may need to retransmit more data than necessary, and the receiver’s buffer cannot be fully utilized until the missing data is recovered.
With SACK, the performance impact is lessened since subsequent packets can be used immediately if needed, and only the lost packets need to be resent, resulting in better utilization of the network and receiver’s buffer.
To summarize, the selective acknowledgment mechanism in TCP allows for more efficient recovery from packet loss, particularly when there are out-of-order packets received while maintaining the TCP window size aligned with the buffer size. This helps to improve overall performance as compared to the traditional cumulative acknowledgment system, especially on networks with higher latency or loss characteristics.
So, if a TCP sender has a large enough congestion window and receive window (the smaller of the two limits the number of bytes that can be sent), it can indeed send up to 1000 packets back-to-back, effectively filling the entire TCP window. This would mean that all 1000 packets are in transit or in the receiver's buffer before any individual acknowledgment has necessarily been received.
The key points to understand in this context are:
Congestion Window (cwnd): This is a TCP state variable that limits the amount of data the sender can have in flight without receiving an acknowledgment. It's used to prevent network congestion and is controlled by the congestion control algorithm (e.g., NewReno, CUBIC).
Receiver's Advertised Window (rwnd): This is the amount of buffer space available at the receiver's end for this connection. The sender must not send more data than the receiver's advertised window allows.
The sender takes the minimum of cwnd and rwnd as the effective window size and can have up to that many bytes unacknowledged at any time.
During the lifetime of a TCP connection, the amount of data in flight, which can span multiple packets, generally corresponds to the effective window size. If acknowledgments are not received in time (leading to a full window of unacknowledged data), the sender must stop and wait for acknowledgments or enough time to pass to invoke a retransmission timeout, if necessary.
This way of operation allows TCP to achieve high-throughput data transmission over a range of network paths with varying characteristics, essentially allowing for the pipelining of data within the limits of the effective window.
Although the receiver has space in its buffer for more packets, TCP does not provide a way to directly communicate this additional available space within its advertised window until the missing packet is received and acknowledged. The reason for this is that TCP relies on in-order delivery, and the acknowledgment number must reflect the last in-order byte that can be read by the application.
However, the receiver can still take advantage of TCP's selective acknowledgment (SACK) mechanism if both sides support it. SACK allows the receiver to acknowledge non-contiguous blocks of data that have been received successfully. While this doesn't directly influence the size of the advertised window (which is based on in-order data), it does inform the sender about which packets have already been received so that the sender doesn't need to retransmit them.
Even with SACK, the receiver’s advertised window will not increase to reflect the additional buffer space beyond the initial window until the missing packet is received and the cumulative acknowledgment can move forward.
So, in practice:
The sender will not try to send more than the missing packet within the initial window size because it hasn't received acknowledgment for the entire window, even if SACK is in use.
The receiver will not advertise the additional buffer space until the hole in the stream (the missing packet) is filled and acknowledged because the TCP advertised window is based on in-order, contiguous data that can be accepted by the receiver without any gaps.
The sender is essentially limited by the smallest of the congestion window (cwnd) and the advertised window size (rwnd); it must wait until the missing packet(s) is acknowledged before it can consider sending additional data into the network to fill the space freed up in the receiver's buffer.
Firstly, TCP uses sequence numbers to keep track of the bytes sent and acknowledged within a connection. Assuming that SACK is in use, the sender knows which specific packets have been received because the receiver includes this information in the SACK option within the acknowledgments.
Given this setup:
The sender knows that packets 2 through 1000 have been received because it receives SACK information showing which bytes have been received but are not yet acknowledged due to the missing packet.
Despite having acknowledged packets 2 through 1000, the receiver’s advertised window does not shift forward, the cumulative acknowledgment number does not update past the first missing packet, and thus the receiver cannot advertise the additional buffer space beyond the initial window.
However, because the sender’s congestion window is 1100 packets, and it knows via SACK that there is space in the receiver’s buffer, the sender may choose to transmit new packets after the already acknowledged packets. These would be packets 1001 through 1100 in sequence numbers.
The sender does not necessarily have to wait for the missing packet to be acknowledged before it can send additional packets because the congestion window allows it. The important point here is that thanks to SACK, the sender knows that there is a gap that needs filling (the first packet), and it knows precisely which packets need to be retransmitted to fill any gaps.
The receiver will not advertise additional buffer space in the form of a larger window until the missing data is filled because the TCP protocol requires in-order data delivery for its cumulative acknowledgments. Even though the receiver has SACK and can manage out-of-order segments that have arrived, it must still respect the cumulative acknowledgment mechanism for window advertisement.
To summarize, with SACK in play, the sender may send additional packets beyond the hole if the congestion window and an understanding of available buffer space allow it. However, the receiver's advertised window will not shift forward until the gap in the byte stream (sequence numbers) is filled.
The sender cannot infer the available buffer space on the receiver side just based on SACK blocks alone. It can only infer which specific packets have been received out of order. The receiver's advertised window size, which is still based on the traditional cumulative acknowledgment field in the TCP header, reflects the amount of contiguous space available in the receiver's buffer starting from the last correctly received in-order byte.
The critical points are:
The receiver's cumulative acknowledgment number cannot advance past the sequence number of the first missing packet, which means it cannot advertise the additional space corresponding to packets that have been received but are after the gap.
While SACK tells the sender that packets after the gap have been received, it does not adjust the receiver’s advertised window size, and thus doesn't signal the available buffer space that has been freed up by the acknowledgment of packets beyond the missing one.
However, if the sender's congestion window (cwnd) is large enough (in your example, 1100 packets) and the SACK has confirmed the receipt of packets 2 through 999, the sender knows that it can send additional packets beyond what was originally in the flight size window, filling the usable space within its cwnd, up to the limit of the receiver's advertised window.
In practice, the sender will continue to respect the receiver's advertised window size based on the last acknowledgment number received. It will not send packets beyond what the receiver has advertised that it can accept, even when aware that some packets have been received out of order. The sender's decision to transmit new packets or retransmit lost packets is based on both the receive window (rwnd) and its congestion window (cwnd), and must always respect the smaller of the two.
SACK options provide additional information on out-of-order bytes/packets that have been received.
The receiver's advertised window reflects the contiguous buffer space following the byte indicated by the cumulative acknowledgment.
Out-of-order packets acknowledged by SACK do not directly increase the advertised window size since the window must represent in-order space available.
The sender must respect the advertised window size provided by the receiver and can only send additional data within that window limit, even if it knows about out-of-order packets received at the receiver.
The TCP receiver's advertised window (rwnd) value effectively means, "Given the current state of my (receiver's) buffer, here's the maximum amount of contiguous data, starting immediately after the last byte I've already acknowledged (the cumulative acknowledgment point), that I am currently willing to receive." This model is based on the fundamental requirement for in-order delivery to the application layer.
When the receiver receives packets out of order and uses SACK to acknowledge them, it can tell the sender that it has received specific discontiguous chunks of data. However, the receiver's buffer is managed in a way that the data can only be processed and consumed by the application when all the data preceding it, including any missing data, has been received.
Here's an example to illustrate why the window cannot be split:
Assume the receiver's buffer has space for 1000 packets, and the receiver gets packets 2 through 1000 but is missing the first packet.
The receiver cannot advertise a new window of 100 packets starting after packet 1000 because it hasn't received packet 1 yet. It must reserve space in the buffer for when packet 1 arrives to ensure proper in-order delivery to the application.
Therefore, the receiver's window is still effectively 0, pending that first packet's arrival. Once packet 1 arrives and is acknowledged, the advertised window can be updated appropriately to reflect the new contiguous space available in the buffer.
The cumulative acknowledgment mechanism, window size advertisement, and TCP flow control are all built around the notion of contiguous data reception and processing. This leads to efficient and orderly data delivery, even though it means the receiver cannot take advantage of the discontiguous free space within its buffer until the missing data is filled in.
TCP Header Limitation: The TCP header contains only one field for the window size (the Advertised Window field), and this field specifies the amount of data the receiver is willing to accept, starting immediately after the last confirmed byte (the cumulative acknowledgment point). There is no provision in the TCP header for indicating non-contiguous availability of receive buffer space.
In-Order Delivery: TCP guarantees in-order delivery to the application layer. If a packet is missing in the sequence, TCP must wait for that packet before delivering any subsequent data. This guarantee simplifies the design of applications, which do not need to handle out-of-order data.
Protocol Simplicity: The decision for this design is based on keeping the protocol simple and avoiding the complexity associated with managing multiple disjointed window spaces. Since TCP can only advertise a single, contiguous window of data that is ready to be received in sequence, it avoids the potential pitfalls of having to deal with multiple discontiguous windows that could make both flow control and congestion control more complicated.
Selective Acknowledgment (SACK): While SACK allows the receiver to inform the sender about which specific packets have been received out of order, it doesn't change the cumulative acknowledgment mechanism or the way the window size is advertised. SACK permits efficient retransmission of lost data but still adheres to the single, contiguous window principle for the advertised window size.
For these reasons, the receiver cannot arbitrarily enlarge its advertised window without moving the window forward in sequence. The receiver will advertise a larger window only when it can accept more contiguous data starting from the last byte acknowledged. Even if there is space in the buffer beyond received out-of-order packets, the TCP protocol does not support advertising it until the missing data is filled and the application can consume the data in order.
ip route change default via <gateway-ip> dev <device> initcwnd 10
Please note that these settings may vary by Linux distribution and kernel version. Additionally, specialized networking stacks or custom-built Linux kernels might use different defaults or provide different mechanisms to adjust the initial congestion window.
Keep in mind that after the connection starts, TCP's congestion control algorithms will adjust the congestion window dynamically based on network conditions such as packet loss, round trip time (RTT), and acknowledgments received, to optimize network throughput while avoiding congestion. These algorithms include variations such as NewReno, CUBIC, BBR, and others.
Acknowledgments (ACKs): These are interpreted as signs that the network is successfully delivering packets. When an ACK is received, it can indicate that it's safe to incrementally increase the cwnd (congestion avoidance phase).
Packet Loss: Detected either through duplicate ACKs or timeouts, packet loss typically results in a reduction of the cwnd (multiplicative decrease) to alleviate potential network congestion.
Round-Trip Time (RTT): Some congestion control algorithms adjust the cwnd based on the duration of the round-trip time, which can vary with network congestion.
The purpose of this dynamic behavior is to balance efficiency and fairness in the use of network resources, while avoiding congestion collapse by reducing traffic when there is network contention.
In specialized cases, or with non-standard implementations of TCP, it might be possible to implement a version of TCP that uses a fixed congestion window. However, this would risk either underutilizing the network (if fixed too low) or causing congestion (if fixed too high) and would not adapt to varying network conditions, which is one of the strengths of TCP.
Implementing a fixed cwnd in TCP on a standard network would contravene the principles of TCP's congestion control and is not recommended in typical use cases._TCP was designed to adapt to changing network conditions to provide reliable, in-order delivery of data while trying to use the available network capacity efficiently without causing congestion.
Maintaining a throughput of 400 gigabits per second (400,000,000,000 bits per second) with a round-trip time (RTT) of 10 milliseconds is a demanding specification that requires proper tuning of various network and TCP parameters as well as sufficient hardware capabilities. Here are several steps to help achieve such high throughput:
High-Bandwidth-Delay Product (BDP): With a high target throughput and a specific RTT, you'll first need to calculate the bandwidth-delay product, which represents the amount of data "in flight" that the network can hold.
BDP (in bits) = bandwidth (in bits per second) × RTT (in seconds)
BDP (in bits) = 400,000,000,000 bps × 0.01s = 4,000,000,000 bits
You'll need to make sure that the TCP window size (both the congestion window and the receive window) can accommodate at least this amount of data. Adjust the TCP window scaling option accordingly, since the standard 16-bit window size field in the TCP header would be too small.
Large Socket Buffers: Configure large socket buffer sizes to match or exceed the BDP. Use the net.core.rmem_max, net.core.wmem_max, net.ipv4.tcp_rmem, and net.ipv4.tcp_wmem sysctl settings to set the maximum receive and send buffer sizes.
Choose an Appropriate Congestion Control Algorithm: Some congestion control algorithms perform better at high speeds and with large BDPs. Consider using algorithms like BBR (Bottleneck Bandwidth and Round-trip propagation time), which is designed to achieve high bandwidths and low latitudes in various conditions.
sysctl -w net.ipv4.tcp_congestion_control=bbr
Ensure Sufficient Hardware and Network Infrastructure: Your servers should have high-speed network interface cards (NICs), and your network infrastructure must support high-speed transmission without bottlenecks.
Use Multiple Parallel Connections: If a single TCP stream cannot achieve the desired throughput due to limitations in TCP or the network path, consider using multiple parallel TCP connections, as is commonly done with protocols like MPTCP (Multipath TCP) or by applications like FTP in its "multi-threaded" or "segmented" mode.
Disable Interrupt Coalescing on NICs: High-throughput scenarios may benefit from disabling coalescing on NICs, where interrupt moderation settings delay packet processing to batch up work, causing increased latency. However, this needs to be balanced as it can increase CPU utilization.
Keep in mind that achieving this level of performance will also depend on the lack of cross traffic and competing flows, as well as the overall quality and capacity of the network infrastructure. These steps involve significant tuning and assume the network infrastructure is capable of supporting such high throughput levels. Any form of network congestion or suboptimal paths can also affect the ability to maintain such a high throughput rate.
To employ BBR on a Linux system, you would typically do the following:
Ensure that your Linux kernel version supports BBR. BBR was merged into the Linux kernel starting with version 4.9.
Activate BBR using the following command:
sysctl -w net.ipv4.tcp_congestion_control=bbr
Remember, apart from choosing the right congestion control algorithm, other parameters need to be considered and possibly tuned, such as the TCP window size (requires window scaling due to the high BDP), buffer sizes, and ensuring that the network hardware (NICs, switches, routers) can handle the target throughput rates.
Always perform testing and monitoring to confirm that the chosen settings are having the intended effect, as real-world network conditions can vary widely and can affect throughput despite theoretical configurations.
Cubic is the default congestion control algorithm in many Linux distributions due to its overall good performance across various network conditions. To ensure Cubic is being used or to explicitly set it as the congestion control algorithm, you can use the following command:
sysctl -w net.ipv4.tcp_congestion_control=cubic
As with any network configuration, the choice of congestion control algorithm should be guided by real-world performance. You should conduct tests under typical network conditions to see how different algorithms affect throughput, delay, and packet loss. You may also consider using tools like iperf or netperf to benchmark the performance of various congestion control algorithms under your specific network conditions.
Additionally, while tuning TCP settings can help optimize performance, achieving optimal performance also greatly depends on factors like the actual capacity of the network path, any intermediate devices or network congestion, cross traffic, and the endpoint hardware.
However, if the network is known to have variable bandwidth or frequent packet loss, you might find that a more traditional algorithm like Cubic or NewReno performs better. These algorithms increase the congestion window more conservatively after packet loss, which can result in more stable throughput under conditions with variable bandwidth or loss.
Ultimately, the best congestion control algorithm for your specific scenario may depend on other factors such as the stability of the available bandwidth, packet loss rates, and the amount of cross traffic. It's recommended to experiment with different algorithms under real-world conditions to see which provides the best balance of throughput, latency, and stability.
Here's how you could switch to BBR on a system that supports it (assuming BBR is compiled into your Linux kernel):
sysctl -w net.ipv4.tcp_congestion_control=bbr
Or to switch back to Cubic (the Linux default for many distributions):
sysctl -w net.ipv4.tcp_congestion_control=cubic
Remember to test your network performance after changing the congestion control algorithm to ensure that it achieves the desired performance. Tools like iperf, netperf, or mtr can help in these tests.
Congestion control algorithms are designed to manage how much data a TCP sender can have in flight to avoid overwhelming the network. Different algorithms excel in different network conditions, such as throughput capacity, RTT, packet loss, etc. Here's a summary of some notable TCP congestion control algorithms and their suitability for particular network scenarios:
NewReno: It's an improvement on the original Reno algorithm and handles multiple packet losses within a single window more effectively than Reno. It's typically well-suited for networks with low to moderate bandwidths and RTTs, and where packet loss is indicative of congestion.
Efficiency: NewReno may not fully utilize very high-bandwidth paths, but it's resource-efficient on the system, as it's a simple algorithm without complex calculations.
Cubic: The default algorithm in many Linux kernels, Cubic is designed for high-speed and long-distance networks. It scales the congestion window cubicly with time since the last congestion event, making it less aggressive in window growth than some other algorithms, which can be beneficial over high RTT links.
Efficiency: Cubic can fill large bandwidths effectively, but it may not react as rapidly to sudden increases in available bandwidth compared to BBR.
BBR (Bottleneck Bandwidth and Round-trip propagation time): Developed by Google, BBR focuses on modeling the network's delivery rate and propagation delay, aiming to increase throughput and decrease latency without causing congestion. It's suitable for various types of networks, from high-speed broadband to mobile networks.
Efficiency: BBR is resource-efficient and aims to maximize network throughput while reducing queuing delay. However, it can be more aggressive, leading to fairness issues on shared networks with non-BBR flows.
Vegas: An older algorithm that bases its congestion avoidance on measuring RTTs, aiming to detect congestion before packet loss occurs. It works well in environments where packet loss is not a reliable indicator of congestion.
Efficiency: Vegas may not achieve the highest throughput in high-bandwidth environments but can be useful in preventing bufferbloat due to its early congestion detection.
Westwood+: It is especially suitable for networks with variable bandwidth, such as wireless or mobile networks, as it uses an estimation of bandwidth based on the rate of returning acknowledgments to adjust the cwnd after a packet loss event.
Efficiency: Westwood+ can result in better performance than NewReno on links with packet loss unrelated to congestion, as it more aggressively restores the cwnd after losses.
HighSpeed TCP: Designed for high-speed, long-distance networks, HighSpeed TCP adjusts the increase and decrease of the congestion window size to achieve higher throughput for such paths.
Efficiency: While HighSpeed TCP is more aggressive in increasing the congestion window, it might not compete fairly with standard TCP traffic and could lead to higher packet loss rates in diverse traffic conditions.
Each of these algorithms attempts to balance network throughput, latency, and loss while being fair to other flows. However, the efficiency of system resource usage by these algorithms can vary depending on factors such as the complexity of the algorithm and the system's ability to handle higher throughput rates (e.g., CPU utilization, NIC capabilities, and system buffers). The choice of an algorithm should be guided by the specific requirements of the network it operates in, and its efficiency should be evaluated in terms of both network and system performance.
In real-world applications, you should assess these algorithms' performance on your network by using benchmarking and monitoring tools and consider factors like fairness, convergence speed, and reaction to network change events, along with raw throughput and latency measurements.
Here's why BBR could be a good fit:
Adapts to Network Conditions: BBR estimates the network's bottleneck bandwidth and end-to-end RTT, allowing it to adapt effectively to varying network conditions and maximize throughput while minimizing latency.
Handles High Latency and Bandwidth Environments: BBR performs well in both high-latency and high-bandwidth environments, making it suitable for the global reach and diverse user base of YouTube.
Reduces Bufferbloat: Traditional algorithms that rely on packet loss as a signal of congestion can contribute to excessive buffering (bufferbloat), leading to higher latency. BBR aims to prevent this by reacting to actual throughput and delay, rather than loss.
Fairness and Coexistence: While BBR can be more aggressive than some other congestion control algorithms, it is designed to coexist on networks with other flows. Its behavior helps ensure that YouTube streams perform well, even when competing with other traffic.
In practice, Google has deployed BBR across its own services, including YouTube. This has resulted in increased throughput and reduced latency when streaming video content under various network conditions. Google's large-scale deployment of BBR has demonstrated its effectiveness for their services, and real-world metrics have shown improvements in network performance and quality of experience for end-users.
When considering the deployment of any congestion control algorithm for a specific application or service, it's essential to conduct thorough testing in a controlled environment that reflects your end-user network conditions. The best choice can vary based on the network infrastructure, application requirements, and user expectations.
Cubic
Here are a few reasons why Cubic could be a good choice:
Good for Diverse Networks: Cubic performs well over a wide range of network conditions, which is important for Wikipedia, as it has a global user base with varying internet speeds and latencies.
Fairness: Cubic is designed for fairness, sharing network capacity equitably with other Cubic flows, and even with other congestion control algorithms like Reno and NewReno.
Scalability: Cubic scales well with increasing bandwidth and longer latencies. It is less aggressive than some high-speed algorithms, making it less likely to cause congestion in networks with mixed traffic.
Default Choice: It is the default TCP congestion control algorithm in many Linux distributions due to its robust performance across different network types, which simplifies deployment and maintenance.
While BBR, as mentioned previously, can offer benefits in terms of throughput and latency, the network environment where Wikipedia is accessed could be quite heterogeneous, with varying qualities of connections, which might favor an algorithm designed with fairness and stability in mind, like Cubic.
It's worth noting that Wikimedia Foundation infrastructure could use other optimizations on top of TCP congestion control to improve performance, like content delivery networks (CDNs), caching, and HTTP/2 or HTTP/3 (which includes QUIC), especially to serve static content more efficiently.
In practice, the choice of the congestion control algorithm also depends on the hosting and network infrastructure used by Wikipedia, as well as the typical interaction model of the users with the website. For interactive use with many small requests and responses, the congestion control algorithm might be less critical than for streaming or bulk data transfer scenarios.
As always, the actual choice is best made based on real-world tests and monitoring, considering both end-user performance and overall network behavior.
BBR (Bottleneck Bandwidth and Round-trip propagation time) could be a good candidate because it is designed to keep latency low and achieve a high network throughput. BBR aims to fill the network pipe just enough to achieve maximum throughput without causing queues to build up, which can introduce latency—essential in gaming where any delay can impact the gameplay experience.
However, if packet loss is indicative of congestion in the particular network path for the game server, traditional congestion control algorithms like NewReno or CUBIC (the latter being the Linux default) could be effective as well since they back off the sending rate upon detecting packet loss, potentially avoiding further congestion and the resulting jitter or spikes in latency. They may not provide the absolute lowest latencies, but they are well-understood, stable, and operate fairly with respect to other network traffic.
For gaming, any chosen TCP congestion control method should complement other latency-reducing techniques such as:
Employing Quality of Service (QoS) rules to prioritize gaming packets.
Using a game server network that is geographically close to players to reduce RTT.
Utilizing fast retransmit and fast recovery mechanisms in TCP to handle packet loss efficiently.
It's important to remember that because online games often use UDP for their real-time elements, the choice of TCP congestion control may only be relevant for supplementary or non-real-time components of the game. For the real-time gaming data, developers often implement custom transport protocols atop UDP or other means to handle packet loss and ordering that suit the low-latency requirements of online games.
Lastly, care should be taken to ensure the network conditions are suitable for any chosen algorithm. Performance testing and real-world user feedback should inform the choice to ensure the best gaming experience.
DNS over TLS (DoT) is designed to provide privacy and security by encrypting DNS queries. Because DoT uses TCP as the underlying transport protocol, the choice of congestion control algorithm doesn't impact the performance as much as it would for bulk data transfer services. This is due to the small size and transactional nature of DNS queries and responses.
For DoT, the primary concerns are about minimizing latency and establishing quick and efficient connections. Given these goals, there are a couple of TCP congestion control algorithms that could be suitable:
BBR (Bottleneck Bandwidth and Round-trip propagation time): It could be favorable due to its ability to minimize RTT and deliver stable performance across different network conditions. Since BBR focuses on maximizing bandwidth while minimizing delays, it can be particularly beneficial for initial connection establishment and speedy transmission of small queries, as it avoids excessive reductions in speed due to packet loss. However, BBR's behavior in mixed traffic conditions or networks with varying or unstable bandwidth should be considered.
CUBIC: As the default on many Linux systems, CUBIC might also be a reasonable option due to its robustness and scalability. While it may not be as latency-focused as BBR, CUBIC's design aims for fair bandwidth sharing and could be more predictable in networks with a mix of traffic patterns.
For either algorithm, performance considerations for DoT are likely to be less about congestion control and more focused on factors like:
TLS handshake performance (connection and encryption establishment times).
General TCP tunings, such as initial congestion window size and socket buffer sizes, that match the typical size of DNS messages.
Network path characteristics between the client and the DNS resolver (proximity, reliability, and base latency).
In practice, because the data packets for DNS are small and connections are often short-lived, the choice of TCP congestion control algorithm might have a negligible impact on performance. It's more crucial to ensure that the DNS software stack is efficient, the TLS implementation is fast, and the network path is optimized for low-latency communications.
Ultimately, testing in real-world conditions is the best way to decide which congestion control algorithm is most suitable for your specific DoT deployment scenario. Benchmarks should measure the time from sending the DNS query to receiving the response under various network conditions to assess the end-to-end latency experienced by clients.
NewReno and CUBIC are both TCP congestion control algorithms, but they operate differently and have different performance characteristics. Here’s a comparison between the two:
NewReno
Pros:
Good for networks with low to moderate bandwidth and latency.
Works well with small-scale or legacy systems where packet loss is relatively common and indicates network congestion.
It's a conservative algorithm, and its slow-start and congestion avoidance algorithms are quite robust in various network conditions.
NewReno reacts quickly to packet losses (considered a sign of congestion) by reducing its congestion window (cwnd) and gradually increasing it as more acknowledgments are received.
Cons:
Not optimized for high-speed, long-distance networks with large bandwidth-delay products (BDPs). NewReno tends to underutilize available bandwidth in such networks due to its conservative approach to increasing the congestion window.
NewReno can result in reduced throughput and longer times to recover from packet loss in high-bandwidth or high-latency networks compared to more aggressive algorithms like CUBIC.
Its slow growth of the congestion window can lead to lower overall throughput in environments with temporary or random packet loss unrelated to actual congestion.
CUBIC
Pros:
CUBIC is specifically designed for high-speed, long-distance networks (high BDP environments) and scales the congestion window more aggressively to achieve larger window sizes without being overly sensitive to individual packet losses.
It improves upon NewReno's performance in networks where loss doesn't necessarily signal congestion (such as networks with high error rates or wireless networks).
CUBIC has a concave window growth function that allows for smoother increments in cwnd, which can be more fair and stable when sharing network capacity with other flows.
CUBIC adjusts its rate of cwnd growth based not on time since the last loss event (as in TCP Reno/NewReno) but rather on the cwnd size, making it less aggressive for smaller cwnds and more aggressive for larger cwnds, which can be beneficial for network performance during varying conditions.
Cons:
CUBIC may not always respond quickly enough to changes in available bandwidth or sudden increases in network latency, potentially leading to temporary periods of underuse or overuse of network resources.
It may not be as fair to flows with traditional algorithms like Reno or NewReno in mixed environments because of its more aggressive nature when the cwnd is large.
In networks with low BDP or where packet loss is a reliable congestion signal, CUBIC's aggressiveness may lead to more pronounced oscillations in the sending rate, which can affect the stability of the network.
Ultimately, the best choice between NewReno and CUBIC depends on the characteristics of the network in which they are used. For modern, high-speed Internet backbone networks, CUBIC is often the better choice and is the default on many Linux systems. However, in networks where bandwidth is limited, latency is low, or packet loss is a reliable indicator of congestion, NewReno or similar algorithms may perform better. As always, real-world testing in the target environment is essential to determining the best algorithm for any given scenario.
BBR (Bottleneck Bandwidth and Round-trip propagation time) and CUBIC are both TCP congestion control algorithms, but they use fundamentally different approaches to congestion control. Each has its own set of advantages and disadvantages.
BBR
Pros:
Responsiveness to Actual Bandwidth: BBR estimates the bottleneck bandwidth and round-trip propagation time to determine the optimal data sending rate, allowing it to effectively utilize the available bandwidth without being dependent on packet loss as a congestion signal.
Minimized Latency: BBR aims to reduce bufferbloat by sending data at a rate that is calculated not to exceed the network's actual bandwidth capacity, potentially decreasing latency and providing consistent throughput.
Performance in High-BDP Networks: BBR can perform well in high bandwidth-delay product (BDP) environments, often outperforming CUBIC and other loss-based algorithms in such contexts.
Multiple RTTs for Bandwidth Estimation: BBR takes multiple rounds of RTT measurements to update its model of the network path, leading to potentially more accurate bandwidth provisioning.
Cons:
Fairness Issues: BBR might not always coexist fairly with loss-based algorithms like CUBIC, particularly in shared networks; it can consume a greater share of the bandwidth.
Performance Under Packet Loss: If packet loss occurs not because of congestion but due to the poor quality of the link, BBR might underperform by continuously trying to probe for higher bandwidths.
Oscillations: BBR can lead to throughput oscillations as the algorithm continuously probes for more bandwidth or backs off in case of potential congestion.
CUBIC
Pros:
Scalability: CUBIC scales the congestion window using a cubic function, making it very effective on networks with high bandwidth and high latency (high BDP).
Stability and Fairness: CUBIC is designed to be fair to multiple flows sharing the same network path and generally seeks a balance that avoids starving other connections of bandwidth.
Fallback to loss-based congestion control: CUBIC falls back to loss-based congestion control when it detects packet drops or ECN (Explicit Congestion Notification) signals, which makes it perform well in a mixed environment with various congestion control algorithms.
Widely Deployed: As the default congestion control algorithm in many Linux distributions, CUBIC is well-studied, tested, and continuously updated to improve performance.
Cons:
Reliance on Packet Loss: CUBIC inherently uses packet loss as an indicator of congestion, which can lead to suboptimal performance in networks where loss occurs independently of congestion (e.g., wireless networks).
Bandwidth Utilization: It might not utilize the path capacity as efficiently as BBR in certain scenarios, especially when competing with BBR flows.
Bufferbloat: CUBIC's aggressiveness in increasing the congestion window can lead to bufferbloat, contributing to higher latency.
Ultimately, the choice between BBR and CUBIC depends on the specific network characteristics and the type of traffic. BBR may offer lower latency and better bandwidth utilization in high-speed networks but may require careful monitoring for fairness and performance stability. In contrast, CUBIC is a more traditional and well-established choice, especially in environments where throughput and fairness across different traffic flows are top priorities.
Real-world testing is essential for selecting between BBR and CUBIC, as network performance can vary widely based on the mix of traffic, available infrastructure, and current network conditions.
Each operating system may use different default TCP congestion control algorithms, and these can change with software updates. Generally, the defaults as of my knowledge cutoff in 2023 are:
Windows:
Windows typically uses a proprietary congestion control algorithm. Until Windows 10, it used Compound TCP (CTCP) as the default algorithm, which aims to achieve high performance on networks with a high bandwidth-delay product while being fair to other traffic.
More recent versions have introduced CUBIC as the default, with options to select alternative algorithms depending on the version and network configuration.
macOS:
macOS has traditionally used the NewReno congestion control algorithm as the default.
It's possible for users to select alternative algorithms (like CUBIC) through the use of system parameters or networking APIs, depending on the macOS version and developer options.
Linux:
Most modern Linux distributions use CUBIC as the default TCP congestion control algorithm.
Linux kernels typically support several other congestion control algorithms as well, including BBR, NewReno, and Vegas, among others, which can be selected by changing sysctl settings.
OpenBSD:
OpenBSD has previously used variants of NewReno; newer versions of OpenBSD have introduced CUBIC and BBR, and one of these may be selected as the default depending on the version.
OpenBSD often focuses on simple, auditable, and secure code, and this can influence their choice of network algorithms.
NetBSD:
NetBSD tends to be quite modular and historically has often used NewReno as the default.
As with other BSDs, it's possible for users to change the congestion control algorithm depending on the system's configuration and capabilities.
FreeBSD:
NewReno has been the traditional default in FreeBSD, suitable for a wide range of network conditions.
FreeBSD 9.0 and later versions support CUBIC and starting from FreeBSD 12.0, BBR is also available. Users can change the default congestion control algorithm to CUBIC or others via sysctl settings.
Do note that defaults can vary not only by operating system but also by version, build or the specific choices made by a system administrator. Additionally, networking stacks can be updated, or different congestion control algorithms can be preferred by users or system administrators for specific workloads or network conditions. Always refer to the latest documentation or the system's current configuration to determine the default settings for any given environment.
Linux does not provide a standard kernel option specifically designed to intentionally send duplicate packets for the same data before an acknowledgment is received, as this behavior is not part of the standard TCP protocol. TCP is designed to handle retransmissions based on the lack of acknowledgments or the reception of duplicate acknowledgments, which imply that a packet has been lost.
However, for cases where there is an expectation of high packet loss, there are methods to mitigate this. For non-TCP protocols, like UDP, applications frequently implement their own reliability mechanisms, which might include sending duplicate packets.
For TCP in high-loss environments, you might consider the following approaches:
Tune Retransmission Timers: Adjust the TCP retransmission timers to be more aggressive. Linux allows configuring the TCP retransmission timeout (RTO) values via sysctl settings. For example, you can reduce the tcp_retries2 value, which defines the number of times TCP attempts to retransmit a packet before a connection is considered broken.
Select an Appropriate Congestion Control Algorithm: Choose a congestion control algorithm that responds better to packet loss, such as BBR, which doesn't solely rely on loss detection to adjust its sending rate.
Forward Error Correction (FEC): This is a method used in some network protocols (outside of standard TCP) where additional information is sent along with the original data. This can be used to reconstruct lost packets without the need for a retransmission.
Multipath TCP (MPTCP): This allows the use of multiple paths for a single TCP connection, which can provide redundancy and potentially overcome packet loss on any single path.
Application-Level Redundancy: Implement redundancy in the application layer logic, which can include sending important data more than once or using custom protocols over UDP to achieve similar effects.
Use Reliable UDP-based Protocols: Consider using reliable UDP-based protocols like QUIC, which is designed to be more resilient to packet loss and to recover from loss more quickly than traditional TCP.
Packet Duplication: For non-critical systems where bandwidth is not a concern, and the goal is simply to mitigate high packet loss, a network appliance or software that duplicates packets over the network could be deployed, but this would be unusual and inefficient.
It's important to note that duplicating packets proactively can lead to significant bandwidth waste and potentially exacerbate congestion, so this approach is generally not recommended unless it's a last resort for specific use cases. More commonly, addressing high packet loss involves improving the network infrastructure, using more robust error handling at the application layer, or employing a more suitable protocol for the conditions at hand.
For achieving packet duplication on Linux, you might consider the following unconventional approaches:
Application Layer Duplication:
Modify the application sending the packets to send each piece of data multiple times. This method gives you full control over which data is duplicated and when, but it increases bandwidth usage and is not a standard practice.
Custom Transport Protocol:
Implement a custom transport protocol on top of UDP which sends duplicate packets. Tools and libraries like libutp (µTP) or ENet could be starting points to build such protocols.
Network Tunnels with Duplication:
Set up a network tunnel that duplicates packets as they go through. Software such as socat can help create such tunnels with some level of redundancy, although it may not strictly duplicate every packet. It is more commonly used to create redundancies at the connection level.
Network Tools with Duplication Features:
Utilize specialized network software that can add redundancy by duplicating packets. One such tool is teql (Traffic Equalizer) in conjunction with the Advanced Routing functionality in Linux (iproute2 package).
Remember, these methods are generally not recommended for common network scenarios because duplicating packets can be highly inefficient and counterproductive in the broader context of a healthy network. Besides, they can lead to additional complexity and difficulty in managing the connection states.
Before resorting to such methods, it's important to explore if the network issues can be mitigated with better infrastructure, using error correction approaches, optimizing the existing application or protocol behavior, or simply moving to a more suitable protocol for unreliable connections, such as QUIC, which is designed to handle unreliable conditions better than TCP. Additionally, for high-loss networks, mechanisms like Forward Error Correction (FEC) at the application or transport layer might be a more effective strategy, as they can reconstruct lost data without needing the exact duplicate packets.
Multipath TCP (MPTCP) is an extension to TCP that enables a single TCP stream to use multiple network paths simultaneously. MPTCP can improve resource utilization, redundancy, and throughput by combining the bandwidth of multiple network interfaces and providing better resilience to network failures. Here's a general guide on setting up MPTCP:
Check Kernel Support:
First, ensure that your Linux kernel supports MPTCP. MPTCP support has been included in the mainline Linux kernel starting with version 5.6. If you have an older kernel, you may need to install an MPTCP-patched kernel.
Enable MPTCP:
On supported kernels, enable MPTCP using the sysctl command. Open a terminal and run:
sysctl -w net.mptcp.enabled=1
Some systems may require other configuration parameters adjusted. You can list all available MPTCP sysctl parameters with:
sysctl net.mptcp
Configure Path Manager and Scheduler:
MPTCP offers different path management and scheduling strategies. Path managers control how subflows are created, while schedulers determine how data is distributed across the subflows. Set the desired path manager and scheduler:
sysctl -w net.mptcp.mptcp_path_manager=fullmesh # Example: fullmesh, ndiffports, etc.
sysctl -w net.mptcp.mptcp_scheduler=default # Example: default, roundrobin, etc.
Set Up Network Interfaces:
MPTCP is designed to utilize multiple network interfaces. Make sure that multiple interfaces (like Ethernet, Wi-Fi, or cellular modems) are configured and connected to different networks to take advantage of MPTCP's path redundancy and potential increased throughput.
Testing MPTCP:
Test if MPTCP is working by connecting to an MPTCP-capable server. You can use tools like iperf3 compiled with MPTCP support or connect to public MPTCP-capable servers to test the performance.
iperf3 -c mptcp-capable.server.address -P 4 # Example: Use four concurrent streams
Application Considerations:
On the application layer, most software does not need to be aware of MPTCP. The kernel handles the MPTCP connections transparently. However, for applications to fully leverage MPTCP, servers must also support MPTCP.
Monitor MPTCP Connections:
You can monitor MPTCP connections like regular TCP connections using standard tools like ss or netstat. MPTCP-capable connections will show additional subflow information.
ss -mptcp # Specifically show MPTCP connections
It is important to note that for a successful MPTCP setup, both the client and server must support MPTCP. If you're setting up an environment that requires specific MPTCP functionality, consider referring to the official MPTCP project documentation for detailed guidelines and up-to-date information:
https://www.multipath-tcp.org/
Please be aware that MPTCP's behavior may significantly depend on the network environment, the configuration of intermediate devices (like NATs and firewalls), and the selected path manager and scheduler strategies. For production environments, careful testing and tuning are necessary to ensure optimal performance and compatibility.
The default Linux TCP settings are designed to provide a good balance of performance for general network conditions; however, they may not be optimized for all scenarios, particularly those requiring maximum TCP throughput. To achieve the best possible performance, manual tuning is often necessary. Here are key factors to consider:
Buffer Sizes:
Ensure that your TCP buffer sizes (net.core.rmem_max, net.core.wmem_max, net.ipv4.tcp_rmem, net.ipv4.tcp_wmem) are large enough to accommodate the bandwidth-delay product (BDP) of your connection.
Buffer sizes should be tuned to match or exceed the BDP for optimal throughput.
Congestion Control Algorithm:
Choose the right congestion control algorithm based on your specific network environment. For high-speed, long-distance networks, algorithms like BBR or CUBIC may yield better performance.
Window Scaling:
Ensure TCP window scaling is enabled (net.ipv4.tcp_window_scaling) to allow for larger window sizes needed for high-throughput connections.
Selective Acknowledgments (SACK):
Verify that SACK is enabled (net.ipv4.tcp_sack) to improve performance in cases of packet loss.
TCP Timestamps:
Consider enabling TCP timestamps (net.ipv4.tcp_timestamps) if supported, which can help with RTT estimation and protect against wrapped sequence numbers in very high-speed connections.
MTU Size:
Adjust the Maximum Transmission Unit (MTU) to the highest stable value supported by the network to reduce fragmentation and overhead.
Nagle's Algorithm:
Depending on your application's nature, disabling Nagle's Algorithm (TCP_NODELAY socket option) can reduce latency for small packets, commonly used in interactive applications.
Offloading Features:
Enable TCP offloading features on your network interface cards (NICs) if available, such as TSO (TCP Segmentation Offload), GSO (Generic Segmentation Offload), and checksum offloading to reduce CPU usage.
Monitoring and Testing:
Regularly monitor network traffic and performance to identify bottlenecks. Use testing tools like iperf to benchmark and verify the effect of your tuning efforts.
While manual tuning can improve performance, achieving maximum TCP throughput is multifaceted. It requires an understanding of the network path characteristics, the capabilities of the hardware, and the nature of the application traffic, along with a willingness to experiment and continuously adjust configurations.
Furthermore, external factors such as cross-traffic, intermediate network devices, and packet loss behavior in the network can affect throughput, regardless of local tuning. Therefore, while adjusting Linux settings is a vital step towards maximum throughput, it's one part of a whole-system approach to network optimization.