API Reference alternera_plugin_wasm_framework v#0.9.0

Copy Markdown View Source

Modules

Starts Slots, the node's limit on guests running at once, UploadedModules, the node's cache of uploaded modules, and Runtime.Port.Pool, the processes of the port runtime. The package is a dependency of every language plugin, so all three are up before a language step runs.

The frames of guest interface version 0 (c_src/alternera_guest.h), the host's side. A field is a 32-bit little-endian length and that many bytes.

The host functions a language step's guest calls through alternera.host_call, served in the process that runs the step (Runtime.call/5), each through the plugin SDK only: Plugin.Provisional.Store, Plugin.Provisional.Reads (over Plugin.Host) and Plugin.Provisional.Calls.

What every language step shares, the way PluginHosts.Step is shared by the plugin hosts' steps: a language plugin holds a %Language{} naming itself and its module, and delegates its callbacks here.

A language step's "Memory limit" setting: how much memory the script's guest may use in one call. Guest memory is outside every BEAM limit, so the step says it, where whoever edits the pipeline sees it, and it travels with the step in exports and releases.

Reads the outline of a WebAssembly core module from its bytes, without compiling it: its imports, exports, memories, whether it has a start function, and its custom sections. The runtime binding does not expose custom sections, and an uploaded module must be judged before anything of it runs, so the walk is ours: the module header, then each section's id and LEB128 length, reading only the sections it needs.

The node's compiled language modules, one per module digest (SHA-256 of the .wasm bytes), kept in :persistent_term: compiling an interpreter takes 150 to 500 ms, so it happens once per node, when the language plugin's package starts (load/2 from its application's start/2), not on the first request. A call finds its module by digest (fetch/1); a module not loaded yet is compiled then, once.

The WebAssembly runtime a language step runs its module on, as a behaviour, so the binding underneath can be replaced without touching anything above it. Nothing outside an implementation names the binding, its engine, epochs or fuel: callers speak in limits/0 and host/0.

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.

The host program of Runtime.Port, alternera_wasm_host, built from the package's native/alternera_wasm_host/ crate: where it is, what it is started with, and whether it can run here.

Compiles a module for Runtime.Port in a host process of its own (alternera_wasm_host compile IN OUT), never in a serving one: a compile then has a time limit (the process is killed past compile_timeout_ms/0), a fault of the compiler on a hostile module costs that process, and no serving process stalls behind a compile.

The node's alternera_wasm_host serve processes for Runtime.Port, each an Erlang port running one call at a time.

The frames between the node and alternera_wasm_host serve, over the port with {:packet, 4}. A frame is one tag byte and fixed little-endian fields, then bytes to its end. The framework's own frames (PluginWasmFramework.Frame) travel inside as bytes.

PluginWasmFramework.Runtime on wasmex 0.18.1, a precompiled NIF over Wasmtime. Experimental: the binding is chosen for good at the gate after the first language plugin, with numbers from the Observatory.

The node's limit on guests running at once, shared fairly between tenants. How many may run is the configured runtime's (Runtime.max_running/0): Runtime.Wasmex lets one fewer run than its threads, so one always stays free for its epoch tick (a guest keeps its thread until the tick, and the tick is a task on the same threads: on a two-thread node two endless scripts at once stopped every language step); Runtime.Port lets as many run as the node has processors, since each guest is an OS process of its own with its ticker on its own thread.

The step editor every language step shares, laid out as Script's editor is, so what a user knows of it carries over. A language plugin's editor is a thin LiveComponent that hands its %Language{} and its callbacks here, as Camel's hands its %PluginHosts.StepEditor{} to the plugin hosts' editor

The contract a language plugin keeps, as ExUnit tests, the way the SDK's plugin_contract/2 checks a plugin. The plugin gives, in its own language, the source for each named scenario; the kit runs each through the step with the SDK's test host (Plugin.Test) and checks the result.

Takes a compiled module a user uploads into a step: checks it, compiles it and stores it (Plugin.Provisional.Files), so a broken module is refused in the editor, never on the first request.

The node's compiled uploaded modules: modules a user uploaded into a step, as opposed to the shipped languages' (Modules, kept for good in :persistent_term). Uploads come and go, so they live in an ETS table bounded by the size of their files (:uploaded_cache_bytes in the framework's application env, 256 MiB by default), the least recently used going first when a new one does not fit. A module evicted is compiled again from storage on its next use.

The named parameters an uploaded module declares, and how a step's bindings turn them into the tenant's own stores, pipelines, variables and secrets.

Mix Tasks

Puts alternera_wasm_host, the host program of PluginWasmFramework.Runtime.Port, at priv/native/<target>/alternera_wasm_host in the framework package.