tessi / wasmex

Execute WebAssembly from Elixir
MIT License
546 stars 31 forks source link

Question: long-running WASM + Erlang scheduler #593

Closed munjalpatel closed 3 months ago

munjalpatel commented 3 months ago

Hey @tessi amazing work!

Erlang scheduler generally doesn't like long-running processes. For native Erlang / Elixir processes, it uses reductions to preempt so that other processes have fair chance of CPU slice.

How would the scheduler react to WASM running through Rustler? What advise do you have when someone needs to run potentially long-running WASM modules?

munjalpatel commented 3 months ago

I think #6 and #7 has the answers I need. Not sure if you want to provide any additional comment / context @tessi

tessi commented 3 months ago

ha! hey @munjalpatel 👋

you already found the good answers for actual function calls into WASM. There is other things (like compiling a WASM module) which is still sync and uses a "dirty CPU scheduler" in the NIF function. Not ideal and we're planning a bigger refactoring to make all things async long term. But for now, compilation and instantiation aren't usually bottlenecks and those things that are bottlenecks (function calls) are already async.

Hope this give you some more context :)

munjalpatel commented 3 months ago

@tessi tbh, I think use of DirtyCPU for module compilation is fair given one-time cost -- provided there is an easy mechanism to preserve compiled / initialized modules to the disk or in memory. Which I believe we have (correct me if wrong)!