如何禁用 fastcgi 的任何重试?
我已经设定:
fastcgi_next_upstream off;
fastcgi_next_upstream_tries 1;
在 nginx 配置中。
以下是一些 nginx 日志:
php_1 | 172.20.0.2 - 28/May/2018:10:07:56 +0000 "GET /index.php" 200
web_1 | 172.20.0.1 - - [28/May/2018:10:07:58 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
php_1 | [28-May-2018 10:07:58.106908] DEBUG: pid 1, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 5 active children, 0 spare children, 5 running children. Spawning rate 1
php_1 | 172.20.0.2 - 28/May/2018:10:07:57 +0000 "GET /index.php" 200
web_1 | 172.20.0.1 - - [28/May/2018:10:07:59 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
php_1 | [28-May-2018 10:07:59.108072] DEBUG: pid 1, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 5 active children, 0 spare children, 5 running children. Spawning rate 1
php_1 | 172.20.0.2 - 28/May/2018:10:07:57 +0000 "GET /index.php" 200
php_1 | 172.20.0.2 - 28/May/2018:10:07:57 +0000 "GET /index.php" 200
php_1 | 172.20.0.2 - 28/May/2018:10:07:57 +0000 "GET /index.php" 200
web_1 | 172.20.0.1 - - [28/May/2018:10:07:59 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
web_1 | 172.20.0.1 - - [28/May/2018:10:07:59 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
web_1 | 172.20.0.1 - - [28/May/2018:10:07:59 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
php_1 | 172.20.0.2 - 28/May/2018:10:07:58 +0000 "GET /index.php" 200
web_1 | 172.20.0.1 - - [28/May/2018:10:08:00 +0000] "GET / HTTP/1.1" 200 18 "-" "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.0.4"
php_1 | [28-May-2018 10:08:00.109179] DEBUG: pid 1, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 5 active children, 0 spare children, 5 running children. Spawning rate 1
以下是来自 siege http 负载测试工具的一些结果:
Transactions: 114 hits
Availability: 88.37 %
Elapsed time: 79.02 secs
Data transferred: 0.00 MB
Response time: 51.59 secs
Transaction rate: 1.44 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 74.43
Successful transactions: 114
Failed transactions: 15
Longest transaction: 61.11
Shortest transaction: 28.07
后端是一个max_children
设置为 5 的 php-fpm 服务 - 因此它最多可以同时处理 5 个请求。但是,如果请求失败,nginx 似乎会“重试”该请求(因为它达到了高于 5 的并发量 - 如围攻结果中所示)。
具有上述行为的完整 docker 项目可以在这里找到:https://github.com/chrissound/phpfpmmaxchildrentest/
答案1
我必须将listen.backlog
其设置为 0,php-fpm
因为它似乎有一个请求队列。虽然这似乎不能完全发挥作用(尽管确实有一些效果):一旦达到其容量上限,如何强制 fastcgi / php-fpm 拒绝连接?