1

我有一种情况,当我第一次打开页面时,一切都运行得很快,如果我在一切正常后不久重新加载页面,并且如果我第三次重新加载页面,浏览器会暂停请求约 25 秒。有时多,有时少。有时是对 root 的请求,有时是对一些静态文件的请求。如果我等待一段时间并再次刷新,一切都会再次快速打开,直到网页的第二次或第三次刷新。

这可能是什么?如果我使用 Nginx 但使用 Node 提供静态文件,我没有那种问题吗?

daemon off;
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

worker_rlimit_nofile 10000;

events {

    use epoll;

    accept_mutex on;

    multi_accept    on;

    worker_connections 1024;
}

error_log   logs/nginx/error.log;

http {

  charset   utf-8;

  include mime.types;

  default_type  application/octet-stream;

  access_log     off;

   log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';

    access_log logs/nginx/access.log l2met;

    sendfile        on;

    tcp_nopush      on;

    tcp_nodelay       on;

    types_hash_max_size       2048;

    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid   30s;
    open_file_cache_min_uses    2;
    open_file_cache_errors  on;

    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;

    limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;

    client_body_buffer_size 16k;

    client_header_buffer_size   1k;

    client_max_body_size    8m;

    large_client_header_buffers 2 1k;


    # # - Configure Timeouts

    reset_timedout_connection on;

    client_body_timeout 12;

    client_header_timeout   12;

    keepalive_timeout   15;

    keepalive_requests 100;

    send_timeout    10;

    server_tokens   off;

  # # - Dynamic gzip compression
  gzip                      on;
    gzip_http_version         1.1;
    gzip_disable              "msie6";
    gzip_vary                 on;
    gzip_min_length           20;
    gzip_buffers              4 16k;
    gzip_comp_level           4;
    gzip_proxied              any;


    # Turn on gzip for all content types that should benefit from it.

    gzip_types  application/ecmascript;
    gzip_types  application/javascript;
    gzip_types  application/json;
    gzip_types  application/pdf;
    gzip_types  application/postscript;
    gzip_types  application/x-javascript;
    gzip_types  image/svg+xml;
    gzip_types  text/css;
    gzip_types  text/csv;
    gzip_types  text/javascript;
    gzip_types  text/plain;
    gzip_types  text/xml;
    gzip_types  text/json;


  # proxying requests to other servers

    upstream nodebeats {
      server unix:/tmp/nginx.socket fail_timeout=0;
    }

    server {
        listen       <%= ENV['PORT'] %>;
        server_name  _;
        root        "/app/";

    limit_conn conn_limit_per_ip 5;
    limit_req zone=req_limit_per_ip burst=10 nodelay;

    location ~* \.(js|css|jpg|png|ico|json|xml|svg)$ {
      root               "/app/src/dist/";
      add_header         Pragma public;
      add_header         Cache-Control public;
      expires            1y;
      gzip_static        on;
      gzip               off;
      log_not_found      off;
      access_log         off;
    }

    location / {
      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   Host $http_host;
      proxy_set_header   Connection "";
      proxy_redirect     off;
      proxy_http_version 1.1;
      proxy_pass         http://nodebeats;
      add_header         Cache-Control no-cache;
      proxy_read_timeout 60s;
    }
}

}

4

1 回答 1

0

好的,在检查后我发现这是因为某些 Chrome(和其他浏览器)限制每个服务器同时 6 个 tcp 连接。当我查看时,chrome://net-internals/#sockets我看到了这一点。问题是 ssl_socket_pool 和 6 个活动连接。它们需要很长时间才能从活动状态变为空闲状态(然后页面继续加载)。如何解决?

在此处输入图像描述

我尝试打开其他一些页面,它们的静态内容和 http 请求比我的(有 8 个)多得多,并且它们总是快速重新加载。我看了看同一个地方,发现Active里什么都没有。页面重新加载后,所有连接都立即空闲。

于 2017-07-09T03:09:03.273 回答