I needed to load-test an HTTP client, so I used nginx. I ran into some limits:
2018/10/17 23:44:09 [alert] 1860#1860: 768 worker_connections are not enough
To get around this, edit /etc/nginx/nginx.conf
and edit the events
section:
events {
worker_connections 5000;
# multi_accept on;
}
Then restart nginx:
sudo service nginx restart
Once I'd done that, I started running into "too many open files" errors:
2018/10/23 13:33:50 [crit] 19813#19813: accept4() failed (24: Too many open files)
2018/10/23 13:33:51 [crit] 19813#19813: *1127 open() "/var/www/html/index.nginx-debian.html" failed (24: Too many open files), client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost:8443"
To resolve this, we need to bump the open file limit for the worker processes.
First, though, let's see what the default is:
sudo cat /proc/$(ps -ef | awk -v pid=$(cat /run/nginx.pid) '$3 == pid {print $2;exit}')/limits | \
grep 'Max open files'
Yeah, that looks complicated, but it won't get confused if you're running another instance of nginx in a (docker) container.
It turns out that, with no further modifications, the limit is 1024.
Let's try to increase that. Edit /etc/nginx/nginx.conf
so that the start of the file looks like the following:
user www-data;
worker_processes auto;
worker_rlimit_nofile 5120;
pid /run/nginx.pid;
Then restart nginx:
sudo service nginx restart
Confirm the new limit with the monstrosity from earlier.
Linux Mint 18.3 (i.e. Ubuntu 16.04)