Conversation
|
Should we add the source code for those wasm files? |
src/engine.rs
Outdated
| let memory = instance | ||
| .get_memory(&mut store, "memory") | ||
| .ok_or(anyhow::format_err!("failed to find `memory` export"))?; |
There was a problem hiding this comment.
Is this a standard? Do we need to document this somewhere?
There was a problem hiding this comment.
Its the way they do it in the docs and in their book: https://docs.rs/wasmtime/0.37.0/wasmtime/struct.Memory.html
https://docs.wasmtime.dev/contributing-architecture.html?highlight=memory#linear-memory
There was a problem hiding this comment.
To be clear, I'm talking about the memory string, not the method of measuring the associated memory
I don't see any use of the magic memory name in those docs 🤔 In fact the first link uses mem in some of their examples
There was a problem hiding this comment.
There was a problem hiding this comment.
It seems unlikely the function developer will have seen that before using this tool. We'll either need to
- (Ideal) Sum up all exported memory stores
- Document that they need to use the special
memoryname somewhere
There was a problem hiding this comment.
Summing up everything they export seems like a reasonable solution, given that we have access to a list of memory export names. I'd rather not document a naming limitation if we could remove the limitation instead.
There was a problem hiding this comment.
This is not a Rust standard, is a standard across compiler infrastructures (LLVM, Binaryen). As Kevin mentioned, you could post-process your Wasm and change the name of the exported memory, not sure what you'd gain by doing so though. Once multiple memories are officially supported by the compiler toolchains I'm pretty sure we'd need to update this. For now this seems a good, standard approach.
There was a problem hiding this comment.
Also multiple memories is going to introduce some complexities to measure resource usage. I suspect that with multiple memories we'd need to implement the Resource Limiter because not all memories declared in a Wasm module are expected to be exported. So the current approach won't be accurate.
There was a problem hiding this comment.
So the current approach won't be accurate.
True, but that's true regardless of whether or not we adopt the "memory" name standard since that's a name we're using to query exports. If that's an issue, let's open a separate separate thread about the approach of the PR in general.
On the topic of the "memory" name: In the latest commit Dominic added an approach that sums up all exported memories, which avoids this naming limitation. Is there a reason to re-add the limitation? It seems like a reasonable limitation if it's standard for LLVM and Binaryen, but it seems better to simply eliminate the limitation from my perspective.
There was a problem hiding this comment.
Yeah, the approach looks good. With the recent changes I don't see the need to reintroduce the "memory" naming standard. I emphasize on multi-memory because when we support it, for example for module linking, the approach here will need to differ considerably. Just want to make sure that this is on your radar.
we could, but I think it would bloat the repo |
Co-authored-by: dunk <duncan.uszkay@shopify.com>
Co-authored-by: dunk <duncan.uszkay@shopify.com>
How will we edit them without the source? 🤔 Is the idea that we'd just rewrite them if they ever needed to be updated? Are they simple enough that we can edit the WAT? |
|
For the test Functions, here is what they do/how I implemented them:
I don't think that any of them would be subject to change however |
|
Going to add @KevinRizzoTO for review since he worked on memory usage in our runtime engine. It would be good if this was aligned with how that is measured too |
Thanks for the add @jianghong. I actually like this implementation better than the one I ended up with. In short, I used the ResourceLimiter trait to hook into calls to the |
Are we planning to change the Runtime Engine implementation then? 🤔 Regardless of which implementation is better I think that we should have a plan towards consistency |
|
@DuncanUszkay1 Not at this time. The service is going to be deprecated once we finish the work for inline execution so it's probably not worth it just yet. The tracking of total memory usage isn't user facing, just sent to statsd to graph in datadog |
Gotcha. As long as we ensure that anything that is given to a developer is reproducible with the script runner I think we're good. |
DuncanUszkay1
left a comment
There was a problem hiding this comment.
Great work on this 👏🏻
What are you trying to accomplish?
The run function can now calculate the memory usage of a Function and add it to the FunctionRunResult struct so it can display it. I also added a unit test to check for a stack overflow error using a benchmark Function that allocates 80MB on the stack. The limit of 256KB is imposed by wasmtime.
What should reviewers focus on?
I checked out @jianghong's branch about memory limit, but I logged it instead of interrupting the Function, because of this.
The impact of these changes
On Shopify
Easier to test. De-bloats the main.
On merchants
No change
On third-party apps
No change.
Tophat 🎩
You can test your own script by running
cargo run --release -- <path/to/input.json> -s <path/to/script.wasm>.Note that
--releaseis mandatory to benchmark since the runtime is much shorter when the binary is optimized.Additionally, I wrote automated tests (that are executed in an opt-3 environment), so
cargo testwill show the results of these tests.Before you deploy