Configuration

View Source

This page lists every setting in one place, with its default and the page that explains it. Read it when you deploy the runtime, and when you tune it: you can only change a default that you know about. There are four kinds of setting: the application environment, for the whole node; the limits map, for one instance; the instantiate options; and the worker options.

Settings for production

Most nodes need only two settings. Put them in your release's sys.config:

%% sys.config
[{wasm, [{scratch_roots, #{scratch => "/var/lib/myapp/wasm-scratch"}},
         {code_cache_dir, "/var/lib/myapp/wasm-code"}]}].

scratch_roots is where request files live. When a node restarts after a crash, it cleans up there what the crashed node left behind. code_cache_dir keeps compiled code across restarts. Make both directories writable only by the node's user: see Security.

The application environment

Set these in sys.config, under wasm, or with application:set_env(wasm, Key, Value) before the runtime reads them. The module cache and the page budget read theirs when the application starts.

Memory and modules

keydefaultwhat it controlsread
page_limit16384 pages (1 GiB)linear memory and object stores across every instance on the node. Change it while the node runs with wasm_engine:set_page_limit/1Memory
table_grow_limit16,777,216 entriesthe largest one table may becomeMemory
max_rec_groups100,000distinct recursive type groups stored for the whole node; they are never freedSecurity
max_module_bytes64 MiBthe size of one module's input, checked before it is decodedSecurity
max_module_loads_per_second50new modules the module cache decodes in one second. Past it: {error, {load_rate_exceeded, 50}}Design principles
max_resident_modules256modules the cache holds at once, counting those being decoded. Past it: {error, {too_many_modules, 256}}Design principles
max_resident_module_bytes2 GiBthe memory the cached modules hold together, as stored; function bodies that processes share come on top. Past it: {error, {module_cache_full, Bytes}}Security

Files and WASI

keydefaultwhat it controlsread
require_native_fsfalsetrue refuses every directory grant when the file NIF is not loaded, so a guest gets no file system rather than the pure Erlang oneWASI preview 1
scratch_rootsunsetthe directories for request files, as #{RootId => Dir}. Set, the reaper starts with the application and cleans what a crashed node leftWorker configuration
reaper_options#{}the reaper's limits: jobs, queue, retries, timeoutsWorker configuration
worker_timeout5000 msthe deadline wasm_instance_worker:call/3 uses, and its start function when limits has no timeoutUsing workers

The compiled tier

keydefaultwhat it controlsread
code_cache_dirunsetwhere compiled code is kept across restarts. Unset, the tier compiles again at every startThe compiled tier
compile_max_heap_wordsunset, no ceilingthe most memory one compile may use, in wordsThe compiled tier
compile_budget_heap_wordsunset, no budgetthe most memory all compiles may use together, in words; works only with compile_max_heap_wordsThe compiled tier

Your application's modules

One key belongs to your application rather than wasm, in your .app.src: wasm_modules, the modules scripts/wasm-units.escript builds compiled code for and wasm:preload_app/1 loads. Each is a map:

keyvalue
filethe module, relative to your application's directory, such as "priv/guest.wasm"
functionsoptional: a file of function indexes, one per line; all functions when absent
qualityoptional: full, the default, or baseline

The compiled tier has the steps.

Snapshots

keydefaultwhat it controlsread
snapshot_dirunsetwhere images are kept between restarts. Unset, images live only in memorySnapshots
max_snapshot_bytesinfinitythe memory all snapshot images keep, on the whole nodeSnapshots
max_snapshot_dir_bytes512 MiBthe disk snapshot_dir may holdSnapshots
max_snapshot_stored_bytes256 MiBthe largest image file the runtime reads, as storedwasm_snapshot_file
max_snapshot_inflated_bytes1 GiBthe largest image once decompressedwasm_snapshot_file
max_snapshot_decode_depth64how deeply nested a value in an image file may bewasm_snapshot_file
max_snapshot_decode_nodes16,000,000how many values one image file may holdwasm_snapshot_file

The last four protect the node from a damaged or planted image file. A value that is not a positive integer refuses the read with snapshot_config_invalid.

Internal settings

These exist, but they are not supported API: they may change or go away in any release. Leave them at their defaults.

keywhat it is
compile_retry_secondshow long the compiled tier waits before it asks again for a compile that was lost; 60 s
gc_alloc_threshold, gc_major_ratio, gc_min_major_size, gc_min_major_pagesthe collector's thresholds, described in Garbage collection
compile_budget_wordsan old key, read only to log that it is ignored; use compile_budget_heap_words
heap_hook, keeper_hook, build_hook, wait_claim_hook, poll_wait_cap_msread only by test builds of the runtime

The limits map

Pass these to wasm:instantiate/3 with the other options, or start from a preset. A key you leave out takes the value in the first column.

keyleft outuntrusted()trusted()what it limits
fuelinfinity10,000,000infinitywork: charged at each call and each jump back to the start of a loop. Compiled code does not count it
timeoutnone1000 msinfinitywall-clock time per call, in milliseconds. Only a worker can apply it, so a direct call ignores it; a worker without one uses its own default
max_depth10242568192WebAssembly call depth
max_memory_pagesinfinity256 (16 MiB)infinityevery memory the instance can reach, imported ones included, and its share of the object store
max_host_callsinfinity10,000infinitycalls out through an import, per call
max_heap_wordsnone8,388,608 (64 MiB)nonethe owning process's own heap. A direct call ignores it; a worker applies it

The presets are wasm_limits:untrusted/0 and wasm_limits:trusted/0. A value that cannot mean what it says, such as #{fuel => -1}, is refused with invalid_limits.

A guest that reaches max_memory_pages is not stopped: its memory.grow answers -1, as the specification says, and the guest decides what to do. A Rust or C guest whose allocator gets -1 usually aborts, and the call then fails as the guest made it fail, often #{class := trap, kind := unreachable}. When max_memory_pages refused a grow during that call, the error's ctx has memory_limit => #{max_pages := N, requested := P}: N is the limit and P the size in pages the grow asked a memory to reach. So you can tell a guest that ran out of the memory you gave it from a guest that crashed. A worker merges your limits over untrusted() and adds its own output limits; see Worker configuration. Security says what each limit bounds, and wasm_limits what limits cannot do.

Instantiate options

wasm:instantiate/3 takes the limits above and these options in one map:

keydefaultwhat it doesread
profilenoneplugin or script: sets the compile options below for that kind of workload. An option you set yourself winsThe compiled tier
compilefalsetrue turns on the compiled tier for this instanceThe compiled tier
compile_after32how many calls of the module before its hot functions compileThe compiled tier
compile_qualityfullbaseline compiles about twice as fast and ran about 14% slower before 0.16.0, which made full faster stillThe compiled tier
linknonean instance to share a garbage-collected object store withwasm:instantiate/3
snapshotablefalsetrue makes the instance capturable with wasm:snapshot/1Snapshots
snapshot_hooks#{}what your imports hold, so a capture can check itSnapshots

compile_shards, compile_sync, compile_whole, compile_force and fuse are also read from this map. They exist for tests and measurement, are not supported API, and compile_force makes a failed compile raise. See Design principles.

wasm_component:instantiate/3 passes the same limits to every core module of the component, and reads these options itself:

keydefaultwhat it doesread
loaderload while the application runs, else compileload builds core modules through the module cache; compile builds them inline, outside the load ratewasm_component:instantiate/3
resource_limitinfinitythe most host resource handles live at once, and async calls waiting at once. Past it: a trap, resource_limit_reachedComponent internals
resource_closer, resource_predropnonefunctions the runtime calls when the guest drops a host resourceComponent internals

The WASI hosts take their own options, such as directories, environment and network: see WASI preview 1, WASI 0.2 and WASI 0.3.

Worker options

wasm_instance_worker:start_link/2 takes four:

keydefaultwhat it does
imports#{}the imports of the instance
limits#{}the limits map above; timeout is the deadline of the start function
isolationfreshfresh builds a new instance for every request; reuse keeps one
namenonea label that info/1 gives back; the worker is not registered under it

wasm_script_worker has more, per request and per worker: Worker configuration lists each one with its default.

Read this next

Worker configuration for the worker settings, Security for what the limits do not cover, and Tuning once you have measured.