Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support generating new image with separate blob for prefetched files #1649

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Maxing1997
Copy link

Relevant Issue #1589

The objective is to generate a new image, which references a new blob included prefetch file chunks. This will accelerate an startup performance due to high-priority pulling of prefetch blob.

Details

Implement optimize subcommand of nydusify to generate a new image, which references a new blob included prefetch file chunks.

Types of changes

What types of changes does your PullRequest introduce? Put an x in all the boxes that apply:

  • New feature (non-breaking change which adds functionality)

Checklist

Go over all the following points, and put an x in all the boxes that apply.

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Major changes:
1. Added compatibility for rafs v5/v6 formats.
2. Set IS_PREFETCHBLOB flag in BlobInfo for prefetchblob.
3. Introduced two new options for storing prefetchblobID path and the optimized bootstrap path.

Signed-off-by: Xing Ma <[email protected]>
@Maxing1997 Maxing1997 requested a review from a team as a code owner November 29, 2024 09:19
@Maxing1997 Maxing1997 requested review from imeoer, jiangliu and gaius-qi and removed request for a team November 29, 2024 09:20
@Maxing1997 Maxing1997 changed the title Maxing mr/nydusify optimize support generating new image with separate blob for prefetched files Nov 29, 2024
We can statically analyze the image entrypoint dependency, or use runtime dynamic
analysis technologies such as ebpf, fanotify, metric, etc. to obtain the container
file access pattern, and then build this part of data into an independent image layer:

* preferentially fetch blob during the image startup phase to reduce network and disk IO.
* avoid frequent image builds, allows for better local cache utilization.

Implement optimize subcommand of nydusify to generate a new image, which references a new
blob included prefetch file chunks.
```
nydusify optimize --policy separated-prefetch-blob \
	--source $existed-nydus-image \
	--target $new-nydus-image \
	--prefetch-files /path/to/prefetch-files
```

More detailed process is as follows:
1. nydusify first downloads the source image and bootstrap, utilize nydus-image to output a
new bootstrap along with an independent prefetchblob;
2. nydusify generate&push new meta layer including new bootstrap and the prefetch-files ,
also generates&push new manifest/config/prefetchblob, completing the incremental image build.

Signed-off-by: Xing Ma <[email protected]>
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 118 lines in your changes missing coverage. Please review.

Project coverage is 59.98%. Comparing base (375f55f) to head (8437d8d).

Files with missing lines Patch % Lines
builder/src/optimize_prefetch.rs 0.00% 51 Missing ⚠️
src/bin/nydus-image/main.rs 0.00% 35 Missing ⚠️
contrib/nydusify/cmd/nydusify.go 0.00% 27 Missing ⚠️
storage/src/device.rs 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1649      +/-   ##
==========================================
- Coverage   60.10%   59.98%   -0.13%     
==========================================
  Files         147      147              
  Lines       49513    49603      +90     
  Branches    46994    47057      +63     
==========================================
- Hits        29762    29756       -6     
- Misses      17970    18065      +95     
- Partials     1781     1782       +1     
Files with missing lines Coverage Δ
storage/src/device.rs 66.63% <0.00%> (-0.36%) ⬇️
contrib/nydusify/cmd/nydusify.go 13.52% <0.00%> (-0.54%) ⬇️
src/bin/nydus-image/main.rs 0.58% <0.00%> (-0.01%) ⬇️
builder/src/optimize_prefetch.rs 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

.help("Output path of the new bootstrap"),
)
.arg(
Arg::new("output-path")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name it output-json and reuse the BuildOutput struct in builder/src/core/context.rs ?

Arg::new("output-path")
.long("output-path")
.short('o')
.help("Output path of for save hot blob id"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File path to save optimization information in JSON format

@@ -79,6 +79,8 @@ bitflags! {
const _V5_NO_EXT_BLOB_TABLE = 0x8000_0000;
/// Blob is generated with chunkdict.
const IS_CHUNKDICT_GENERATED = 0x0000_0200;
/// Blob is a hot blob
const IS_PREFETCHBLOB = 0x0001_0000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about IS_SEPARATED_WITH_PREFETCH_FILES ?

@@ -79,6 +79,8 @@ bitflags! {
const _V5_NO_EXT_BLOB_TABLE = 0x8000_0000;
/// Blob is generated with chunkdict.
const IS_CHUNKDICT_GENERATED = 0x0000_0200;
/// Blob is a hot blob
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Blob is generated with separated prefetch files..

@@ -508,6 +510,12 @@ impl BlobInfo {
}
}

pub fn set_hot_blob_feature(&mut self, is_prefetchblob: bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_separated_with_prefetch_files_feature

@@ -0,0 +1,536 @@
// Copyright 2023 Nydus Developers. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024

return nil
}

// Optimize covert and push a new optimized nydus image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

covert -> converts

return errors.Wrap(err, "Init source image parser")
}
sourceParser, err := parser.New(sourceRemote, runtime.GOARCH)
if sourceParser == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil {

return &blobDesc, nil
}

func pushCompoundBootstrap(ctx context.Context, opt Opt, buildInfo BuildInfo) (*bootstrapInfo, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushCompoundBootstrap -> pushNewBootstrap ?

bootstrapTarRa, err := os.Open(bootstrapTarPath)
if err != nil {
return nil, errors.Wrap(err, "open bootstrap tar file")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer bootstrapTarRa.Close()

@imeoer
Copy link
Collaborator

imeoer commented Dec 4, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants