nginxのworker processesとcpuコア数とworker_connectionsの確認方法

Nov 30, 2017 ( Feb 11, 2022 更新 )

nginxでworker_processesをautoにすると、CPU数と同数のworker_processesが生成される。

http://nginx.org/en/docs/ngx_core_module.html#worker_processes

$ head /etc/nginx/nginx.conf
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    multi_accept  on;
    use  epoll;

cpuinfoで確認できるのは8プロセッサ。

psで見ると、nginx worker processは8プロセス起動している。

$ egrep "^processor\s:\s[0-9]+$" /proc/cpuinfo
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
$ ps -T aux | grep [n]ginx
nginx    27320 27320  0.0  0.0  48664  4744 ?        S    11月09   4:26 nginx: worker process
nginx    27321 27321  0.0  0.0  48664  4856 ?        S    11月09   4:22 nginx: worker process
nginx    27322 27322  0.0  0.0  48664  4732 ?        S    11月09   4:26 nginx: worker process
nginx    27323 27323  0.0  0.0  48664  4856 ?        S    11月09   4:33 nginx: worker process
nginx    27324 27324  0.0  0.0  48664  4712 ?        S    11月09   4:23 nginx: worker process
nginx    27325 27325  0.0  0.0  48664  4728 ?        S    11月09   4:18 nginx: worker process
nginx    27326 27326  0.0  0.0  48664  4732 ?        S    11月09   4:16 nginx: worker process
nginx    27327 27327  0.0  0.0  48664  4728 ?        S    11月09   4:19 nginx: worker process
root     39979 39979  0.0  0.0  47208  5120 ?        Ss   11月06   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

confに書いてあるworker_connectionsとulimitが合ってるか確認する。

$ cat /proc/27320/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             64144                64144                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       64144                64144                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
Return to top