I use WasmTime in my project with WASI in an async context. The reason is I want to be able to create a large number of instances and use as little resources as possible, thus avoid overhead of threads. It works great so far, but I wanted to decrease the amount of plumbing between the host and guest functions and implement WASI components. Is there any way to run WASI components in an async context? Note that I'm not talking about using async inside the modules, just executing the functions exported by WASM components in an async context.
I only now realized there is a dedicated #wasmtime channel here, if any mod sees it, please move there, I can't move topics, sorry! :man_facepalming:
(moving looks like it requires admin privileges so probably will need to wait until tomorrow)
Does this example showcase what you're looking for?
Yes, that seems like exactly what I was looking for, I have totally missed it. Thanks a lot for help, I'll try it out
I think a part of the confusion is that I haven't realised the bindgen!
macro can take a list of paramters with an async
option. @Alex Crichton do you think it would be valuable to add an async component example to examples in the wasmtime repo?
Yes of course! It'd be good to double-check it's documented here and for examples it'd be great to extend this list here too
@Alex Crichton sure, I'll take a look! the bindgen!
documentation definitely has that option, it's just that when looking at examples I always saw bindgen!("foo" in "foo.wit")
and I honestly haven't thought about looking up if any other syntax exists. It's a silly mistake, but I guess if it happened to me, it might happen to others too. I will also try to create an example with WASI cause, at least for me, it was not 100% apparent how to add WASI bindings to the linker. There is so many add_to_linker
methods that it takes a bit of time to find the right one. During the weekend I was switching my library to WASI components and for example this change was not obvious to me:
- wasmtime_wasi::preview1::add_to_linker_async(&mut linker, |t| &mut t.preview2_ctx)?;
+ wasmtime_wasi::add_to_linker_async(&mut linker)?;
In any case, I'll try to come up with some more examples that should make sense some time this week
Good point! Sounds like we should do a better job of having examples that use the curly-braced syntax too.
And examples is definitely something I think we should improve at, if you've got suggestions of good ones to add and/or locations to add them feel free to let us know!
(e.g. an issue or a comment here or such)
I'm planning to open a PR with stuff that I was missing if that's OK :)
please do!
This topic was moved here from #general > Running WasmTime components in an async context by David Bryant.
Last updated: Dec 23 2024 at 14:03 UTC