Google AMP 缓存和 HTTP/2 – 通过 HTTP/2 在移动设备上传送内容?

Google AMP Cache and HTTP/2 – Content delivery via HTTP/2 on mobile devices?

Google AMP 缓存默认通过 HTTP/2 提供最大 12 MB 的文件。尽管 AMP 不受限于在移动设备上使用,但它们是 AMP 背后的主要动机。

我刚读完 a paper about the performance of HTTP/2 on cellular networks。 虽然他们发现 HTTP/2 对于小文件 (2 MB) 比 HTTP/1.1 更快,但他们还发现,对于 8 MB 或更大的文件,包丢失对 HTTP/2 比 HTTP/1.1,导致页面加载时间更长(即在这种情况下 HTTP/1.1 比 HTTP/2 快)。在他们的研究中,32% 的移动连接经历了数据包丢失。

因此我一直在想 HTTP/2 是否真的适合 (Google) AMP 缓存。

基于此 documentation, the Google AMP Cache performs optimizations and modifications and it serves over a secure channel (HTTPS) and uses the latest web protocols (SPDY, HTTP/2). Also from this blog,Google AMP 缓存是一个基于代理的内容分发网络,用于分发所有有效的 AMP 文档。它获取 AMP HTML 页面,缓存它们,并自动提高页面性能。 当使用 Google AMP 缓存时,文档、所有 JS 文件和所有图像都从使用 HTTP 2.0 的同一来源加载以获得最大效率。

HTTP/2主要目的是性能,第一,为什么不HTTP/1.1

HTTP/1.1 引入官方 IETF 标准;不幸的是,实现的简单性也以应用程序性能为代价:

  • HTTP/1.x客户端需要使用多连接来实现并发,降低延迟;
  • HTTP/1.x 不压缩请求和响应头,造成不必要的网络流量;
  • HTTP/1.x不允许有效的资源优先级排序,导致底层TCP连接使用不佳;等等。

这些限制并不是致命的,但随着网络应用程序在我们日常生活中的范围、复杂性和重要性不断增长,它们给网络开发人员和用户带来了越来越大的负担,这是HTTP/2 旨在解决的确切差距:

来源: https://developers.google.com/web/fundamentals/performance/http2/

现在,引用我在开始实施 AMP 时阅读的关于 HTTP/2 的数据包丢失的研究:

Packet Loss, High-RTT Links, and HTTP/2 Performance Wait, I hear you say, we listed the benefits of using one TCP connection per origin but aren’t there some potential downsides? Yes, there are.

We have eliminated head-of-line blocking from HTTP, but there is still head-of-line blocking at the TCP level (see Head-of-Line Blocking).

Effects of bandwidth-delay product may limit connection throughput if TCP window scaling is disabled.

When packet loss occurs, the TCP congestion window size is reduced (see Congestion Avoidance), which reduces the maximum throughput of the entire connection.

Each of the items in this list may adversely affect both the throughput and latency performance of an HTTP/2 connection. However, despite these limitations, the move to multiple connections would result in its own performance tradeoffs:

Less effective header compression due to distinct compression contexts

Less effective request prioritization due to distinct TCP streams

Less effective utilization of each TCP stream and higher likelihood of congestion due to more competing flows

Increased resource overhead due to more TCP flows

The above pros and cons are not an exhaustive list, and it is always possible to construct specific scenarios where either one or more connections may prove to be beneficial. However, the experimental evidence of deploying HTTP/2 in the wild showed that a single connection is the preferred deployment strategy:

In tests so far, the negative effects of head-of-line blocking (especially in the presence of packet loss) is outweighed by the benefits of compression and prioritization.

Hypertext Transfer Protocol version 2, Draft 2

As with all performance optimization processes, the moment you remove one performance bottleneck, you unlock the next one. In the case of HTTP/2, TCP may be it. Which is why, once again, a well-tuned TCP stack on the server is such a critical optimization criteria for HTTP/2.

There is ongoing research to address these concerns and to improve TCP performance in general: TCP Fast Open, Proportional Rate Reduction, increased initial congestion window, and more. Having said that, it is important to acknowledge that HTTP/2, like its predecessors, does not mandate the use of TCP. Other transports, such as UDP, are not outside the realm of possibility as we look into the future.

来源: https://hpbn.co/http2/

HTTP/2 大多数 站点的一致性显示更快。是否有某些情况更糟 - 绝对! - 但你应该阻止为 少数 改善 大多数网站 吗?我认为没有。

但是,即便如此,我认为您还需要考虑其他因素:

AMP 页面旨在提高性能,我想说的是,尤其是对于它们而言,8mb 页面应该是例外,而不是常态。因此,虽然在某些情况下对较大的页面使用 HTTP/1.1 可能更有效 - 对于大多数较小的页面使用 HTTP/2. 更有效。 =10=]

是否应该回退到 HTTP/1.1 以获得更大的页面?也许吧,但这更复杂,因为协议是在您知道页面之前首先协商的,降级将需要重定向或类似操作,并且肯定会减慢页面速度。

AMP 和 AMP 缓存是否应该限制为 8Mb 而不是 12Mb,因为它们使用 HTTP/2,本文建议这可能是一个更好的限制?也许 - 但话又说回来,他们不会在 HTTP/2 上工作,他们会优雅地回退,但加载速度可能不如在 HTTP/1.1.

上那么快

此外,大多数 AMP 页面本身应该很小,并逐步加载非必要资产(例如图像或视频)。因此,即使存在数据包丢失,大文件(可能是图像或视频)也可能不会阻止 AMP 页面的关键呈现。

是否所有移动页面都通过移动网络加载?有没有人通过 WiFi 网络使用手机,包裹丢失应该更少(我知道我有!)。该论文不清楚 32% 的数字是蜂窝连接(即不通过 WiFi)还是所有移动连接(即蜂窝和 WiFi)

Google 也在试验 HTTP/2 下的 QUIC 而不是 TCP - 这解决了单个 HTTP/2 连接速度慢的主要原因(即单个 TCP 数据包丢失将保留所有 HTTP/2 流,而不仅仅是数据包所属的流)。当然,这仅适用于 Chrome,因此其他浏览器尚无法从中受益,但是 Chrome 拥有庞大的用户群。

因此,基于所有这些,我认为 HTTP/2 绝对是正确的选择 - 尤其是对于 AMP 页面。正如我在开始时所说的那样,它并不完美,在某些情况下有些页面可能会变慢,但绝大多数页面应该会更快,因此应该使用它。