About speeding things up. A couple of useful points.
As is well known, browsers limit the number of simultaneous connections per domain while loading a site. Because of this, site elements are loaded sequentially. Every image/js/css file is a separate connection. If there are many such elements on a site's pages, you can speed up loading by moving static assets to subdomains. For example: s1.domain.com, s2.domain.com, and so on. So if the browser has, say, a limit of 5 connections per domain, now you get 5 connections for each subdomain. If you spread everything out correctly, load speed can theoretically increase almost fivefold.
The downside: the number of simultaneous connections to the server also grows. With the same site traffic, the number of connections grows by about 5 times as well (if you have 5 subdomains). If Nginx is the frontend, it has a limit on the number of connections in its config. And since there are now 5 times more connections, it also has to do more work at the same time than before. So with this acceleration we are also pushing Nginx closer to its simultaneous connection limit, and as a result the site may fail to open for the user or some files may simply not be served during loading.
The Nginx logs will show an error like:
"...socket() failed (24: Too many open files) while connecting to upstream..."
To see the current limit from the console:
ulimit -n
To see it nicely formatted like this:
nginx: worker process
Limit Soft Limit Hard Limit Units
Max open files 1024 1048576 files
Currently open files: 945
nginx: master process /usr/sbin/nginx
Limit Soft Limit Hard Limit Units
Max open files 1024 1048576 files
you can run this in the console:
for pid in `pidof nginx`; do echo "$(< /proc/$pid/cmdline)"; egrep 'files|Limit' /proc/$pid/limits; echo "Currently open files: $(ls -1 /proc/$pid/fd | wc -l)"; echo; done
To change the limit:
-
add these lines to /etc/security/limits.conf:
* soft nofile 16384
* hard nofile 16384 -
run as root:
ulimit -n 16384 - restart Nginx, just in case.
They also write that you can simply add this to the Nginx config:
worker_rlimit_nofile 16384
and restart it.