估计带宽使用情况

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


了解更新带宽使用情况

¥Understanding update bandwidth usage

EAS Update 使应用能够通过无线方式更新其自己的非原生部分(例如 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。压缩将进一步减小其大小。

    ¥Update size: The key factor in bandwidth consumption is the size of update assets that are not already on the device. If an update only modifies the JavaScript portion of your app, users will only download the new JavaScript. To begin an example, let's say the uncompressed JavaScript portion generated during export is 10 MB. Compression will further reduce its size.

  • 压缩率:压缩级别取决于文件类型。JavaScript 和 Hermes 字节码(常用于 React Native 应用中)可以压缩,而图片和图标不会自动压缩。在上面的例子中,Hermes 字节码包实现了估计的 2.6 倍压缩率,将实际下载大小减少到:

    ¥Compression ratio: The level of compression depends on the file type. JavaScript and Hermes bytecode (commonly used in React Native apps) can be compressed, while images and icons are not automatically compressed. In the example above, a Hermes bytecode bundle achieves an estimated 2.6× compression ratio, reducing the actual download size to:

  10 MB / 2.6 ≈ 3.85 MB update bandwidth size

给定带宽分配,我们估计在每月结算期内可以下载多少更新,然后才会收取额外的带宽费用。例如,如果你的生产计划中有 60,000 个 MAU,则它包括每月 50,0000 个 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 包 (bundle.hbc.br 和 bundle.hbc.gz) 的 Brotli 和 Gzip 压缩版本并显示其大小。你可以使用它根据应用的实际更新大小来优化带宽计算。

¥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:

  • 用户行为:理论计算假设每个用户都会下载每个更新。但是,许多用户只有在重新打开应用时才会获得更新,通常会跳过中间更新。因此,实际带宽使用量通常远低于理论最大值。

    ¥User behavior: Theoretical calculations assume every user downloads every update. However, many users only get updates when they reopen the app, often skipping intermediate updates. As a result, actual bandwidth usage is usually much lower than the theoretical maximum.

  • 缺少资源:如果更新包括字体和图片等资源,而这些资源在构建或之前下载的更新中尚未存在于设备上,则也需要下载它们。

    ¥Missing assets: If an update includes assets such as fonts and images that are not already on the device from the build or previously downloaded updates, they will need to be downloaded as well.

优化带宽使用

¥Optimizing bandwidth usage

  1. 首先监控使用情况:管理带宽的最简单方法是跟踪你的 使用指标 并识别任何异常峰值或低效率。

    ¥Monitor usage first: The easiest way to manage bandwidth is to track your usage metrics and identify any unusual spikes or inefficiencies.

  2. 优化资源大小:使用 本指南 减少资源的大小。

    ¥Optimize asset size: Reduce the size of your assets with this guide.

  3. 需要时排除资源:使用 资源选择 减少每次更新所包含的资源数量。这是一个高级优化,应首先尝试其他方法。

    ¥Exclude assets when needed: Use asset selection to reduce the number of assets included with each update. This is an advanced optimization and other approaches should be tried first.