目前,我正在基于tomcat上运行的grails 3的系统上使用JMeter运行负载测试。每秒发送20k请求后,nginx错误日志中显示“连接上游客户端时没有上游上游”。我们的应用程序是基于多租户的,因此我需要执行高负载。这是我的nginx配置。
worker_processes 16;
worker_rlimit_nofile 262144;
error_log /var/log/nginx/error.log;
events {
worker_connections 24576;
use epoll;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 600;
keepalive_requests 100000;
access_log off;
server_names_hash_max_size 4096;
underscores_in_headers on;
client_max_body_size 8192m;
log_format vhost '$remote_addr - $remote_user [$time_local] $status "$request" $body_bytes_sent "$http_referer" "$http_user_agent" "http_x_forwarded_for"';
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
gzip on;
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss image application/javascript;
gzip_min_length 1000;
gzip_static on;
gzip_vary on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_proxied any;
gzip_disable "msie6";
proxy_intercept_errors on;
recursive_error_pages on;
ssl_prefer_server_ciphers On;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA;
include /etc/nginx/conf.d/*.conf;
}
如何配置高并发负载?
最佳答案
对我来说,问题出在我的proxy_pass条目上。我有
location / {
...
proxy_pass http://localhost:5001;
}
这导致上游请求使用IP4本地主机IP或IP6本地主机IP,但是每隔一段时间,它将使用没有端口号的本地主机DNS,从而导致上游错误,如下面的日志所示。
[27/Sep/2018:16:23:37 +0100] <request IP> - - - <requested URI> to: [::1]:5001: GET /api/hc response_status 200
[27/Sep/2018:16:24:37 +0100] <request IP> - - - <requested URI> to: 127.0.0.1:5001: GET /api/hc response_status 200
[27/Sep/2018:16:25:38 +0100] <request IP> - - - <requested URI> to: localhost: GET /api/hc response_status 502
[27/Sep/2018:16:26:37 +0100] <request IP> - - - <requested URI> to: 127.0.0.1:5001: GET /api/hc response_status 200
[27/Sep/2018:16:27:37 +0100] <request IP> - - - <requested URI> to: [::1]:5001: GET /api/hc response_status 200
如您所见,我的“ localhost:”状态为502:
将proxy_pass更改为127.0.0.1:5001意味着所有请求现在都通过端口使用IP4。
此StackOverflow响应对发现问题有很大帮助,因为它详细更改了日志格式以使您可以查看问题。
关于nginx - 如何解决Nginx-连接到上游客户端时没有实时上游?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49767001/