This should be multiple processes reusing one socket at the same time
However, in modern
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
linux3.9or above kernel supports SO_REUSEPORT option, which allows multiple socketbind/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))
Using the
SO_REUSEPORT option can effectively solve the epollthundering problem. For specific tests, you can see the example written below: ThunderingHerdTest.cpp
For discussions about the
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
For discussions about
Nginx and SO_REUSEPORT, please see We increase productivity by means of SO_REUSEPORT in NGINX 1.9.1
This should be multiple processes reusing one socket at the same time
However, in modernlinux
, it is possible for multiple
socketsto listen to the same port at the same time. This behavior is also supported in
Nginx 1.9.1or above
linux
3.9
bind/listen
Using theor above kernel supports
SO_REUSEPORToption, which allows multiple
socketon the same port. In this way, multiple processes can each apply for
socketto 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
For discussions about theoption can effectively solve the
epollthundering problem. For specific tests, you can see the example written below: ThunderingHerdTest.cpp
SO_REUSEPORT
That is, not any process can be bound to the same port, only if theoption, please refer to The SO_REUSEPORT socket option. Regarding the questioner’s doubts, this sentence in the article can be used as an answer:
effective user ID
For discussions aboutis the same
Nginx
and
SO_REUSEPORT, please see We increase productivity by means of SO_REUSEPORT in NGINX 1.9.1
The one with the smallest pid should be the master.
A single application has multiple processes listening to the same port, and the socket is shared