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 monitor memory usage #201

Open
vlkv opened this issue Nov 17, 2023 · 4 comments
Open

How to monitor memory usage #201

vlkv opened this issue Nov 17, 2023 · 4 comments

Comments

@vlkv
Copy link
Contributor

vlkv commented Nov 17, 2023

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.

@alexcrichton
Copy link
Member

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

@gggrafff
Copy link
Contributor

@alexcrichton Hello! Thank you for your answer
It seems we misunderstood. I read about ResourceLimiter.

  1. It does the same as ResourceLimiter? https://github.com/bytecodealliance/wasmtime-go/pull/171/files
  2. 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,

@vlkv
Copy link
Contributor Author

vlkv commented Nov 20, 2023

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.

@alexcrichton
Copy link
Member

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.

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