BuildKit Registry Cache vs. Local Layer Cache for CI Retry Efficiency
0 reputation · 31 Oct 2020, 06:34 UTC
0 reputation · 31 Oct 2020, 06:34 UTC
In distributed CI environments using Docker BuildKit, the goal is to prevent the re-execution of expensive RUN instructions that perform heavy filesystem writes when a build is retried or triggered across different agents.
Local layer caching allows a single agent to skip unchanged steps instantly. However, in ephemeral CI runners, this cache is lost between jobs. BuildKit's --cache-from and --cache-to options enable the use of a remote registry backend to share these layers across a cluster, potentially avoiding redundant writes on new agents.
The trade-off involves the overhead of pulling remote cache manifests and layers versus the compute and I/O cost of re-running the write-heavy instructions locally.
Which approach provides more consistent build times for large-scale filesystem writes in ephemeral environments: relying on local cache persistence via volume mounts or utilizing a registry-based cache backend?
Under what network latency thresholds does the cost of pulling remote layers exceed the cost of re-executing the write instructions?
35775 reputation · 31 Oct 2020, 06:51 UTC
For large‑scale filesystem write steps in ephemeral CI runners, a persistent local layer cache (via a volume mount) yields more consistent build times than a registry‑based cache, because reuse is near‑instant and unaffected by network latency.
RUN step exceeds that pull/push overhead.When the volume‑backed local cache is available, the cached layer is read directly from disk, giving sub‑second reuse regardless of network conditions. The registry approach incurs variable latency (RTT, bandwidth, possible throttling) and therefore produces a wider spread of build times, especially under congested or high‑latency links.
WRITE RUN instruction on a clean agent (no cache). Call this T_reexec.T_pullpush.T_reexec > T_pullpush, the registry cache is expected to be faster; otherwise rely on the local volume cache.tc netem delay 100ms) and re‑measure T_pullpush to see at what latency the recommendation flips.If you do not know the actual re‑execution time of the heavy write step on a fresh runner (T_reexec), obtain that measurement first; it directly determines which cache strategy is preferable.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.