简体   繁体   English

Nginx 比 uwsgi 花费更多的时间

[英]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.

相关问题 不止一个站点 ERROR Django uwsgi 配置问题 - more than one site ERROR Django uwsgi config problem 无法到达使用 uWSGI 和 Nginx 服务的 Flask 应用程序 - Can not reach Flask app served with uWSGI and Nginx getDocuments() 函数多次获取相同的数据 - getDocuments() function getting the same data more than one time 有没有办法将多个云 function 附加到 Firestore 中的特定集合? - Is there a way to attach more than one cloud function to a specific collection in Firestore? 我如何在快速应用程序中加速 firebase 功能,这些功能加载时间太长,大多数时间超过 8 秒 - How can i speed up firebase functions in an express app which are taking too long to load taking more than 8 seconds most times 我的 Firestore 中有超过 50,000 个文档,排序和查找的时间超过 30 秒,限制为 50 个。如何加速? - I have more than 50,000 documents in my firestore and it is taking more than 30secs to sort and find in limits of 50. how to speedup? Google Cloud 中的 EventArc 一次多次请求 Cloud Run Service 触发器 - EventArc in Google Cloud Request the Cloud Run Service more than Once in One Time Trigger 在 AWS Fargate 上部署一个容器(当已经有一个容器在运行时需要比平时更多的时间来启动) - Deploying a container on AWS Fargate (takes more than usual time to start when there is already a container running) lambda 存储过程中的最大时间限制问题将需要超过 15 分钟才能完全执行 - Max time limit issue in lambda stored procedure will take more than 15min to execute completly 如何在bigquery中获取过期的表数据,如果过期时间超过两天? - How to get expired table data in bigquery, If the expired time is more than two days?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM