I found 'accept_mutex' is 'on' as default in Nginx as follows:
http://wiki.nginx.org/EventsModule
Then does accepting connection require mutex? Why?
As of nginx mainline version 1.11.3 (released 2016-07-26), accept_mutex
now defaults to off
. This is partly because the new EPOLLEXCLUSIVE
flag provides the benefits of accept_mutex
without the extra overhead.
Imagine some processes listen on one port and wait in epoll. Without accept mutex all processes will wake up, but only one will be able to accept connection. Others process waked up unproductive. It is well known http://en.wikipedia.org/wiki/Thundering_herd_problem
But it is not the end of story.
Often or always unsuccessful accept will result in context switch: http://en.wikipedia.org/wiki/Lock_convoy
My tests show 5-10% performance lost without accept mutex.
Update: "accept mutex" is not just mutext locked around accept. It is the name of technology used to serialize listening on server port between workers. Only one worker is listening for given port in one moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With