Chrome Network Resource Timing详解

Chrome Network Resource Timing

Resource Scheduling

Queueing

排队时间。(请求文件顺序的的排序)

在 http1 下浏览器对每次TCP连接的数量有所限制。
比如 Chrome浏览器是限制同一域名下支持同时6个TCP连接。
如果请求的资源超过6个并资源优先级比较低,便会进入队列进行排队等待其他连接释放
(Queueing 就是这个等待时间: 从添加到待处理队列,到实际开始处理的时间间隔标示)。

优化方法:

  • 合理使用多域名,增加并发连接数量。
  • http2支持多路复用,即没有TCP连接数量限制。

Connection Start

Stalled

请求允许被发出到请求真正发出的时间间隔。

也就是浏览器收到一个指令,指令说你可以准备发出请求了,于是浏览器就准备代理协商,如果有已经建好的链接,还会等待可建立的TCP连接被重新复用的时间(不包括DNS查询、TCP建立连接等时间)。

等这些做完了,请求也就可以发出了。

Stalled 就是收到这个指令到请求可以发出的时间间隔。

已建立的TCP连接确认是否可被继续使用需要一个检测过程,这个检测过程的时间会包含在stalled中。
如果这个检测返回错误,客户端会连续发送可复用tcp连接继续进行检测,如果持续检测超过最大次数仍然没有连接检测成功、查找到可复用的tcp连接。客户端便认为没有可复用的连接,检测结束。记录时间。(在这之后会发送一个新的TCP请求连接,已不属于stalled时间间隔)

如果出现stalled阶段过长,可能是丢包所致,说明网络不太好或服务端有问题。

参考:http://fex.baidu.com/blog/2015/01/chrome-stalled-problem-resolving-process

Proxy Negotiation

与代理服务器连接协商所用的时间。(需要使用代理服务器进行访问的url才会有这个时间)

Initial Connection / Connecting

建立连接所用时间。

包括 TCP握手和多次尝试握手、处理SSL的时间。

TCP建立连接,可能由于网络原因或服务器原因导致丢包,一次握手不成功,于是会出现多次尝试握手情况。

如果在 stalled阶段成功检测到可复用TCP连接,这个时间同样也会为 0,忽略不计。

SSL

完成 SSL 握手所用时间。

Request / Response

Request Sent / Sending

请求发出时间。

http请求报文第一个字节发出开始到最后一个字节发出结束的时间。

通常非常小。
如果请求报文比较大,这个时间可能会长一点,不过影响不大。

Waiting (TTFB)

等待服务端初始响应的时间。

也就是从请求发出开始,服务端接收到请求,返回数据,客户端接收到第一个字节的这一段时间。

这个时间段代表服务器处理和返回数据网络延时时间。

如果时间过长,说明可能客户端与服务端之间网络较差或服务器响应较慢。

服务器优化的目的就是要让这个时间段尽可能短。

Content Download / Downloading

接收响应数据时间。

也就是客户端接收到服务端返回的第一个字节开始,到接收到最后一个字节结束的这一段时间。

一般来说时间也比较小,如果返回体比较大,这个时间也可能会长一点。

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

官方解释

The primary phases of the request lifecycle are:

  • Redirect
    Immediately begins startTime.
    If a redirect is happening, redirectStart begins as well.
    If a redirect is occurring at the end of this phase then redirectEnd will be taken.

  • App Cache
    If it’s application cache fulfilling the request, a fetchStart time will be taken.

  • DNS
    domainLookupStart time is taken at the beginning of the DNS request.
    domainLookupEnd time is taken at the end of the DNS request.

  • TCP
    connectStart is taken when initially connecting to the server.
    If TLS or SSL are in use then secureConnectionStart will start when the handshake begins for securing the connection.
    connectEnd is taken when the connection to the server is complete.

  • Request
    requestStart is taken once the request for a resource has been sent to the server.

  • Response
    responseStart is the time when the server initially responds to the request.
    responseEnd is the time when the request ends and the data is retrieved.

timing 图:

  • Queuing
    A request being queued indicates 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.

  • Proxy Negotiation
    Time spent negotiating with a proxy server connection.

  • DNS Lookup
    Time spent performing the DNS lookup. Every new domain on a page requires a full roundtrip to do the DNS lookup.
    Initial Connection / Connecting
    Time it took to establish a connection, including TCP handshakes/retries and negotiating a SSL.

  • SSL
    Time spent completing a SSL handshake.
    Request Sent / Sending
    Time spent issuing the network request. Typically a fraction of a millisecond.

  • Waiting (TTFB)
    Time spent waiting for the initial response, also known as the Time To First Byte. This time captures the latency of a round trip to the server in addition to the time spent waiting for the server to deliver the response.
    Content Download / Downloading
    Time spent receiving the response data.

参考资料