-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasmtime) new 'cache_config' directive for compilation cache
This adds support for `wasmtime { cache_config <config.toml>; }`, which enables disk caching of ahead-of-time compilation of `.wasm` files. This should alleviate noticeable CPU spikes when starting up workers using Wasmtime and Wasm modules larger than a few megabytes. Signed-off-by: Thibault Charbonnier <[email protected]>
- Loading branch information
1 parent
4ed3817
commit 91d447f
Showing
5 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
t/01-wasm/directives/011-wasmtime_cache_config_directive.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: | ||
|
||
use strict; | ||
use lib '.'; | ||
use t::TestWasmX; | ||
|
||
if ($t::TestWasmX::nginxV !~ m/wasmtime/) { | ||
plan(skip_all => "not built with Wasmtime, skipping"); | ||
|
||
} else { | ||
plan_tests(4); | ||
} | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: wasmtime cache_config - missing file | ||
--- main_config | ||
wasm { | ||
wasmtime { | ||
cache_config missing_file; | ||
} | ||
} | ||
--- error_log eval | ||
qr/\[emerg\] .*? failed configuring wasmtime cache; failed to read config file: missing_file/ | ||
--- no_error_log | ||
[error] | ||
[crit] | ||
--- must_die | ||
|
||
|
||
|
||
=== TEST 2: wasmtime cache_config - invalid contents file | ||
--- user_files | ||
>>> wasmtime_config.toml | ||
invalid contents | ||
--- main_config | ||
wasm { | ||
wasmtime { | ||
cache_config $TEST_NGINX_HTML_DIR/wasmtime_config.toml; | ||
} | ||
} | ||
--- error_log eval | ||
qr@\[emerg\] .*? failed configuring wasmtime cache; failed to parse config file: .*/wasmtime_config.toml@ | ||
--- no_error_log | ||
[error] | ||
[crit] | ||
--- must_die | ||
|
||
|
||
|
||
=== TEST 3: wasmtime cache_config - valid file, cache disabled | ||
--- user_files | ||
>>> wasmtime_config.toml | ||
[cache] | ||
enabled = false | ||
--- main_config eval | ||
qq{ | ||
wasm { | ||
module hostcalls $t::TestWasmX::crates/hostcalls.wasm; | ||
|
||
wasmtime { | ||
cache_config $ENV{TEST_NGINX_HTML_DIR}/wasmtime_config.toml; | ||
} | ||
} | ||
} | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/set_request_header \ | ||
value=Hello:wasm'; | ||
proxy_wasm hostcalls 'test=/t/echo/headers'; | ||
} | ||
--- response_body | ||
Host: localhost | ||
Connection: close | ||
Hello: wasm | ||
--- error_log eval | ||
qr@setting wasmtime cache config file: ".*/wasmtime_config.toml"@ | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 4: wasmtime cache_config - valid file, cache enabled | ||
--- user_files | ||
>>> wasmtime_config.toml | ||
[cache] | ||
enabled = true | ||
directory = "/tmp/ngx_wasm_module/cache/wasmtime" | ||
--- main_config eval | ||
qq{ | ||
wasm { | ||
module hostcalls $t::TestWasmX::crates/hostcalls.wasm; | ||
|
||
wasmtime { | ||
cache_config $ENV{TEST_NGINX_HTML_DIR}/wasmtime_config.toml; | ||
} | ||
} | ||
} | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/set_request_header \ | ||
value=Hello:wasm'; | ||
proxy_wasm hostcalls 'test=/t/echo/headers'; | ||
} | ||
--- response_body | ||
Host: localhost | ||
Connection: close | ||
Hello: wasm | ||
--- error_log eval | ||
qr@setting wasmtime cache config file: ".*/wasmtime_config.toml"@ | ||
--- no_error_log | ||
[error] |