-
Notifications
You must be signed in to change notification settings - Fork 97
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
Store Compiled Modules when using OCI Wasm Images #405
Store Compiled Modules when using OCI Wasm Images #405
Conversation
e29594f
to
4c01e11
Compare
fyi @cpuguy83 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to add some GC labels so containerd does not collect this content.
See: https://github.com/containerd/containerd/blob/8459273f806e068e1a6bacfaf1355bbbad738d5e/docs/garbage-collection.md#garbage-collection-labels
How do we invalidate (and de-reference in containerd) pre-compiled modules?
As I understand it a pre-compiled module will not work across different versions of a runtime.
Also we likely need to annotate what runtime the content is for.
Also, when writing the content we'll need to attach a lease to it until gc labels are applied otherwise containerd will collect it.
From my experimenting, the GC is looks to be a top down model. So I've put the label that retains on the image level: https://github.com/containerd/runwasi/pull/405/files#diff-74fa6f2b9f387ae0683336f3c04b7e15658dbb2c2820f74bd143894009593d1bR365-R368. If the image gets removed this will be removed as well. log::debug!("updating content with precompile digest to avoid garbage collection");
let mut image_content = self.get_info(digest.clone())?;
image_content.labels.insert("containerd.io/gc.ref.content.precompile".to_string(),precompile_digest.clone(),);
I did this here, but as you point out might need to do this per version as well. That way if a runtime is upgraded it would re-compute. let label = format!("runwasi.io/precompiled/{}", T::name()); For dereferencing, do you think it is enough to wait for the image to be removed, which would drop the couple versions (if there are any)? I don't think it will be too much space to have a couple versions of it sitting around vs complexity to dereference them on an ongoing basis. For example, during the upgrade of the shim I think there might be alot of edge cases.
Ah, I was wondering about that! There did seem to be a small moment where it could be cleaned up before I put the label on the image. I will take a look at putting a lease on it. |
@jsturtevant Started reviewing this PR. How do I run this to see if the modules are stored? |
The shim logs have will have statements and you will also be able to verify in containerd using Find the compiled info:
See it in the content store:
save it to local file:
|
4c01e11
to
a4a353b
Compare
Added a lease during new content creation |
a4a353b
to
96dfd6b
Compare
Another question I had was if this is something we want to turn on for all images (as the code is now) or if we want to put an annotation on the image that would enable this feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jsturtevant great PR! Sorry I was late for the code review.
Honestly it took me some time to grasp the interaction between containerd and the sandbox for saving / retriving precompiled content using leases. I am still not 100% sure the full picture of the interactions. Would be appreciate if you clarify the logic here (maybe document it somewhere?)
@CaptainVincent does WasmEdge Rust SDK have an API to AOT compile a Wasm module to bytes that's similar to https://github.com/bytecodealliance/wasmtime/blob/7690c500228ae005fc70ee3b6297bb4b403686d5/crates/wasmtime/src/engine.rs#L222-L223? |
I've thought on this a bit more and I think it should be opt in feature so will add support for an annotation |
I don't think an annotation on the image would work well. We must compile the wasm to run it at all, so we already need to store it. |
Yes. This lines of the code provides two methods about
|
I was leaning towards it being experimental but I can keep it as. |
f58fe43
to
941e500
Compare
Signed-off-by: James Sturtevant <[email protected]>
Signed-off-by: James Sturtevant <[email protected]>
Co-authored-by: Vaughn Dice <[email protected]> Signed-off-by: James Sturtevant <[email protected]> Signed-off-by: James Sturtevant <[email protected]>
Signed-off-by: James Sturtevant <[email protected]>
Signed-off-by: James Sturtevant <[email protected]>
Signed-off-by: James Sturtevant <[email protected]>
0d38599
to
603d448
Compare
I tracked this down to the call to parallelize the compile step here. The engine should be usable across threads and each test should be creating a new "engine" so I don't know why this happens. |
Did we turn on the "parallel-compilation" feature of wasmtime? |
yes we turn it that feature
and it looks to be avaliable on my machine as well as on CI My next step is to make a small/simpler reproducible example |
I was able to create a simple repo: https://github.com/jsturtevant/rayon-clone-issue/blob/master/src/main.rs. After adding the unit tests I am effectively running into #357 which is also called out in rayon-rs/rayon#708 (comment) |
I've updated wasmtime to use this hash for the label |
I've added the ability to disable the parallel compilation for the tests. We won't run into this issue as is in the shim since each shim is it's own instance but we need to address it longer term with #357 |
Signed-off-by: James Sturtevant <[email protected]>
1d85d31
to
063242a
Compare
test failure was #423 |
Signed-off-by: James Sturtevant <[email protected]>
346e064
to
15a8212
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work!
@cpuguy83 I've addressed the feedback, could you take another look? Thanks! |
🥳 Awesome! I am going to do a new release |
this would replace #44