Rules of Thumb for HTTP/2 Push (translate 9%)
Aug 4, 2016Rules of Thumb for HTTP/2 Push
Tom Bergan, Simon Pelchat, Michael Buettner {tombergan, spelchat, buettner}@chromium.org
HTTP/2 has a new feature called server push that promises to improve page load times. The idea: rather than waiting for the client to send a request, the server preemptively pushes a resource that it predicts the client will request soon afterwards. For example, if the server sends the client an HTML document, the server can reasonably predict that the client will also request subresources linked from that HTML document, such as JS and CSS files.
HTTP/2 有一個新功能叫做 server push,他承諾增進讀取時間。 這個想法取代了等待使用者送出 request, 伺服器搶先送出我們預測到使用者之後想要的資源。 舉例來說,假設伺服器送出了一個HTML document,伺服器可以合理的預測使用者也會請求連接到這個 HTML document 的子資源,像是JS and CSS。
More broadly, we can build a fetch dependency graph for a page. This graph has an edge from A to B if resource A reveals the need to fetch resource B. For example, given that doc.html imports a.js and a.js import b.js via document.write, there is an edge from doc.html -> a.js and another edge from a.js -> b.js. Each time a client requests a.js, the server can proactively push b.js along with any or all of the other descendants of a.js in the fetch dependency graph.
更廣泛地說,我們可以幫這個頁面建立一個 fetch dependency graph。 假設資源 A 表明他需要 fetch 資源B,這個 graph 就有一個 edge 從 A 到 B 。 舉例來說,考慮到 doc.html 引入了 a.js 並且 a.js 透過 document.write 引入了 b.js, 我們就有了一個 edge 從 doc.html -> a.js 並且有另一個 edge 從 b.js 沿著任何或是所有其他 a.js 的後裔在 fetch dependency graph。
Unfortunately, server push does not always improve page load performance. It is not always obvious why this is so. Further, indiscriminate use of server push can actually make page load times worse. This document compiles lessons we learned while experimenting with server push. Many of these lessons will be obvious and common-sense, at least in retrospect; others may not be so obvious.
很不幸的,server push 不是總是增進頁面讀取效能。為什麼他並不總是這樣。進一步來說, 濫用 server push 可以讓頁面讀取時間變得很糟。本文件編寫的是當我們實驗 server push 時我們學習到的教訓。
To summarize, we recommend the following:
總結來說,我們建議如下列:
- Push just enough resources to fill idle network time, and no more. Server push eliminates idle network time between the server sending one response to the client and waiting for the next request. During this idle time, the server can fill the network with as many bytes as are allowed by the current TCP congestion window (cwnd). Pushing more than cwnd bytes has no additional benefit and can actually hurt performance, for reasons described below. A corollary is that TCP slow start makes server push less effective on cold connections than on warm connections.
推送剛好足夠的資源去填滿閒置的網路就好。 Server push 消除閒置網路時間在 server 送出一個 response 到用戶端並且等待下一個 request 之間。 在這個閒置時間中,伺服器可以填滿這個網路伴隨盡可能多的位元組到被允許的當前的 TCP congestion window (cwnd)。 推送多餘 cwnd bytes 沒有額外的好處還可能傷害效能,根據下面描述的原因。 一個推論是 TCP slow start 讓 server push 在 cold connections 比 warm connections 較沒效率。
- Push resources in evaluation-dependence order. The browser evaluates each subresource in a specific order. Pushing resources in the wrong order delays evaluation, which can delay discovery of hidden resources that are requested dynamically, which can make page load time worse. For this reason, it may be better to avoid pushing resources when their evaluation order is not precisely known, especially when those resources cumulatively exceed the current cwnd (recall rule #1).
推送資源在評估依賴(evaluation-dependence)的順序。 瀏覽器評估每一個子資源透過特定的順序。 推送資源在不對的順序會延遲評估,會延遲發現隱藏那些動態請求的資源, 會讓頁面載入時間變得更長。 根據這個原因,也許最好避免當評估順序還不是精確的被瞭解時推送資源, 特別是當這些資源累積超過 cwnd(回想 rule #1)
- Consider using special strategies to track the client-side cache. Push wastes bandwidth when the client has already cached the resource being pushed. Further, pushing more than cwnd bytes makes page load time worse if the extra bytes pushed are already cached (again, recall rule#1). Unfortunately, there is no perfect, well-tested method to avoid pushing cached resources. We mention a few recent proposals.
考慮使用特別的策略去追蹤用戶端的快取。 推送浪費頻寬當用戶端已經快取這項正在推送的資源。 更進一步來說,推送多於一個 cwnd bytes 讓頁面載入速度更慢, 假如多餘的位元組已經被快取了(再次回想 rule #1)。 不幸的是,沒有完美,良好測試的方法去避免推送被快取的資源。 我們會提到一些最近的提案。
- Use the right cookies when pushing resources that vary by cookie. Unlike the above issues, this is a correctness problem, not a performance problem. This is particularly important when a pushed resource depends on path-scoped cookies that may not have been sent with the mainframe request that initiated the push.
使用正確的 cookies 當推送資源是根據 cookie 的改變。 不像上面的問題,這是正確性的問題,並非效能的問題。 這是格外重要當推送的資源取決於 path-scoped cookies 可能沒有送出過 with 大型機請求 that 初始過的推送(看不懂自己在翻什麼)
- Use server push to fill the initial cwnd and consider using preload links to reveal the remaining critical or hidden resources. In cases where a resource should not be pushed due to the above rules, a preload link may make more sense. Preload links cannot eliminate idle network time as well as server push. However, preload links are cache- and cookie-aware, and further, they can be applied to cross-domain or third-party resources, while a server can only push resources for which it is authoritative.
使用伺服器推送
Table of contents:
Intended Audience and Scope Experimental Methodology Rule #1: Push Enough to Fill Idle Network Time, and No More A Simple Example Slow Start Means Slow Push How Resource Evaluation Speed Affects Idle Time Generalizing to Multiple RTTs Implications for Developers Rule #2: Push Resources in the Right Order Push and HTTP/2 Priorities Bad Interactions Between HTTP/2 Priorities and Bufferbloat Don’t Let Pushed Responses Delay the Main Response Implications for Developers Rule #3: Don’t Push Resources the Client has Already Cached Rule #4: Use the Right Cookies What Happens if the Server Uses the Wrong Request Headers? Rule #5: Consider Preload Instead of Push Case Studies on Actual Pages Straw Man Comparison
Intended Audience and Scope The intended audience is HTTP/2 server implementers, who want to support server push in their servers, and web developers, who think their pages may be benefit from server push. We assume the reader is already familiar with basic web concepts a high-level, particularly HTTP/2 and HTML, and also basic networking concepts like BDP, congestion control, and head-of-line blocking. Ilya Grigorik’s High Performance Browser Networking gives a great overview of these topics.
Our examples focus on using server push to improve page load performance in web browsers. This is not the only case where server push is useful. Other cases include: responses to user actions on already-loaded web pages, or responses to RPC requests where the RPC transport layer uses HTTP/2. Our rules of thumb should generalize to these other cases as well, although rules #3-#5 apply only when the client is a web browser.
When we discuss response ordering, particularly in rule #2, we assume responses should be ordered as atomic units. This matches HTTP/2’s notion of stream dependence, where each response corresponds with a single HTTP/2 stream. Advanced servers may want to carefully interleave pushed responses with the main response to micro-optimize resource delivery. For example, a server may “inline” a JS file by pushing it just after sending the corresponding
… 10 KB of junk …