containerd: optimizations #293
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant performance optimizations and code improvements to the image saving and layer handling logic in
local/store.go
, with a focus on supporting containerd storage scenarios more efficiently. The main changes include implementing caching for containerd storage detection, optimizing layer processing by introducing parallelism, and improving how layer sizes are calculated and cached. These updates are especially beneficial for environments using containerd, leading to faster image saves and more efficient resource usage.Performance optimizations for containerd storage:
Store
struct and used it throughout the codebase to avoid redundant checks and improve performance. (containerdStorageCache
,usesContainerdStorageCached
) [1] [2]AddLayer
method to proactively calculate (or defer) the uncompressed size of compressed layers, optimizing for containerd by skipping unnecessary calculations during download and only performing them when required. [1] [2]Parallelization and concurrency improvements:
errgroup
and semaphores in both layer preparation for tar creation and during layer downloads, reducing wall-clock time and making better use of system resources. [1] [2]API and function signature updates:
doSave
,addImageToTar
) to accept anisContainerdStorage
flag, ensuring the optimizations are applied conditionally based on the storage backend. [1] [2] [3] [4]These changes collectively enhance the efficiency and scalability of image saving and layer management, especially when working with containerd-based Docker setups.
Note: the streaming of the existing layer files is the biggest win here by a large margin
This is an effort to close out buildpacks/pack#2272 and make sure perf is decent on docker's containerd storage option.
Using @edmorley 's slightly modified example in the issue above. This is a subsequent
pack build
. I've only extracted the Export numbers here as this isn't targeting the otherpack
inefficiencies.baseline non-
containerd
storage current lifecycle:containerd
storage current lifecycle:containerd
storage improved lifecycle:We are never going to get to pre-
containerd
perf due to the cheat we were using before. We now have to give the docker daemon layers we were entirely able to skip before. Those layers are also the bigger base layers. We are much closer todocker load <exported>
on a clean docker installation though. IME it was about ~1.7s.