-
Notifications
You must be signed in to change notification settings - Fork 344
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
Metering improvements #670
Comments
Maybe you can clarify. They are not random, but rather arbitrary. ie. They are fixed for all instances and runs, but are rather meaningless. |
@ethanfrey If I do I understand correctly, every operator cost was 1 point flat in Wasmer 0.17: https://github.com/wasmerio/wasmer/blob/0.17.1/lib/middleware-common/src/metering.rs#L43-L113. This means we can trivially get similar or even the same gas results by using a constant |
Yes, it does look quite easy to get the same result. Let's use this for the 0.13 release and then open a new issue for a more nuanced gas meter (and new sdk-wasm multiplier calculation) in a future release. Clearly adding 2 registers is faster than reading from memory. |
We should benchmark different op codes to get a feel for relative cost. I took a look at NEAR, which uses wasmer in production, to see their gas metering strategy, and it seems like they charge a flat cost: Note they use |
Note, I think this page is a decent introduction to gas pricing and we should do something similar for docs (the high-level aspects): https://docs.near.org/docs/concepts/gas Notably, they have a huge difference between native token transfer and contract tokens...
So, around 35x more expensive for the contract (with CosmWasm + Cosmos SDK contracts are about 2x more expensive... maybe cuz the bank and auth modules are so inefficient? Or maybe cuz we have better caching?) |
I've been mulling this over and the best thing I can come up with is writing our own We could then write a Operators that were never profiled would probably get an expensive cost by default (I think?) Does this sound like a good direction? |
This sounds good. But isn't a middleware a Wasm -> Wasm mapping, such that we had to implement all profiling logic in Wasm? |
Yeah. I don't know much about Wasm, so it's a bit tricky to me. I'm trying to figure out if we can measure time sensibly by injecting the right Wasm code between each (?) operator. I think then it's a matter of keeping some sort of global map of |
I think we can 1. try to include them in some contract, 2. compare with similar operations, 3. look into the spec to dertermine if they are potentially expensive. |
This is similar to how the metering middleware works. This looks at blocks of code, not individual operations. We could adapt this approach to call a tracing import every time the metering middleware would do accounting. The import is implemented in the host and has access to a clock. |
Yeah, I studied it. That's a pretty neat idea. Wouldn't we want to be more granular though and do this per instruction? We can try to do some statistical magic with whole sequences of them timed, but I think timing each instruction would be more reliable. |
Or is it that most instructions will pretty much be a rounding error compared to calling something on the host? |
Some thoughts:
|
I feel convinced ;) |
I am super curious to learn what we get out of this. Maybe it's a dead end and we need to try something completely different. But it's worth a try. |
Interesting links from NEAR above. The docs look cool. I like the idea of a target gas/millisecond and the high numbers to be able to adjust in both direction. Here is their config:
The memory growth (per 64KiB page) seems ridiculously cheep such that I am afraid I missed something. |
Okay, it's probably about time for an update on what I've been up to. My attempts at creating a profiling tool (to assess how much time each op takes and what our cost function should look like) have failed so far, although I have the pieces and a clear idea of how it needs to work. I submitted what I have in a draft PR: #1042. Details are there! |
After significant work on #1042 it became clear that we currently cannot measure the execution time of individual Wasm operations precise enough to charge different price for them. Also there is a runtime parameter after memory.grow and memory copy operations would be important to read and consider first. In CosmWasm 1.0 gas price will be 150_000 times as large as in 0.16 and a target gas per second is defined. This should make future adjustment much easier than before. Done for now. We'll follow up with more specific issues. |
After migrating to Wasmer 1.0 and adding #668, there are a few smaller improvements we should do at some point:
get_remaining_points
/set_remaining_points
from Wasmer directly (done in Upgrade to latest Wasmer (🎅 edition) #676)VmError::RuntimeErr { .. } | VmError::GasDepletion { .. } => {}
and#[ignore] // fails due to the inability to handle gas depletion (https://github.com/wasmerio/wasmer/issues/1931)
, see Allow users to handle metering errors wasmerio/wasmer#1931; done in Upgrade to latest Wasmer (🎅 edition) #676)The text was updated successfully, but these errors were encountered: