Alternera. PluginWasmFramework. UploadedModules
(alternera_plugin_wasm_framework v0.9.0)
Copy Markdown
View Source
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.
Compiling is CPU-heavy and has no time limit of its own, so uploaded
modules compile one at a time per node, uploads and cache misses
alike, in this server. A caller that finds no entry reads the file
itself (in its own process, which may hold a database connection) and
asks the server to compile it, waiting at most compile_wait_ms/0;
past that the call fails with :not_ready while the compile finishes
and the entry is kept for the next call.
An entry is keyed by digest only. Who may run it is not this module's
business: a step checks that its tenant stored the file first
(Language), on every run.
Each entry keeps the module's declared parameters (Uses), read from
the bytes it was compiled from, so what a step enforces is bound to
the digest that runs.
Summary
Types
A compiled upload: the module as Modules answers it, its declared
parameters and the size of its file.
Functions
The cache's size budget, in bytes of module files.
Returns a specification to start this module under a supervisor.
Drops every entry (a test's clean slate).
Compiles wasm on this node, one compile at a time, and keeps it:
the entry, or why it does not compile. Waits at most info.wait_ms,
capped at compile_wait_ms/0 (:not_ready then); a step passes its
time left, so a wait never outlasts the step.
How long a step waits for its module to compile before it fails.
The entry for digest, compiled from what read answers when it is
not on this node. read runs in the calling process, only on a miss.
info goes to the compile's log line and telemetry (tenant_id),
and its wait_ms bounds the wait (compile/3).
The entry for digest when it is compiled on this node for runtime,
marked used. An entry another runtime compiled (the runtime was
switched, as a load profile does) is a miss: the compile that follows
replaces it.
Notes that tenant_id stored digest.
Whether this node has seen that tenant_id stored digest
(own/2): a step checks it on every run, since the compiled module
is shared by digest. A node forgets nothing it learned, also when
Alternera.PluginFileCleanup removes the stored file.
Types
@type entry() :: %{ module: Alternera.PluginWasmFramework.Modules.t(), uses: Alternera.PluginWasmFramework.Uses.t(), size: non_neg_integer() }
A compiled upload: the module as Modules answers it, its declared
parameters and the size of its file.
Functions
@spec cache_bytes() :: pos_integer()
The cache's size budget, in bytes of module files.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Drops every entry (a test's clean slate).
Compiles wasm on this node, one compile at a time, and keeps it:
the entry, or why it does not compile. Waits at most info.wait_ms,
capped at compile_wait_ms/0 (:not_ready then); a step passes its
time left, so a wait never outlasts the step.
@spec compile_wait_ms() :: pos_integer()
How long a step waits for its module to compile before it fails.
@spec fetch(String.t(), (-> {:ok, binary()} | {:error, String.t()}), map(), module()) :: {:ok, entry()} | {:error, String.t()} | :not_ready
The entry for digest, compiled from what read answers when it is
not on this node. read runs in the calling process, only on a miss.
info goes to the compile's log line and telemetry (tenant_id),
and its wait_ms bounds the wait (compile/3).
The entry for digest when it is compiled on this node for runtime,
marked used. An entry another runtime compiled (the runtime was
switched, as a load profile does) is a miss: the compile that follows
replaces it.
Notes that tenant_id stored digest.
Whether this node has seen that tenant_id stored digest
(own/2): a step checks it on every run, since the compiled module
is shared by digest. A node forgets nothing it learned, also when
Alternera.PluginFileCleanup removes the stored file.