所有请求都进入ELB喘振队列

一个问题:似乎对我们的应用程序的每一个请求都会在ELB浪涌队列中结束

喘振排队图的例子: 在这里输入图像说明

AWS上有一个经典的ELB,后面有多个EC2框。 ELB监听器设置在下一个方法

LB Protocol LB Port Instance Protocol Instance Port Cipher SSL Certificate TCP 80 TCP 80 N/AN/A 

在一个EC2实例中,我们有一个nginx服务器和下一个nginx.conf:

 user nginx; worker_processes 3; pid /var/run/nginx.pid; worker_rlimit_nofile 8192; worker_rlimit_sigpending 32768; events { worker_connections 2048; multi_accept on; use epoll; accept_mutex off; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; map_hash_bucket_size 128; server_tokens off; client_max_body_size 0; server_names_hash_bucket_size 256; include /etc/nginx/mime.types; default_type application/octet-stream; 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'; access_log /app/log/nginx/access.log main; error_log /app/log/nginx/error.log; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_comp_level 4; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; client_body_temp_path /app/tmp/nginx;:q include /etc/nginx/sites-enabled/*; upstream tomcat { server localhost:8080; } upstream httpd { server localhost:9000; } upstream play { server localhost:9000; } 

和vhost sites.conf

 log_format proxylog '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$proxy_protocol_addr" $request_time'; server { server_name www.my-site.com; rewrite ^(.*) http://my-site.com$1 permanent; } server { listen 80 proxy_protocol; listen 443 ssl proxy_protocol; ssl_certificate /etc/nginx/my-certificate.crt; ssl_certificate_key /etc/nginx/my-key.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "SECRET"; ssl_prefer_server_ciphers on; set_real_ip_from 10.0.0.0/8; root /app/websites/my-site.com/httpdocs; index index.html index.htm; real_ip_header proxy_protocol; server_name my-site.com; access_log /app/log/nginx/my-site.com.access.log proxylog buffer=16k flush=2s; error_log /app/log/nginx/my-site.com.error.log; charset utf-8; location /foo { proxy_pass http://play; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /bar { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET,POST,OPTIONS,DELETE,PUT" always; add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, User-Agent, Authorization, Referer, Timestamp' always; add_header Access-Control-Allow-Credentials true always; proxy_pass http://play; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET,POST,OPTIONS,DELETE,PUT" always; add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, User-Agent, Authorization, Referer, Timestamp' always; add_header Access-Control-Allow-Credentials true always; real_ip_header proxy_protocol; set_real_ip_from 10.0.0.0/8; proxy_read_timeout 90s; proxy_set_header X-Real-IP $proxy_protocol_addr; proxy_set_header X-Forwarded-For $proxy_protocol_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_pass http://play; proxy_set_header Host $http_host; } location ~ ^/(images|css|js|html) { root /app/websites/my-site.com/httpdocs; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } 

我限制可能的ELB和nginx问题的嫌疑人,而不是最明显的 – 实际的web服务器处理请求,因为在我的一个testing中,我完全删除了java应用程序,并用一个虚拟的node.js服务器取代了它回答“hello world”给每一个请求,我仍然得到所有这些请求logging在浪涌队列中。

我也尝试调整worker_processeskeepalive_timeout ,看看它是否影响任何东西,而不是。

令我困扰的是,这个1的浪涌队列不会影响服务的性能,因为看起来请求往往停留在几分之一秒内,但我不明白的是,为什么即使是单个请求也要经过浪涌队列。

你有ELB设置为TCP吗?

如果是这样,您的ELB将注册每个连接进入喘振队列。 我害怕没有得到解决。 您必须使用http或https才能使喘振队列正常工作。

从OP更新

我创build了一个微小的EC2实例,它有一个简单的TCP服务器,它只是对每个请求回复“马铃薯”。 我把它放在一个带有TCP监听器的经典ELB上,并向我的新鲜ELB提出了一个请求,并检查了喘振队列图。

在这里输入图像说明

查看经典负载平衡器的 AWS文档监听器

当为前端和后端连接使用TCP(第4层)时,负载均衡器将请求转发到后端实例,而不修改标头。 在您的负载均衡器收到请求后,它将尝试在侦听器configuration中指定的端口上打开到后端实例的TCP连接。

和这个:

对于HTTP / HTTPS负载均衡器后面的每个已注册且健康的实例,Elastic Load Balancing将打开并维护一个或多个TCP连接。 这些连接确保始终有一个已build立的连接准备好接收HTTP / HTTPS请求。

从我的理解中可以看出,每次我们打电话给TCPconfiguration的ELB时,它都将我们的请求放在一边,能够打开一个到我们EC2的连接,然后才把请求传递给机器。