Open zhenjunMa opened 3 years ago
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.
@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.
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
OK, although i am new to rust, i will have a try😊
Hello, any progress here?..
@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.
Unfortunately, no, but I would recommend reading over the Rust documentation for this, learning the C API's implementation a bit, and starting there.
@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
Indeed!
Can you please take a look at https://github.com/bytecodealliance/wasmtime-go/pull/171 It looks to me that there is no need to implement anything in C API, but I am not completely sure)
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:
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?