I found 'multi_accept' is 'off' as default in Nginx as follows:
2 Answers
Probably because with on, all the worker processes are active and try to handle all of the incoming request simultaneously. When disabled, Nginx decides which child process gets to deal with the request one by one. As Nginx is very efficient at this, this probably serves most people well. Some consider it a risk to enable it, as it may flood the worker connections with requests. Your TCP settings at OS level will likely play a part in this too.
-
3I had the exact situation. I had tried to find out what worker_rlimit_nofile, worker_connections and worker_processes auto commands do. Nginx is a reverse proxy for an application which accepts websockets. Nginx config allows 50 connections for every worker. When I have two workers (therefore 100 connections should be established) and multi_accept is on I get an error that the websockets can't be created (the worker who already has 50 connections tries it...). When multi_accept is off everything works perfectly.– HamburmlJun 22, 2017 at 12:41
multi_accept off
: a worker accepts just a single connection, handles it and then returns to the kernel for the next event to process.
multi_accept on
: a worker would do accept
in a loop until it gets EAGAIN
finally. This might be beneficial if there're quite a lot of connections by cutting off events handling which requires an additional kernel involvement. But if there're not that many incoming connections then EAGAIN
would be hit pretty often, say with 1:1
ratio. This approach could also inflict a connection handling misbalance specially when they arrive irregularly and SO_REUSEPORT
isn't in use.
All in all — it's kinda "hacky", probably not worth tinkering with it at all, but the knob is still there — just in case it could be helpful.
Heavily based on explanation by Valentin Bartenev, nginx-ru mailing list.