nginx反向代理吞吐量周期性下降,请问是怎么回事?
Periodic drop in throughput of nginx reverse proxy, what can it be?
我正在对一个 t2.micro 盒子进行负载测试,它在 docker 容器中装有 nginx 和 postgrest 运行。 Nginx 充当 postgrest 前面的代理。
如果我直接去上游(postgrest),我会得到一个很好的图表(峰值约为 900/rps)
如果我通过 nginx,我会得到这种图表
CPU没有刷满(只有50%左右)
这是使用的 nginx 配置。评论的所有内容都已尝试,没有任何影响。我还玩过 worker_connections 的值和相关的东西。
什么可以触发这种周期性下降?
worker_processes2;
#worker_rlimit_nofile2048;
事件{
# multi_accept 开;
worker_connections1024;
使用 epoll;
}
HTTP {
解析器 127.0.0.11 ipv6=关闭;
包括 mime.types;
#tcp_nodelay关闭;
#tcp_nopush 开;
上游postgrest {
服务器postgrest:3000;
保活 64;
}
服务器 {
听80;
server_name 本地主机;
字符集 utf-8;
位置/休息/ {
default_type application/json;
#proxy_buffering关闭;
proxy_pass http://postgrest/; # 反向代理到你的 PostgREST
}
}
}
罪魁祸首是(默认)内核 tcp 设置。
当通过 nginx 代理时,系统用完了所有本地端口,然后一切都停止了(丢弃),直到旧的 tcp 连接可以完全关闭(它们在 time_wait 中持续了 60 秒)
调整这些设置解决了问题
#tcp settings
net.core.somaxconn
net.ipv4.tcp_fin_timeout
net.ipv4.tcp_tw_reuse
net.ipv4.ip_local_port_range
#nginx configs
proxy_set_header Connection "";
proxy_http_version 1.1;
下面的文章更详细地介绍了到底发生了什么,要调整的参数。
https://engineering.gosquared.com/optimising-nginx-node-js-and-networking-for-heavy-workloads
我正在对一个 t2.micro 盒子进行负载测试,它在 docker 容器中装有 nginx 和 postgrest 运行。 Nginx 充当 postgrest 前面的代理。 如果我直接去上游(postgrest),我会得到一个很好的图表(峰值约为 900/rps) 如果我通过 nginx,我会得到这种图表
CPU没有刷满(只有50%左右)
这是使用的 nginx 配置。评论的所有内容都已尝试,没有任何影响。我还玩过 worker_connections 的值和相关的东西。 什么可以触发这种周期性下降?
worker_processes2; #worker_rlimit_nofile2048; 事件{ # multi_accept 开; worker_connections1024; 使用 epoll; } HTTP { 解析器 127.0.0.11 ipv6=关闭; 包括 mime.types; #tcp_nodelay关闭; #tcp_nopush 开; 上游postgrest { 服务器postgrest:3000; 保活 64; } 服务器 { 听80; server_name 本地主机; 字符集 utf-8; 位置/休息/ { default_type application/json; #proxy_buffering关闭; proxy_pass http://postgrest/; # 反向代理到你的 PostgREST } } }
罪魁祸首是(默认)内核 tcp 设置。 当通过 nginx 代理时,系统用完了所有本地端口,然后一切都停止了(丢弃),直到旧的 tcp 连接可以完全关闭(它们在 time_wait 中持续了 60 秒) 调整这些设置解决了问题
#tcp settings
net.core.somaxconn
net.ipv4.tcp_fin_timeout
net.ipv4.tcp_tw_reuse
net.ipv4.ip_local_port_range
#nginx configs
proxy_set_header Connection "";
proxy_http_version 1.1;
下面的文章更详细地介绍了到底发生了什么,要调整的参数。
https://engineering.gosquared.com/optimising-nginx-node-js-and-networking-for-heavy-workloads