Stream: wasmtime

Topic: Running WasmTime components in an async context


view this post on Zulip Piotr Sarnacki (Oct 06 2024 at 19:57):

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.

view this post on Zulip Piotr Sarnacki (Oct 06 2024 at 20:14):

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:

view this post on Zulip Alex Crichton (Oct 06 2024 at 20:24):

(moving looks like it requires admin privileges so probably will need to wait until tomorrow)

Does this example showcase what you're looking for?

view this post on Zulip Piotr Sarnacki (Oct 06 2024 at 20:26):

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

view this post on Zulip Piotr Sarnacki (Oct 06 2024 at 23:41):

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?

view this post on Zulip Alex Crichton (Oct 06 2024 at 23:42):

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

view this post on Zulip Piotr Sarnacki (Oct 07 2024 at 14:17):

@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

view this post on Zulip Alex Crichton (Oct 07 2024 at 14:20):

Good point! Sounds like we should do a better job of having examples that use the curly-braced syntax too.

view this post on Zulip Alex Crichton (Oct 07 2024 at 14:20):

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!

view this post on Zulip Alex Crichton (Oct 07 2024 at 14:21):

(e.g. an issue or a comment here or such)

view this post on Zulip Piotr Sarnacki (Oct 07 2024 at 14:22):

I'm planning to open a PR with stuff that I was missing if that's OK :)

view this post on Zulip Alex Crichton (Oct 07 2024 at 14:22):

please do!

view this post on Zulip Notification Bot (Oct 07 2024 at 15:50):

This topic was moved here from #general > Running WasmTime components in an async context by David Bryant.


Last updated: Nov 22 2024 at 17:03 UTC