TCP Parameter Optimization in Windows

Source: Internet
Author: User

Last article: TCP connection status and closing method, and its impact on server and client

Generally, the Windows system parameters are improved by modifying the registry. The following describes the TCP Parameter Optimization Methods for Windows 2003, Windows XP, Windows 7, and server. The optimization methods vary with the specific system environment and performance requirements, and the effects are also different. They are only personal suggestions. All optimization operations are implemented by modifying the Registry. You need to run the Regedit command to enter the registry and create or modify parameters. After the modification, You need to restart the system to make it take effect. The following values are in hexadecimal notation.

1.Tcpwindowsize

The value of tcpwindowsize indicates the size of the TCP window. TCP receive window (TCP Data receiving buffer) defines the maximum number of bytes that can be sent by the sending end without receiving confirmation from the receiving end. The larger the value, the less information will be returned, and the better the communication between the sending end and the receiving end. This value can reduce the possibility of timeout when the sender waits for the receiving end to return confirmation information, but this increases network traffic and reduces the effective throughput. TCP dynamically adjusts an integer multiple of the maximum segment length (MSS) (maximum segment size) between the sending end and the receiving end. The MSS determines when the connection is established. Because the TCP receive window is adjusted to an integer multiple of the MSS, the proportion of TCP data segments with full length increases during data transmission, thus improving the network throughput.

By default, TCP tries to optimize the window size based on MSS. The initial value is 16 KB and the maximum value is 64 KB. The maximum tcpwindowsize is usually 65535 bytes (64 KB), the maximum length of the Ethernet segment is 1460 bytes, and the maximum integer multiple below 1460 of 64 KB is 62420 bytes, therefore, you can set tcpwindowsize to 62420 in the registry as the applicable performance optimization value for high-bandwidth networks. The procedure is as follows:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named tcpwindowsize under the parameters subkey, the value ranges from 0 to 65535 and is set to 62420.

2.Tcp1323opts

to make more efficient use of the high-bandwidth network, you can use a TCP window larger than the preceding TCP window, this feature is a new feature in Windows 2000 and Windows Server 2003, known as TCP Window Scaling, which increases the previous 65535-byte (64 KB) limit to 1073741824-byte (1 GB ). For connections (such as satellite connections) with a high product of bandwidth and latency, you may need to increase the window size to more than 64 KB. Using TCP Window Scaling, the system can confirm the transmission of larger data volumes between information, increasing network throughput and performance. The time required for the round-trip communication between the sender and the receiver is called the Back-to-Loop Time (RTT ). TCP Window Scaling is valid only when both TCP connections are enabled. TCP has a timestamp option that increases the estimated RTT value by more frequent calculation. This option is particularly helpful in estimating the RTT value of a wide-area network connection over a longer distance, and adjust the TCP Retransmission timeout time more accurately. The timestamp is provided in the TCP Header in two regions. One record starts to resend and the other record receives the time. The timestamp is especially useful for TCP Window Scaling, that is, to confirm the transmission of large data packets before the message is received. The activation timestamp only adds 12 bytes to the header of each data packet, and has little impact on network traffic. Which of the following is more important for data integrity and data Throughput Maximization. In some environments, for example, video stream transmission requires a larger TCP window, which is the most important, while data integrity ranks second. In this environment, TCP Window Scaling does not open the timestamp. This feature is valid only when both the sender and receiver activate TCP Window Scaling and timestamp. However, if a timestamp is added during packet sending, after Nat, if the same port in front is used and the timestamp is greater than the timestamp in the SYN from the connection, the server ignores the SYN, indicating that the user cannot complete the TCP three handshakes normally. Initially, a small TCP window is generated, and the window size increases according to the internal algorithm . The procedure is as follows:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey and create or modify the REG_DWORD value named tcp1323opts under the parameters subkey. the specific meaning of this value is: 0 (default) indicates to disable TCP Window Scaling and timestamp; 1 indicates to enable only TCP Window Scaling; 2 indicates to enable only timestamp; 3 indicates to enable both TCP Window Scaling and timestamp. After tcp1323opts is set to activate TCP Window Scaling, you can increase the value of the preceding registry key tcpwindowsize to 1 GB. To achieve optimal performance, the value here should be set to a multiple of MSs. The recommended value is 256960 bytes.

3.TCPControl Block table

For each TCP connection, the control variables are stored in a memory block called a TCP Control Block (TCB. The size of the TCB table is controlled by the maxhashtablesize registry. In systems with many active connections, setting a large table can reduce the time for the system to locate the TCB table. Partitioning on a TCB table can reduce the competition for table access. By increasing the number of partitions, TCP performance will be optimized, especially in multi-processor systems. Registry entry numtcbtablepartitions controls the number of partitions. The default value is the square of the number of processors. TCB is usually pre-configured in the memory to prevent repeated TCP connections and disconnections. It is a waste of time to locate TCB repeatedly. This buffer method promotes memory management, however, the number of TCP connections allowed at the same time is also limited. The registry entry maxfreetcbs determines the number of connections before the idle wait TCB is available again. It is often set to a value higher than the default value in the NT architecture to ensure that there is enough preset TCB. A new feature has been added since Windows 2000 to reduce the possibility of running TCB exceeding the preset. If the number of connections in the waiting state is greater than that set in maxfreetwtcbs, all connections that have waited for more than 60 seconds will be forcibly disabled and will be enabled again later. After this feature is merged into Windows 2000 Server and Windows Server 2003, maxfreetcbs will no longer be used to optimize performance. Specific operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named maxhashtablesize under the parameters subkey, the value ranges from 1 to 65536, and must be the Npower of 2. The default value is 512. We recommend that you set this value to 8192. Create or modify the REG_DWORD value named numtcbtablepartitions under the parameters subkey. The value ranges from 1 to 65536, and must be 2 to the Npower. The default value is the square of the number of processors, we recommend that you set it to 4 times the number of processor cores.

4.Tcptimedwaitdelay

The value of tcptimedwaitdelay indicates the waiting time before the system releases closed TCP connections and reused its resources. The time interval is the time_wait State mentioned in the previous blog (2msl, which is twice the maximum data packet lifecycle ). If the system shows that a large number of connections are in the time_wait status, the concurrency and throughput will be seriously reduced. By reducing this value, the system can release closed connections more quickly, in this way, more resources are provided for new connections, especially for servers with high concurrency and short connections.

The default value of this item is 240, that is, to release resources after 4 minutes. The minimum value supported by the system is 30, that is, the waiting time is 30 seconds. Specific operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named tcptimedwaitdelay under the parameters subkey, the value ranges from 0 to 300. We recommend that you set this value to 30.

5.Maxuserport

The value of maxuserport indicates thatProgramMaximum port number that can be allocated by TCP/IP when requesting available ports from the system. If the system displays an exception during connection establishment, it may be caused by insufficient number of anonymous (temporary) ports, especially when the system opens a large number of ports to establish connections with Web Services, databases, or other remote resources.

The default value of this item is 5000 in decimal format, which is also the minimum value allowed by the system. By default, Windows uses anonymous (temporary) ports to retain port numbers ranging from 1024 to 5000. To obtain a higher concurrency, we recommend that you set this value to at least 32768 or even a theoretical maximum of 65534, especially for the client that simulates the high concurrency test environment. Specific operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named maxuserport under the parameters subkey, the value ranges from 5000 to 65534. The default value is 5000. We recommend that you set this value to 65534.

6. Dynamic Reserve

The value of the dynamic reserve enables the system to automatically adjust its configuration to accept a large number of sudden connection requests. If a large number of connection requests are received at the same time, the system's processing capability is exceeded, the dynamic reserve will automatically increase the number of temporary connections supported by the system (that is, the number of waiting connections requested by the client and not processed by the server, and the total number of TCP connections includes the number of established connections and the number of waiting connections ), this reduces the number of connection failures. When the system's processing capability and the number of supported temporary connections are insufficient, the client's connection request will be rejected directly.

By default, dynamic reserve is not enabled for windows. You can enable and set it using the following operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ AFD \ Parameters registry subkey, and create or modify the REG_DWORD value of the following name under the parameters subkey.

    • EnableDynamicBacklog. The value is 1, indicating that dynamic reserve is enabled.
    • Minimumdynamicbacklog. The value is 128, indicating that the minimum number of temporary connections supported is 128.
    • Maximumdynamicbacklog. The value is 2048, indicating that the maximum number of temporary connections supported is 2048. For highly concurrent short-connection servers, we recommend that you set the maximum value to 1024 or above.
    • DynamicBacklogGrowthDelta, with a value of 128, indicates that the number of supported temporary connections is increased by 128, that is, when the number is insufficient, it increases by 128 until it reaches the set maximum value, such as 2048.

7.KeepAliveTime

The value of KeepAliveTime controls how often the system tries to verify that idle connections are still intact. If the connection is not active for a period of time, the system will send a signal to maintain the connection. If the network is normal and the receiver is active, it will respond. If you need to be sensitive to the loss of the receiver, that is, you need to identify whether the receiver is lost more quickly, please reduce this value. If idle connections that are not active for a long time appear frequently, but the number of lost receivers is less, you may need to increase the value to reduce the overhead.

By default, if the idle connection is not active within 7200000 milliseconds (2 hours), the system will send a message to keep the connection. We recommend that you set the value to 1800000 ms, so that the lost connection will be detected within 30 minutes. Specific operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named KeepAliveTime under the parameters subkey, and set the appropriate number of milliseconds for this value.

8.Keepaliveinterval

The value of keepaliveinterval indicates the frequency at which the system repeatedly sends the "keep connection" signal when the other party does not receive the response to the "keep connection" signal. If no response is received, the connection is dropped when the number of consecutive "keep connection" Signals exceeds the value of TCPMaxDataRetransmissions (described below. If the network environment is poor and a long response time is allowed, increase the value to reduce the overhead. If you need to verify whether the receiver has been lost as soon as possible, reduce the value or TCPMaxDataRetransmissions.

By default, the system will wait 1000 milliseconds (1 second) until the "keep connection" signal is sent again without receiving a response. You can modify the parameters as needed:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named keepaliveinterval under the parameters subkey, and set the appropriate number of milliseconds for this value.

9.TCPMaxDataRetransmissions

The value of TCPMaxDataRetransmissions indicates the number of times TCP data segments are resold over an existing connection. If the network environment is poor, you may need to increase the value to maintain effective communication and ensure that the receiver receives the data. If the network environment is good, or data is usually lost due to the loss of the receiver, this value can be reduced to reduce the time and cost of verifying whether the receiver is lost.

By default, the system resends the data segment that does not return a response five times. You can modify the data segment as needed:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named TCPMaxDataRetransmissions under the parameters subkey, the value ranges from 0 to 4294967295. The default value is 5. Set the value based on the actual situation.

10.Tcpmaxconnectretransmisstions

The value of tcpmaxconnectretransmisstions indicates the number of times the TCP connection is resold, and the non-confirmed connection request (SYN) is resold before the TCP exits. For each attempt, the Retransmission timeout is twice that of the successful retransmission. In Windows Server 2003, the default timeout value is 2 and the default timeout value is 3 seconds (in the Registry key tcpinitialrtt ). The timeout time for slow WAN connections can be increased accordingly. Different environments may have different optimization settings, which need to be tested and determined in the actual environment. Do not set the timeout value too large. Otherwise, no network connection timeout will occur. Specific operations:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters registry subkey, create or modify the REG_DWORD value named tcpmaxconnectretransmisstions under the parameters subkey, the value ranges from 0 to 255. The default value is 2. Set the value based on the actual situation. Create or modify the REG_DWORD value named tcpinitialrtt under the parameters subkey, and set the value according to the actual situation.

11.Tcpackfrequency

The value of tcpackfrequency indicates the frequency at which the system sends response messages. If the value is 2, the system sends a response after receiving two segments, or send a response when one segment is received, but no other segment is received within 200 milliseconds. If the value is 3, then the system will send a response after receiving three segments, or when receiving one or two segments but not receiving any other segments within 200 milliseconds, and so on. If you want to shorten the response time by eliminating the response latency, we recommend that you set this value to 1. In this case, the system will immediately send a response to each segment. If the connection is mainly used to transmit a large amount of data, and the latency of 200 milliseconds is not important, this value can be reduced to reduce the response overhead.

By default, the system sets this value to 2, that is, the system replies every other part. The valid range of this value is 0 to 255. 0 indicates that the default value is 2. You can modify the value as needed:

Browse to the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters \ Interfaces \ XX (XX is determined by the network adapter) registry subkey, create or modify the REG_DWORD value named tcpackfrequency under the XX subkey. The value ranges from 1 to 13 and the default value is 2, set this value based on the number of segments to be sent to return a response. We recommend that you set the Mbps network to 5 and the Mbps network to 13.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.