nginx’s model knows that it is master-worker
黄舟2017-05-31 10:39:23
This should be multiple processes reusing one socket at the same time
linux, it is possible for multiple
sockets to listen to the same port at the same time. This behavior is also supported in
Nginx 1.9.1or above
linux
3.9or above kernel supports
SO_REUSEPORT option, which allows multiple
socket
bind/listen on the same port. In this way, multiple processes can each apply for
socket to listen to the same port. When data comes, the kernel does load balancing and wakes up one of the listening processes for processing. The usage is similar to
setsockopt(listener, SOL_SOCKET, SO_REUSEPORT, &option, sizeof (option))
SO_REUSEPORT option can effectively solve the
epollthundering problem. For specific tests, you can see the example written below: ThunderingHerdTest.cpp
SO_REUSEPORT option, please refer to The SO_REUSEPORT socket option. Regarding the questioner’s doubts, this sentence in the article can be used as an answer:
To prevent unwanted processes from hijacking a port that has already been bound by a server using SO_REUSEPORT, all of the servers that later bind to that port must have an effective user ID that matches the effective user ID used to perform the first bind on the socket.That is, not any process can be bound to the same port, only if the
effective user IDis the same
Nginx and
SO_REUSEPORT, please see We increase productivity by means of SO_REUSEPORT in NGINX 1.9.1
漂亮男人2017-05-31 10:39:23
A single application has multiple processes listening to the same port, and the socket is shared