nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.4k stars 330 forks source link

More suitable max open file descriptor limits by default ? #49

Open centminmod opened 7 years ago

centminmod commented 7 years ago

With benchmarking and general performance for Nginx Unit and it's processes, maybe a more suitable and higher default max open file descriptor limits is needed ?

On CentOS 7.4 64bit using systemd unitd.service file, the default limits are fairly low with soft/hard limits at 1024/4096.

root      4018  0.0  0.0  16428   516 ?        Ss   00:35   0:00 unit: main [/opt/unit/sbin/unitd]
nginx     4039  0.0  0.0  26672   264 ?        S    00:35   0:00  \_ unit: controller
nginx     4241  0.0  0.0 1165196   40 ?        S    00:36   0:00  \_ unit: "php71domaincom" application
cat /proc/4039/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             7272                 7272                 processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0              
Max realtime priority     0                    0              
Max realtime timeout      unlimited            unlimited            us
cat /proc/4241/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             7272                 7272                 processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0              
Max realtime priority     0                    0              
Max realtime timeout      unlimited            unlimited            us

Setting higher defaults

mkdir -p /etc/systemd/system/unitd.service.d
echo -en "[Service]\nLimitNOFILE=262144\nLimitNPROC=16384\n" > /etc/systemd/system/unitd.service.d/limit.conf
systemctl daemon-reload
systemctl restart unitd
root      4559  0.0  0.0  16032   800 ?        Ss   00:54   0:00 unit: main [/opt/unit/sbin/unitd]
nginx     4578  0.0  0.0  26276   720 ?        S    00:54   0:00  \_ unit: controller
nginx     4579  0.0  0.0 341832   912 ?        Sl   00:54   0:00  \_ unit: router
nginx     4642  5.2  2.7 1175440 52152 ?       S    00:57   0:00  \_ unit: "php71domaincom" application
cat /proc/4578/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             16384                16384                processes
Max open files            262144               262144               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0                
Max realtime priority     0                    0                
Max realtime timeout      unlimited            unlimited            us  
cat /proc/4642/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             16384                16384                processes
Max open files            262144               262144               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0                
Max realtime priority     0                    0                
Max realtime timeout      unlimited            unlimited            us
VBart commented 7 years ago

It's not expected to show good performance at the current stage of early beta, as the code contains some quirks. So, there's not much sense to benchmark and tune limits for that.

But you're right, for production use and performance testing the limits should be raised.

centminmod commented 7 years ago

True, though folks will still attempt to benchmark and compare Nginx Unit in early beta to their existing solutions and make early conclusions. And you wouldn't want those conclusions to be limited by something like max open file limits. Though some system admins would easily pinpoint the limitation and make adjustments themselves.