Some TCP ParametersIntroduction
Tcp_max_syn_backlog
Maximum port backlog kernel limit. This parameter limits server applicationsProgramThe maximum backlog value that can be set (corresponding to the length of the syn_backlog and backlog queues of the port ). The motivation is to limit/prevent applications from consuming the kernel memory by configuring a large backlog value on servers with limited memory. If the application sets a backlog value greater than this value, the operating system automatically limits this value.
Tcp_abort_on_overflow
After TCP establishes a three-way handshake, the connection is placed in the established status and delivered to the backlog queue of the application, and the backlog queue is full. If the connection is full, the connection is usually restored to the syn_ack state, this creates the illusion of accidental loss of the last ACK packet of a three-way handshake-this way, you can resend ack after the client waits for timeout-to attempt to enter the established status again-as a repair/Retry Mechanism. If tcp_abort_on_overflow is enabled, when the backlog queue is full, an RST packet is sent directly to the client to terminate the connection. In this case, the client will receive the 104 Connection reset by peer error.
Warning enabling this option may result in a 104: Connection reset by peer or white screen error during peak periods (depending on the browser ). Before enabling this option, try to optimize and improve the performance of the server application so that it can take over and process connections faster.
Tcp_syncookies
When the server receives the initial SYN request during the three-way handshake of TCP connection, it checks whether the syn_backlog queue of the application is full. If it is full, the SYN packet is usually discarded. If not, check whether the application's backlog queue is full. If the application is full and the system determines that the application will not consume the connection quickly based on the history, the SYN packet will be discarded. If tcp_syncookies are enabled, the SYN packet is not discarded when the syn_backlog queue is full. Instead, a three-way handshake is performed using syncookie technology.
Warning when syncookie is used for handshake, because the technology misappropriates the tcp_options field space, it will forcibly disable the TCP advanced traffic control technology and degrade to the original TCP mode. This mode will cause the Peer to wait for MSL time to find the packet loss event and retry, And the time_wait State will remain 2msl time when the connection is closed. This technology should only be used to protect syn_flood attacks. If the server load in a normal server environment is heavy and the syn_backlog and backlog queues are full, the load capacity of the server application should be optimized to increase the value of the application backlog. However, fortunately, this parameter is an automatic value and will only be triggered when the syn_backlog queue is full (this behavior is disabled when the queue is available for recovery ).
Note 1:
The server application sets the port backlog value. The kernel will theoretically allow this port to receive a maximum of 2 backlog concurrent connection "requests at the same time (excluding connections that have been taken over by applications) -- stored in the syn_backlog and backlog queues respectively -- the length of each queue is the backlog value.The syn_backlog queue stores connections in the syn_ack state, while the backlog stores connections in the established State that have not been taken over by the application.
NOTE 2:
The syn_backlog queue is actually a hash table, and the size of the hash table is the power of 2. Therefore, the length of the actual syn_backlog queue must be slightly greater than the backlog value set by the Application -- Take the power value corresponding to 2.
NOTE 3:
When the backlog value is small and the concurrent connection request is too high during the peak period, the latency of the three-way handshake network established by TCP will become the bottleneck-when the concurrent connection is too high, the syn_backlog queue will be full and cause the 'can't connect 'error. At this point, increasing the throughput of the server application does not work, because the connection has not yet been established, the server application cannot take over and process these connections-but needs to increase the backlog value (length of the syn_backlog Queue) to alleviate this problem.
Note 4:
Enabling syncookie can also solve the problem of 'can't connect 'during ultra-high concurrency, but it will cause the time_wait status fallback to keep 2msl time, during peak hours, the client may be unable to connect to the server because the connection is unavailable (TCP connection multiplexing is based on the <src_ip, src_port, dst_ip, dst_port> values must be different, for accessing the same target server, the value of <src_ip, dst_ip, dst_port> is the same, so the number of available connections is limited to only the number allowed by src_port, the same src_port connection in the time_wait status cannot be reused. The Linux system is even stricter. Only the <src_ip, src_port, dst_ip> Triple...) is used ...). Therefore, syncookie is not recommended.
Original
Http://zhumeng8337797.blog.163.com/blog/static/100768914201262010163658/