Alternera. PluginWasmFramework. Runtime. Port
(alternera_plugin_wasm_framework v0.9.0)
Copy Markdown
View Source
PluginWasmFramework.Runtime in OS processes: the package's own host
program, alternera_wasm_host (native/alternera_wasm_host/, Wasmtime
51.0.0, the version wasmex 0.18.1 carries), run as Erlang ports by
Runtime.Port.Pool. A fault, a hang or a compiler bug costs one OS
process, never the node.
config :alternera_plugin_wasm_framework, runtime: :portprepare/1 compiles in a process of its own into the node's cache of
compiled modules (Runtime.Port.Compiler) and answers a handle to the
file. call/5:
- checks a process out of the pool (the caller becomes its port's
owner), or, for a call made while a holder up the caller's chain is
parked in a host call, borrows that holder's port
(
Pool.held_port/0): a nested call runs in a second instance in the same process. The port is lent only for the host call's length, and taken back only once every borrow deeper ended (Pool.lend/3,Pool.reclaim/4); - takes a slot (
PluginWasmFramework.Slots); - sends one
Cframe and serves what the guest asks for until its result: host calls withhost.call(the slot goes back meanwhile, as with wasmex), body pieces withhost.body, and growth past the call's free floor, claimed throughPlugin.Host.claim_held_bytes/2when the limits sayclaim: true; - hands the port back. The host drops the instance after it answered, so Wasmtime resets its slot while the node already has the result.
The time a slot is held is the guest's running time, reported as
guest_us: the guest's work outside the BEAM, which its reductions
leave out.
A module a process has not loaded answers "not loaded" and is loaded
from its compiled file and called again, once. The host interrupts a
guest at its deadline itself (an epoch ticker on a thread of its own) and
answers a time-out; past the deadline the caller cancels a host call it
cannot resume, and kills the OS process when no result came
@backstop_ms after the deadline (or after its last answer, when a host
call ran past the deadline). A host function that raises or exits kills
the process too, since its guest waits for an answer that will not come,
and the error goes on.
Summary
Functions
The bytes of guest memory a call may take before its growth is claimed
(:guest_free_mib in the framework's env, 8: the Body × floor).
Types
Functions
@spec free_bytes() :: non_neg_integer()
The bytes of guest memory a call may take before its growth is claimed
(:guest_free_mib in the framework's env, 8: the Body × floor).