From b736585e2515f253d4507ae32f2e3180f4385192 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 16 Feb 2024 15:52:02 -0800 Subject: [PATCH] Add a script for benchmarking `wasmtime serve`'s requests per second (#7955) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a *ton* of different options such a script could have, and things we could tweak. This is just meant to be a shared starting point so it is easy to get up and running with something. Example output: ``` ./benches/wasmtime-serve-rps.sh -O pooling-allocator hello_wasi_http.wasm Finished `release` profile [optimized] target(s) in 0.17s Running `target/release/wasmtime serve -O pooling-allocator hello_wasi_http.wasm` Serving HTTP on http://0.0.0.0:8080/ Running `wasmtime serve` in background as pid 2476839 Benchmarking for 10 seconds... Summary: Total: 10.0025 secs Slowest: 0.0138 secs Fastest: 0.0001 secs Average: 0.0013 secs Requests/sec: 39461.5419 Response time histogram: 0.000 [1] | 0.001 [277602] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.003 [111637] |■■■■■■■■■■■■■■■■ 0.004 [4182] |■ 0.006 [720] | 0.007 [301] | 0.008 [143] | 0.010 [76] | 0.011 [26] | 0.012 [19] | 0.014 [7] | Latency distribution: 10% in 0.0006 secs 25% in 0.0009 secs 50% in 0.0012 secs 75% in 0.0016 secs 90% in 0.0019 secs 95% in 0.0022 secs 99% in 0.0031 secs Details (average, fastest, slowest): DNS+dialup: 0.0000 secs, 0.0001 secs, 0.0138 secs DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs req write: 0.0000 secs, 0.0000 secs, 0.0092 secs resp wait: 0.0012 secs, 0.0001 secs, 0.0137 secs resp read: 0.0000 secs, 0.0000 secs, 0.0113 secs Status code distribution: [200] 394714 responses ``` --- benches/wasmtime-serve-rps.sh | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 benches/wasmtime-serve-rps.sh diff --git a/benches/wasmtime-serve-rps.sh b/benches/wasmtime-serve-rps.sh new file mode 100755 index 0000000000..19262b5392 --- /dev/null +++ b/benches/wasmtime-serve-rps.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Usage: +# +# wasmtime-serve-rps.sh [WASMTIME-FLAGS] path/to/wasi-http-component.wasm +# +# For a basic WASI HTTP component, check out +# https://github.com/sunfishcode/hello-wasi-http +# +# You must have the `hey` tool installed on your `$PATH`. It is available in at +# least the `apt` and `brew` package managers, as well as a binary download via +# its github page: https://github.com/rakyll/hey + +set -e + +repo_dir="$(dirname $0)/.." +cargo_toml="$repo_dir/Cargo.toml" + +# Build Wasmtime. +cargo build --manifest-path "$cargo_toml" --release -p wasmtime-cli + +# Spawn `wasmtime serve` in the background. +cargo run --manifest-path "$cargo_toml" --release -- serve "$@" & +pid=$! + +# Give it a second to print its diagnostic information and get the server up and +# running. +sleep 1 + +echo 'Running `wasmtime serve` in background as pid '"$pid" + +# Benchmark the server! +echo "Benchmarking for 10 seconds..." +hey -z 10s http://0.0.0.0:8080/ + +kill "$pid"