wasmtime-go
wasmtime-go copied to clipboard
How to monitor memory usage
Hello!
In my project I need to monitor memory usage inside the Wasm VM's store. Is there a corresponding API to do this?
Thank you.
In the Rust wasmtime
crate the type for this is the ResourceLimiter
trait. That API is not bound in the C API which this repository uses, however, so currently this can't be done through Go. If you're interested though adding bindings for that API to the C API would be much appreciated
@alexcrichton Hello! Thank you for your answer It seems we misunderstood. I read about ResourceLimiter.
- It does the same as ResourceLimiter? https://github.com/bytecodealliance/wasmtime-go/pull/171/files
- We need not only limiting but monitoring also. We want monitor :
- how much memory was reserved (is about it
memory.DataSize()
???), - how much memory was consumed (consumed of reserved),
- when will the next increase of
memory.DataSize
occur,
- how much memory was reserved (is about it
Yes, indeed, my question was not about how to limit the memory, but how to know at runtime how much memory is occupied, free, etc right now.
Ah so the API implemented in #171 is a less-powerful version of the ResourceLimiter
trait. Despite its name that trait in Rust enables "listening" effectively to changes in memory. For example the trait gets an accurate snapshot of all memory used within a Store
and notifications whenever memory is grown. The trait can optionally disallow some growth (hence the "limiter" in the name) but it could also only be there for accounting purposes (which I think is what you want here).
In that sense the ResourceLimiter
trait is the way to do this, but that's only exposed in a limited fashion in the C API right now because otherwise it'd involve callbacks and such in C.