ベンチマークを取っている時にどうも違うような挙動をしたので確認してみた.
worker_processes 8, worker_connections 256 のとき
いままでの理解
nginx の同時接続数は
worker_connections * worker_processes
なので
256 * 8 = 2048
になるんだと思ってた.
確認
この設定に対して同時接続数 1024 でリクエストしても当然問題なく処理されるものと思いきや,
[root@client ~]# ab -c 1024 -n 10240 'http://10.100.47.58/10k.dat' This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.100.47.58 (be patient) apr_socket_recv: Connection reset by peer (104) Total of 544 requests completed
エラーになってしまった.
さらにエラーログに
2014/11/12 17:41:55 [alert] 13733#0: 256 worker_connections are not enough
が出力されておりworker_connections
を使い切ったことがはっきりとわかる.
worker_processes 1, worker_connections 2048 のとき
[root@hosweb001 ~]# ab -c 1024 -n 10240 'http://10.100.47.58/10k.dat' This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.100.47.58 (be patient) Completed 1024 requests Completed 2048 requests Completed 3072 requests Completed 4096 requests Completed 5120 requests Completed 6144 requests Completed 7168 requests Completed 8192 requests Completed 9216 requests Completed 10240 requests Finished 10240 requests Server Software: nginx/1.7.7 Server Hostname: 10.100.47.58 Server Port: 80 Document Path: /10k.dat Document Length: 10240 bytes Concurrency Level: 1024 Time taken for tests: 1.003 seconds Complete requests: 10240 Failed requests: 0 Write errors: 0 Total transferred: 107595930 bytes HTML transferred: 105031680 bytes Requests per second: 10206.19 [#/sec] (mean) Time per request: 100.331 [ms] (mean) Time per request: 0.098 [ms] (mean, across all concurrent requests) Transfer rate: 104727.19 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 4 5.3 1 21 Processing: 3 20 42.7 13 620 Waiting: 2 17 42.3 12 617 Total: 7 24 44.2 13 630 Percentage of the requests served within a certain time (ms) 50% 13 66% 14 75% 16 80% 31 90% 37 95% 61 98% 85 99% 216 100% 630 (longest request)
この設定だと問題なく処理されるので,さっきのエラーがカーネルパラメータや ulimit 等によるリソース不足によるものではないことがわかる.
まとめ
今までの理解ならどっちも問題なく処理できるか,どっちも失敗するかのはず.
「worker_processes 8, worker_connections 256」がダメで「worker_processes 1, worker_connections 2048」が OK ということは
worker_connections
は「worker 当たり」ではなく「nginx 全体」の同時接続数になっていると考えられる.