The meaning of the backlog parameter in the TCP/IP protocol listen function and the PHP-FPM 502 bad Gateway

Source: Internet
Author: User
Tags ack

To understand the backlog argument, we must realize, a given listening socket, the kernel maintains the queues:
To understand the meaning of the backlog parameter, we must understand that for a listening socket,kernel maintainer two queues:

1.An Incomplete connection queue, which contains an entry for each SYN that have arrived from a client for which the server Is awaiting completion of the TCP Three-way handshake. These sockets is in the SYN_RCVD state.
1. A queue that does not complete the connection, which maintains a connection that has received the Client SYN section information and waits for the three-way handshake to complete, the state of the socket is SYN_RCVD

2.A completed connection queue, which contains an entry for each client with whom the TCP three-way handshake have complete D. These sockets is in the established state
2. A completed connection queue that contains the connections that have completed a three-way handshake, the status of the socket is established

The backlog argument to the Listen function have historically specified the maximum value for the sum of both queues.
The backlog parameter is historically defined as the sum of the size of the above two queues

Berkeley-derived implementations add a fudge factor to the backlog:it are multiplied by 1.5
The backlog value in the berkely implementation is the top two teams list and multiply by 1.5

When a SYN arrives from a client, TCP creates a new entry on the incomplete queue and then responds with the second segmen T of the Three-way handshake:the server ' s syn with an ACK of the client's SYN (section 2.6). This entry would remain on the incomplete queue until the third segment of the Three-way handshake arrives (the client ' s AC K of the server ' s SYN), or until the entry times out. (berkeley-derived implementations has a timeout of seconds for these incomplete entries.)
When the client's first SYN arrives, TCP adds a new record to the unfinished queue and then replies to the second section in the client's three-way handshake (SYN on the server and ACK for the client), which persists until the last sub-section of the three-way handshake arrives. or until timeout (Berkeley time to define this timeout as 75 seconds)

If the queues is full when a client SYN arrives, TCP ignores the arriving SYN (pp. 930–931 of TCPv2); It does not the send an RST. This was because the condition is considered temporary, and the client TCP would retransmit its SYN, hopefully finding On the ' queue ' in the ' future. If the server TCP immediately responded with a RST, the client ' s connect would return an error, forcing the application T O Handle this condition instead of the letting TCP ' s normal retransmission take over. Also, the client could not differentiate between an RST on response to a SYN meaning "there are no server at this port" ver SUS "There is a server at this port, but its queues be full."
If the queue is full when the client SYN arrives, TCP ignores the subsequent incoming SYN, but does not send the RST information to the client because the client is now allowed to retransmit the SYN section, and if an error message is returned, Then the client will not be able to tell whether the server port on the corresponding ports on the corresponding application or the service port on the corresponding ports on the queue is full of two cases

The somaxconn of the system can be modified in the following way

Vim/etc/sysctl.conf

Net.core.somaxconn = 2048

Sysctl-p

In PHP-FPM, there is an option for this

Listen.backlog =-1

This value, preferably not set to-1, 1 when the system is not able to set the number of settings, resulting in 502 appears

2015/02/11 12:37:22 [ERROR] 25725#0: *1015645 connect () to Unix:/tmp/php-cgi.sock failed (11:resource temporarily unavail able) while connecting to upstream, client:222.240.64.190,

The workaround is to set this value manually

Listen.backlog = 1024

The meaning of the backlog parameter in the TCP/IP protocol listen function and PHP-FPM's 502 bad Gateway

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.