nginx - nginx upstream_response_time 比 web app 大
问题描述
QPS 5000/s时,最小的nginx响应时间是88ms,最大的nginx响应时间是1844ms,但是web app响应时间几乎在1ms,不知道为什么
这是 nginx 配置
worker_processes 32;
worker_rlimit_nofile 65535;
# define event
events {
use epoll;
worker_connections 65535;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for "|$request_time|$upstream_response_time';
upstream natee{
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
server 127.0.0.1:8004;
server 127.0.0.1:8005;
server 127.0.0.1:8006;
server 127.0.0.1:8007;
server 127.0.0.1:8008;
server 127.0.0.1:8009;
server 127.0.0.1:8010;
server 127.0.0.1:8011;
server 127.0.0.1:8012;
server 127.0.0.1:8013;
server 127.0.0.1:8014;
server 127.0.0.1:8015;
server 127.0.0.1:8016;
server 127.0.0.1:8017;
server 127.0.0.1:8018;
server 127.0.0.1:8019;
server 127.0.0.1:8020;
}
server {
proxy_http_version 1.1;
listen 9000;
proxy_ignore_client_abort on;
proxy_read_timeout 300s;
server_name localhost;
access_log /root/nginx/access.log main;
error_log /root/nginx/error.log debug;
location / {
proxy_pass http://natee;
proxy_http_version 1.1;
proxy_connect_timeout 60000;
proxy_read_timeout 60000;
proxy_send_timeout 60000;
}
}
}
我使用日志格式记录 request_time 和 upstream_reponse_time,
这是网络响应时间
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.32ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.32ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.31ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.34ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.34ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.36ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.38ms
[I 211008 11:30:39 web:2243] 200 POST /test (127.0.0.1) 0.34ms
这是 nginx access.log
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
172.19.3.130 - - [08/Oct/2021:11:30:40 +0800] "POST /test HTTP/1.1" 200 2 "-" "Go-http-client/1.1" "- "|0.652|0.592
这是 nginx error.log
2021/10/08 11:30:38 [debug] 3142#3142: accept on 0.0.0.0:9000, ready: 1
2021/10/08 11:30:38 [debug] 3143#3143: accept on 0.0.0.0:9000, ready: 1
2021/10/08 11:30:38 [debug] 3145#3145: accept on 0.0.0.0:9000, ready: 1
2021/10/08 11:30:38 [debug] 3142#3142: posix_memalign: 000055F731876F30:512 @16
2021/10/08 11:30:38 [debug] 3143#3143: posix_memalign: 000055F730E02410:512 @16
2021/10/08 11:30:38 [debug] 3142#3142: *148769 accept: 172.19.3.130:52354 fd:9
2021/10/08 11:30:38 [debug] 3143#3143: *148770 accept: 172.19.3.130:52356 fd:9
2021/10/08 11:30:38 [debug] 3145#3145: posix_memalign: 000055F730BF0250:512 @16
2021/10/08 11:30:38 [debug] 3142#3142: *148769 event timer add: 9: 60000:152402669
2021/10/08 11:30:38 [debug] 3145#3145: *148771 accept: 172.19.3.130:52358 fd:9
2021/10/08 11:30:38 [debug] 3142#3142: *148769 reusable connection: 1
2021/10/08 11:30:38 [debug] 3145#3145: *148771 event timer add: 9: 60000:152402669
2021/10/08 11:30:38 [debug] 3142#3142: *148769 epoll add event: fd:9 op:1 ev:80002001
2021/10/08 11:30:38 [debug] 3145#3145: *148771 reusable connection: 1
2021/10/08 11:30:38 [debug] 3145#3145: *148771 epoll add event: fd:9 op:1 ev:80002001
2021/10/08 11:30:38 [debug] 3142#3142: posix_memalign: 000055F730E2EB10:512 @16
2021/10/08 11:30:38 [debug] 3145#3145: accept() not ready (11: Resource temporarily unavailable)
2021/10/08 11:30:38 [debug] 3142#3142: *148772 accept: 172.19.3.130:52360 fd:11
2021/10/08 11:30:38 [debug] 3143#3143: *148770 event timer add: 9: 60000:152402669
2021/10/08 11:30:38 [debug] 3142#3142: *148772 event timer add: 11: 60000:152402669
2021/10/08 11:30:38 [debug] 3143#3143: *148770 reusable connection: 1
2021/10/08 11:30:38 [debug] 3142#3142: *148772 reusable connection: 1
2021/10/08 11:30:38 [debug] 3143#3143: *148770 epoll add event: fd:9 op:1 ev:80002001
2021/10/08 11:30:38 [debug] 3142#3142: *148772 epoll add event: fd:11 op:1 ev:80002001
2021/10/08 11:30:38 [debug] 3142#3142: accept() not ready (11: Resource temporarily unavailable)
2021/10/08 11:30:38 [debug] 3143#3143: accept() not ready (11: Resource temporarily unavailable)
2021/10/08 11:30:38 [debug] 3142#3142: accept on 0.0.0.0:9000, ready: 1
2021/10/08 11:30:38 [debug] 3142#3142: posix_memalign: 000055F73187CB40:512 @16
2021/10/08 11:30:38 [debug] 3142#3142: *148773 accept: 172.19.3.130:52362 fd:13
2021/10/08 11:30:38 [debug] 3142#3142: *148773 event timer add: 13: 60000:152402669
2021/10/08 11:30:38 [debug] 3142#3142: *148773 reusable connection: 1
2021/10/08 11:30:38 [debug] 3143#3143: accept on 0.0.0.0:9000, ready: 1
2021/10/08 11:30:38 [debug] 3142#3142: *148773 epoll add event: fd:13 op:1 ev:80002001
2021/10/08 11:30:38 [debug] 3143#3143: posix_memalign: 000055F730CC8B20:512 @16
2021/10/08 11:30:38 [debug] 3143#3143: *148774 accept: 172.19.3.130:52364 fd:11
2021/10/08 11:30:38 [debug] 3142#3142: accept() not ready (11: Resource temporarily unavailable)
2021/10/08 11:30:38 [debug] 3143#3143: *148774 event timer add: 11: 60000:152402669
解决方案
推荐阅读
- r - 通过 includeMarkdown 包含覆盖内联代码的外部 markdown 文件
- django - 在 Django ListView 中使用具有 isnull=False 和 order_by 的外键解决慢查询
- c - 从具有自己的 main() 的外部 C 文件调用函数
- amazon-web-services - AWS CloudHSM PKCS#11 与 PKCS11Interop 为 Wrap 操作 CKR_ARGUMENTS_BAD 提供错误
- jquery - 如何检查 iframe 中的选择下拉菜单是否更改?
- xamarin.forms - 如何检查发生触摸的视图标签
- javascript - django 使用经典 javascript 将 AJAx POST 请求发送到带有 csrf_token 的服务器,如何?
- pandas - Pandas:将重复的 df 行压缩为 1 行
- java - 以错误编码 UTF-8 加载的文件,在 windows-1252 android studio 中重新加载
- flutter - 颤动按下设备的物理后退按钮时如何执行功能?