/ nginx / docs / how-to-improve-concurrency


How to speed up nginx connection handling?

Adjust the count of Workers - maybe you can have more workers that can handle requests

Variables

Calculation

1 worker per CPU. Better to use ‘auto’ - NGINX will do the same in your place. No worries it won’t do it on every request but just once when changes are compiled.

Open request count

The main bottleneck of handling request is the open file limit. If the limti is reached then 500 error will just be thrown. You can try it by setting these limits to a very small count and then just make more requests than the count.

Variables

Calculation

File system’s Hard limit

File system’s Soft limit

Required action

Set the soft limit same as the hard

ulimit -n 65536.

Set NGINX variables to the hard limit’s value.

 worker_rlimit_nofile 65536;
 worker_connections 65536;

Cache meta data like paths

Keep track of every requested files for 2 minutes max while expiring resources after 1 minute.

Variables

Variables

Use HTTP2 A.K.A. H2

HTTP by default has a really small concurrent request limit. So H2 fixes this. This example explains it: