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

bench: benchmark several common WASI scenarios #5274

Merged
merged 3 commits into from
Nov 16, 2022

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Nov 15, 2022

In order to properly understand the impact of providing thread-safe
implmentations of WASI contexts (#5235), we need benchmarks that measure
the current performance of WASI calls using Wiggle. This change adds
several common WASI scenarios as WAT files (see benches/wasi/*.wat)
and benchmarks them with criterion. Using criterion's iter_custom,
the WAT file runs the desired number of benchmark iterations internally
and the total duration of the runs is divided to get the average time
for each loop iteration.

Why WAT? When compiling these benchmarks from Rust to wasm32-wasi, the
output files are large, contain other WASI imports than the desired
ones, and overall it is difficult to tell if we are measuring what we
expect. By hand-writing the WAT, it is (slightly) more clear what each
benchmark is doing.

In order to properly understand the impact of providing thread-safe
implmentations of WASI contexts (bytecodealliance#5235), we need benchmarks that measure
the current performance of WASI calls using Wiggle. This change adds
several common WASI scenarios as WAT files (see `benches/wasi/*.wat`)
and benchmarks them with `criterion`. Using `criterion`'s `iter_custom`,
the WAT file runs the desired number of benchmark iterations internally
and the total duration of the runs is divided to get the average time
for each loop iteration.

Why WAT? When compiling these benchmarks from Rust to `wasm32-wasi`, the
output files are large, contain other WASI imports than the desired
ones, and overall it is difficult to tell if we are measuring what we
expect. By hand-writing the WAT, it is (slightly) more clear what each
benchmark is doing.
@abrown
Copy link
Contributor Author

abrown commented Nov 15, 2022

cc: @alexcrichton, @pchickey: I would like to add benchmarks for "scan a directory" and "read a file" but I don't know how to do that yet... any pointers to how to use path_open and fd_read the right way?

Copy link
Contributor

@jameysharp jameysharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the context for this PR, but I was curious so I reviewed it anyway, and it looks good to me!

benches/wasi.rs Outdated Show resolved Hide resolved
benches/wasi.rs Outdated Show resolved Hide resolved
@pchickey
Copy link
Contributor

Not much I can say about using fd_read and path_open from using .wat beyond, read what wasi-libc does to call them and mimic that. There is not a whole lot you can get wrong. fd_readdir is a total nightmare in preview1, but again wasi-libc can show the way.

@abrown abrown marked this pull request as ready for review November 16, 2022 01:01
@abrown
Copy link
Contributor Author

abrown commented Nov 16, 2022

I'm going to merge this as-is and figure out the next scenarios in a future PR.

@abrown abrown merged commit 8426904 into bytecodealliance:main Nov 16, 2022
@abrown abrown deleted the bench-wasi branch November 16, 2022 01:02
abrown added a commit to abrown/wasmtime that referenced this pull request Nov 21, 2022
This follows up on bytecodealliance#5274 to add several more scenarios with which to
benchmark WASI performance:
- `open-file.wat`: opens and closes a file
- `read-file.wat`: opens a file, reads 4K bytes from it, then closes it
- `read-dir.wat`: reads a directory's entries

Each benchmark is hand-crafted WAT to more clearly control what WASI
calls are made. As with bytecodealliance#5274, these modules' sole entry point takes a
parameter indicating the number of iterations to run in order to use
`criterion`'s `iter_custom` feature.
abrown added a commit to abrown/wasmtime that referenced this pull request Nov 21, 2022
This follows up on bytecodealliance#5274 to add several more scenarios with which to
benchmark WASI performance:
- `open-file.wat`: opens and closes a file
- `read-file.wat`: opens a file, reads 4K bytes from it, then closes it
- `read-dir.wat`: reads a directory's entries

Each benchmark is hand-crafted WAT to more clearly control what WASI
calls are made. As with bytecodealliance#5274, these modules' sole entry point takes a
parameter indicating the number of iterations to run in order to use
`criterion`'s `iter_custom` feature.
abrown added a commit to abrown/wasmtime that referenced this pull request Nov 21, 2022
This follows up on bytecodealliance#5274 to add several more scenarios with which to
benchmark WASI performance:
- `open-file.wat`: opens and closes a file
- `read-file.wat`: opens a file, reads 4K bytes from it, then closes it
- `read-dir.wat`: reads a directory's entries

Each benchmark is hand-crafted WAT to more clearly control what WASI
calls are made. As with bytecodealliance#5274, these modules' sole entry point takes a
parameter indicating the number of iterations to run in order to use
`criterion`'s `iter_custom` feature.
abrown added a commit to abrown/wasmtime that referenced this pull request Nov 21, 2022
This follows up on bytecodealliance#5274 to add several more scenarios with which to
benchmark WASI performance:
- `open-file.wat`: opens and closes a file
- `read-file.wat`: opens a file, reads 4K bytes from it, then closes it
- `read-dir.wat`: reads a directory's entries

Each benchmark is hand-crafted WAT to more clearly control what WASI
calls are made. As with bytecodealliance#5274, these modules' sole entry point takes a
parameter indicating the number of iterations to run in order to use
`criterion`'s `iter_custom` feature.
abrown added a commit that referenced this pull request Nov 22, 2022
* bench: add more WASI benchmarks

This follows up on #5274 to add several more scenarios with which to
benchmark WASI performance:
- `open-file.wat`: opens and closes a file
- `read-file.wat`: opens a file, reads 4K bytes from it, then closes it
- `read-dir.wat`: reads a directory's entries

Each benchmark is hand-crafted WAT to more clearly control what WASI
calls are made. As with #5274, these modules' sole entry point takes a
parameter indicating the number of iterations to run in order to use
`criterion`'s `iter_custom` feature.

* fix: reduce expected size of directory entries
@abrown abrown added the wasi Issues pertaining to WASI label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants