估计带宽使用情况

了解如何估算 EAS 更新的带宽使用情况。


了解更新带宽使用情况

🌐 Understanding update bandwidth usage

EAS 更新使应用能够通过空中传输更新其非原生部分(如 JavaScript、样式和图片)。本指南解释了带宽的使用情况以及如何优化带宽消耗。

🌐 EAS Update enables an app to update its own non-native pieces (such as JavaScript, styling, and images) over-the-air. This guide explains how bandwidth is consumed and how consumption can be optimized.

带宽计算细目

🌐 Bandwidth calculation breakdown

每个订阅计划都包括每月账单周期内的预定义带宽分配,以及每月活跃用户(MAU)分配(了解有关 MAU 计算方式的更多信息)。超出标准分配的 MAU 将按按使用量计费的费率收取费用,每增加一个额外的 MAU,你的标准带宽分配将增加 40 MiB。此带宽决定了你的用户在被收取额外带宽使用费用之前可以下载的更新数量。

🌐 Each subscription plan includes a predefined bandwidth allocation per monthly billing period in addition to its monthly active user (MAU) allocation (learn more about how MAU are calculated). MAU's beyond the standard allocation are billed at usage-based pricing rates, and each of those additional MAU add an extra 40 MiB to your standard bandwidth allocation. This bandwidth determines the number of updates your users can download before being charged for additional bandwidth usage.

以下是如何估计每次更新的带宽使用量:

🌐 Here's how to estimate bandwidth usage per update:

  • 更新大小: 带宽消耗的关键因素是设备上尚未存在的更新资源的大小。如果一次更新仅修改了应用的 JavaScript 部分,用户只会下载新的 JavaScript。举个例子,假设导出过程中生成的未压缩 JavaScript 部分为 10 MB。压缩将进一步减少其大小。

  • 压缩比: 压缩程度取决于文件类型。JavaScript 和 Hermes 字节码(在 React Native 应用中常用)可以被压缩,而图片和图标不会自动压缩。在上面的示例中,一个 Hermes 字节码包实现了估计 2.6× 的压缩比,将实际下载大小减小为:

    10 MB / 2.6 ≈ 3.85 MB update bandwidth size

在给定带宽分配的情况下,我们估算在下一个月结算周期内可以下载多少更新,超出部分将产生额外的带宽费用。例如,如果你在生产计划中有 60,000 个 MAU,它包含 50,000 个 MAU 和 每月 1 TiB(1,024 GiB)带宽。通过按使用量计费购买的额外 10,000 个 MAU 会获得每个 MAU 额外 40 MiB 的带宽。可以下载的总更新数量为:

🌐 Given a bandwidth allocation, we estimate how many updates can be downloaded in a monthly billing period before additional bandwidth charges apply. For example, if you have 60,000 MAUs on a production plan, it includes 50,0000 MAU and 1 TiB (1,024 GiB) of bandwidth per month. An additional 10,000 MAUs purchased through usage-based pricing receives an additional 40 MiB of bandwidth per MAU. The total number of updates that can be downloaded is:

(1,024 GiB × 1,024 MiB/GiB) + (10,000 MAU × 40 MiB/MAU) = 1,448,576 MiB per month 1,448,576 MiB / 3.85 MiB ≈ 376,254 updates

测量你的实际更新大小

🌐 Measuring your actual update size

要确定 Hermes 包的实际压缩大小,请运行以下命令:

🌐 To determine the actual compressed size of your Hermes bundle, run the following commands:

Terminal
brotli -5 -k bundle.hbc
gzip -9 -k bundle.hbc
ls -lh bundle.hbc.br bundle.hbc.gz

这将生成你的 Hermes 包的 Brotli 和 Gzip 压缩 版本(bundle.hbc.brbundle.hbc.gz)并显示它们的大小。你可以使用它来根据应用的实际更新大小优化带宽计算。

🌐 This will generate Brotli- and Gzip-compressed versions of your Hermes bundle (bundle.hbc.br and bundle.hbc.gz) and display their sizes. You can use this to refine bandwidth calculations based on your app's real-world update sizes.

影响带宽消耗的因素

🌐 Factors that affect bandwidth consumption

实际带宽使用情况因以下因素而异:

🌐 Actual bandwidth usage varies due to:

  • **用户行为:**理论计算假设每个用户都会下载每一个更新。然而,许多用户只有在重新打开应用时才会获取更新,经常会跳过中间的更新。因此,实际使用的带宽通常远低于理论最大值。
  • 缺失的资源: 如果更新包含设备上尚未存在的资源,如字体和图片(无论是从版本构建还是之前下载的更新中),也需要下载这些资源。

优化带宽使用

🌐 Optimizing bandwidth usage

  1. 首先监控使用情况: 管理带宽最简单的方法是跟踪你的使用指标,并识别任何异常的峰值或低效情况。
  2. 优化资源大小: 使用本指南来减小你的资源大小。
  3. 在需要时排除资源: 使用 资源选择 来减少每次更新中包含的资源数量。这是一种高级优化,应先尝试其他方法。