[英]Nginx taking way more time than uwsgi
We are running nginx and uwsgi behind Load Balancer (AWS ELB).我们在负载均衡器 (AWS ELB) 后面运行 nginx 和 uwsgi。 uwsgi is able to process request in lesses than 100 ms but nginx is adding some overhead and final request time is becoming way more than uwsgi time.
uwsgi 能够在不到 100 毫秒的时间内处理请求,但 nginx 增加了一些开销,最终请求时间变得比 uwsgi 时间长得多。 This is not happening for all of the requests but for only 2-3 % of requests.
并非所有请求都会发生这种情况,但只有 2-3% 的请求会发生这种情况。
Log Format日志格式
'$status [$time_local] "$request" $body_bytes_sent $request_length $request_time $upstream_response_time $upstream_connect_time $upstream_header_time $upstream_status $pipe';
200 [21/Sep/2022:11:46:46 +0000] "POST api_end_point HTTP/1.1" 7238 1546 24.848 0.036 0.000 0.036 200 .
200 [21/Sep/2022:11:46:57 +0000] "POST api_end_point HTTP/1.1" 1130 1558 2.178 0.044 0.000 0.040 200 .
200 [21/Sep/2022:11:46:56 +0000] "POST api_end_point HTTP/1.1" 1130 1565 10.212 0.028 0.000 0.024 200 .
Log 1 : upstream request time is 36 ms and upstream connect time is 0 but nginx request time is 24.848 seconds.日志 1 :上游请求时间为 36 毫秒,上游连接时间为 0,但 nginx 请求时间为 24.848 秒。
Log 2 : upstream request time is 44 ms and upstream connect time is 0 but nginx request time is 2.178 seconds.日志 2 :上游请求时间为 44 毫秒,上游连接时间为 0,但 nginx 请求时间为 2.178 秒。
Log 3 : upstream request time is 28 ms and upstream connect time is 0 but nginx request time is 10.212 seconds.日志 3 :上游请求时间为 28 毫秒,上游连接时间为 0,但 nginx 请求时间为 10.212 秒。
Nginx Config: Nginx 配置:
error_log /var/log/nginx/error.log info;
worker_processes auto;
worker_rlimit_nofile 30000;
events {
worker_connections 1000;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/json;
client_max_body_size 5m;
client_body_buffer_size 256k;
client_header_buffer_size 1k;
large_client_header_buffers 8 64k;
client_header_timeout 1m;
client_body_timeout 2m;
send_timeout 2m;
reset_timedout_connection on;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 200;
keepalive_requests 2000;
log_format mycombined '$status [$time_local] "$request" $body_bytes_sent $request_length $request_time $upstream_response_time $upstream_connect_time $upstream_header_time $upstream_status $pipe';
map $status $loggable {
~^[23] 0;
default 1;
}
include /etc/nginx/conf.d/*.conf;
}
server {
listen our_custom_port;
server_name localhost;
access_log /var/log/nginx/access.log mycombined;
location api_end_point {
include uwsgi_params;
uwsgi_read_timeout 5s;
uwsgi_pass unix:/opt/apis/server/uwsgi_socket.sock;
uwsgi_ignore_client_abort on;
}
location /_health {
include uwsgi_params;
uwsgi_read_timeout 5s;
uwsgi_pass unix:/opt/apis/server/uwsgi_socket.sock;
uwsgi_ignore_client_abort on;
}
}
I tried using gunicorn also instead of uwsgi.我也尝试使用 gunicorn 而不是 uwsgi。 Similar issue persists with nginx + gunicorn also.
nginx + gunicorn 也存在类似问题。
Any help would be highly appreciated.任何帮助将不胜感激。
Nginx logs the request time when client/user has received the response from the server (has successfully read the response from the server). Nginx 记录客户端/用户收到服务器响应(已成功读取服务器响应)的请求时间。
The root cause is probably found somewhere else than the server itself.根本原因可能在服务器本身以外的其他地方找到。 Check for AWS VPC flow logs or possible user connectivity issues.
检查 AWS VPC 流日志或可能的用户连接问题。 The.network outside of the EC2 might not work properly.
EC2 之外的网络可能无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.