Kong / ngx_wasm_module

Nginx + WebAssembly
Apache License 2.0
79 stars 7 forks source link

feat(wasmtime) expose cache_config directive #536

Closed hishamhm closed 4 months ago

hishamhm commented 4 months ago

This adds support for wasmtime { flag cache_config_load <config.toml>; }, for enabling 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.

Implementation notes:

hishamhm commented 4 months ago

@thibaultcha the tests for cache enabled and disabled don't actually check that the cache was actually created (I don't know how to check for the existence of files at the end of a test within the Test::Nginx DSL), but if you run each of them with -- ONLY you can see that one of them creates the cache in the temporary dir and the other one doesn't.

codecov[bot] commented 4 months ago

Codecov Report

Merging #536 (fa89090) into main (bb139e1) will decrease coverage by 0.00210%. Report is 2 commits behind head on main. The diff coverage is 89.47368%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536/graphs/tree.svg?width=650&height=150&src=pr&token=T0PT2Q9IAN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong)](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) ```diff @@ Coverage Diff @@ ## main #536 +/- ## =================================================== - Coverage 90.06471% 90.06261% -0.00210% =================================================== Files 47 47 Lines 10045 10063 +18 =================================================== + Hits 9047 9063 +16 - Misses 998 1000 +2 ``` | [Files](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | Coverage Δ | | |---|---|---| | [src/wasm/ngx\_wasm\_core\_module.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536?src=pr&el=tree&filepath=src%2Fwasm%2Fngx_wasm_core_module.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL3dhc20vbmd4X3dhc21fY29yZV9tb2R1bGUuYw==) | `92.64706% <ø> (ø)` | | | [src/wasm/wrt/ngx\_wrt\_wasmtime.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536?src=pr&el=tree&filepath=src%2Fwasm%2Fwrt%2Fngx_wrt_wasmtime.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL3dhc20vd3J0L25neF93cnRfd2FzbXRpbWUuYw==) | `82.56881% <89.47368%> (+0.36816%)` | :arrow_up: | | [Flag](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | `90.12555% <86.66667%> (-0.00588%)` | :arrow_down: | | [valgrind](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/536/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | `78.05435% <26.31579%> (-0.10945%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#carryforward-flags-in-the-pull-request-comment) to find out more.
thibaultcha commented 4 months ago

Ultimately it's fine if all we test is our directive and its calling of the underlying wasmtime function. We aren't responsible for testing the behavior of the runtime itself, even though that's a plus if we can, but well...