Nginx出现http 504错误

beidao-ai 发布于 2016/05/30 21:12
阅读 1K+
收藏 0

今天做服务器压测,当单机QPS在 1500 左右时出现 http 504 (gateway timeout)。

tomcat配置:(Tomcat7)


<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               enableLookups="false" acceptCount="200"
               debug="0" disableUploadTimeout="true" URIEncoding="UTF-8"
               maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
               useBodyEncodingForURI="true" compression="on" compressionMinSize="2048"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               redirectPort="8443" />


nginx配置:(Nginx 1.6)


server_names_hash_bucket_size 128;
  client_header_buffer_size 4k;
  large_client_header_buffers 4 32k;
  client_max_body_size 80m;

  sendfile on;
  tcp_nopush     on;

  client_body_timeout  5;
  client_header_timeout 5;
  keepalive_timeout  5;
  send_timeout       5;


  open_file_cache max=65535 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 1;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  client_body_buffer_size  512k;
  proxy_connect_timeout    5;
  proxy_read_timeout       60;
  proxy_send_timeout       5;
  proxy_buffer_size        16k;
  proxy_buffers            4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;



nginx 错误日志:



"$request" "$request_time" "$upstream_response_time" "$status" "$body_bytes_sent"
POST    HTTP/1.1  5.003   5.001   504     184 
 POST    HTTP/1.1  5.003   5.001   504     184 
 POST    HTTP/1.1  5.003   5.001   504     184 
 POST    HTTP/1.1  5.003   5.001   504     184

从监控可以看出tomcat线程连接数才不过500就开始出现http 504,如果说是请求进入tomcat请求队列导致超时的话,那应该是tomcat线程达到1000的时候才出现,请问大家知道这是什么原因导致 nginx 返回 504呢?



加载中
0
Feng_Yu
Feng_Yu
看看504的时候是不是tomcat负载太高
Feng_Yu
Feng_Yu
回复 @ahern88_ : tomcat负载过高,已经DOS了,自然504.跟你开多少个线程没关系。你应该优化你的程序,以承载高并发带来的压力
beidao-ai
beidao-ai
tomcat负载应该是比较高了,但是从监控可以看到tomcat线程数才不到500的,还没有达到极限,配置的最大线程数是1000,等待队列个数是200
返回顶部
顶部