了解 Chrome 网络日志 "Stalled" 状态

Understanding Chrome network log "Stalled" state

我在 chrome 中有以下网络登录:

里面有一件事我没看懂:实心灰条和透明灰条有什么区别

Google 在 DevTools 文档的 Evaluating network performance 部分给出了这些字段的细分。

摘自Resource network timing

Stalled/Blocking

Time the request spent waiting before it could be sent. This time is inclusive of any time spent in proxy negotiation. Additionally, this time will include when the browser is waiting for an already established connection to become available for re-use, obeying Chrome's maximum six TCP connection per origin rule.

(如果您忘记了,Chrome 在悬停工具提示和“计时”面板下有一个“说明”link。)

基本上,您会看到这种情况的主要原因是因为 Chrome 一次只能为每个服务器下载 6 个文件,其他请求将被暂停,直到连接槽可用。

这不一定是需要修复的问题,但避免停滞状态的一种方法是将文件分发到多个域名 and/or 服务器,如果适用,请记住 CORS根据您的需要,但是 HTTP2 可能是未来更好的选择。资源捆绑(如 JS 和 CSS 串联)也有助于减少停滞连接的数量。

DevTools: [network] explain empty bars preceeding request

Investigated further and have identified that there's no significant difference between our Stalled and Queueing ranges. Both are calculated from the delta's of other timestamps, rather than provided from netstack or renderer.


Currently, if we're waiting for a socket to become available:

  • we'll call it stalled if some proxy negotiation happened
  • we'll call it queuing if no proxy/ssl work was required.

https://developers.google.com/web/tools/chrome-devtools/network-performance/understanding-resource-timing

这来自 Chome-devtools 的官方网站,它有帮助。 我在这里引用:

  • Queuing If a request is queued it indicated that:
    • The request was postponed by the rendering engine because it's considered lower priority than critical resources (such as scripts/styles). This often happens with images.
    • The request was put on hold to wait for an unavailable TCP socket that's about to free up.
    • The request was put on hold because the browser only allows six TCP connections per origin on HTTP 1. Time spent making disk cache entries (typically very quick.)
  • Stalled/Blocking Time the request spent waiting before it could be sent. It can be waiting for any of the reasons described for Queueing. Additionally, this time is inclusive of any time spent in proxy negotiation.

我的情况是页面在打开时发送了多个具有不同参数的请求。所以大多数都在 "stalled"。以下立即发送的请求获得 "stalled"。避免不必要的请求会更好(偷懒......)。

由于许多人来到这里调试他们缓慢的网站,我想通知您我的案例,google 解释中的 none 帮助解决了这个问题。我的巨大停滞时间(有时 1 分钟)是由 Windows 上的 Apache 运行 造成的,工作线程太少无法处理连接,因此它们正在排队。

如果您的 apache 日志有以下注释,这可能适用于您:

Server ran out of threads to serve requests. Consider raising the ThreadsPerChild setting

此问题已在 Apache httpd.conf 中得到解决。取消注释: 包括conf/extra/httpd-mpm.conf

并编辑 httpd-mpm.conf

<IfModule mpm_winnt_module>
   ThreadLimit              2000
   ThreadsPerChild          2000
   MaxConnectionsPerChild   0
</IfModule>

请注意,您可能不需要 2000 个线程,也可能需要更多。 2000 年对我来说还可以。