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

How to set resource limit in wasmtime-go? #101

Open
zhenjunMa opened this issue Sep 14, 2021 · 10 comments
Open

How to set resource limit in wasmtime-go? #101

zhenjunMa opened this issue Sep 14, 2021 · 10 comments

Comments

@zhenjunMa
Copy link

zhenjunMa commented Sep 14, 2021

1. background

In my case, i want to limit the max memory that the *.wasm file can use, if it reached the limit, it can crash by OOM.

it's better for me to limit both stack and heap memory.

2. what i have found

In wasmtime, which is written by rust, i found some api to limit the resource:

cpu limit : https://docs.rs/wasmtime/0.29.0/wasmtime/struct.Config.html#method.consume_fuel
stack limit: https://docs.rs/wasmtime/0.29.0/wasmtime/struct.Config.html#method.consume_fuel
memory limit: https://docs.rs/wasmtime/0.29.0/wasmtime/struct.Config.html#method.consume_fuel

these features are so cool and meet my needs, i also found a project named lunatic, it build on wasmtime and allow users to set resource limit as the doc said:

image

3. my question

my host environment is written by golang, so i want to use wasmtime-go to load and run wasm instance, i know this project uses CGO to consume the C API of the Wasmtime project, but i can't find how to set resource limit in wasmtime-go API.

any ideas about this?

@alexcrichton
Copy link
Member

Thanks for the report! The main type used for this is a ResourceLimiter in the Rust API and the Store::limiter API. At this time though I don't believe those are exposed via the C API (and transitively not into the Go API as well).

I think the first steps to handling this would be filling out the C API for those constructs, and then it could be mirrored into the Go API as well.

@zhenjunMa
Copy link
Author

@alexcrichton

Thanks for your reply!
Is there currently a planned time to complete the first step? maybe on November or December ? hhhh

I think that supporting wasm's resource restriction is an essential condition for wasm to run in a production environment, and the number of users of the wasmtime-go project should be quite large.

@alexcrichton
Copy link
Member

I don't believe anyone is currently signed up specifically for doing this, but if you're interested we're always happy to review PRs for additions to the C API

@zhenjunMa
Copy link
Author

OK, although i am new to rust, i will have a try😊

@vlkv
Copy link
Contributor

vlkv commented Jan 26, 2023

Hello, any progress here?..

@vlkv
Copy link
Contributor

vlkv commented Jan 27, 2023

@alexcrichton Hi, can you give an example of a similar merged PR which adds something to the C API? I need the resource limit feature and would like to try to implement it myself. Similar PR would help me to get started, a lot.

@alexcrichton
Copy link
Member

Unfortunately, no, but I would recommend reading over the Rust documentation for this, learning the C API's implementation a bit, and starting there.

@vlkv
Copy link
Contributor

vlkv commented Mar 1, 2023

@alexcrichton Hello, If I want to contribute to C API, which sources should I look at? These, right? https://github.com/bytecodealliance/wasmtime/tree/main/crates/c-api

@alexcrichton
Copy link
Member

Indeed!

vlkv pushed a commit to vlkv/wasmtime-go that referenced this issue Mar 1, 2023
vlkv pushed a commit to vlkv/wasmtime-go that referenced this issue Mar 1, 2023
@vlkv
Copy link
Contributor

vlkv commented Mar 1, 2023

Can you please take a look at #171 It looks to me that there is no need to implement anything in C API, but I am not completely sure)

alexcrichton pushed a commit that referenced this issue Mar 2, 2023
* How to set resource limit in wasmtime-go? (#101)

* Using dev version temporarily

---------

Co-authored-by: Vitaly Volkov <[email protected]>
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

No branches or pull requests

3 participants