Worker configuration

View Source

This page lists every setting the workers take, with its default and what it limits. Look here when a guide names a setting, and before you go to production: you can only change a default that you know about.

Words used below: the guardian is the process that owns one request's deadline and files; the reaper is the one process per node that cleans up after requests; an image is a saved copy of a guest after start-up, which each request restores. Worker internals describes them.

Per request, in the limits map

The limits map you pass to wasm_script_worker:start_link/2 is merged over wasm_limits:untrusted/0. So every limit of that preset still applies, unless you change it:

settingdefaultwhat it limits
timeout5 sone request, wall clock, enforced by the guardian
max_output_bytes1 MiBstdout and stderr, each separately; also accepts #{stdout := N, stderr := M}
max_result_bytes1 MiBthe dedicated result channel
max_combined_bytes1 MiBstdout and the result together, on script_v1.combined, where they share one descriptor
max_request_bytes1 MiBthe source plus the encoded context
max_staged_bytes8 MiBeverything the adapter stages, across all mounts
max_staged_files64how many files it stages

An interpreter needs several of these raised. Raise them yourself: an adapter never raises one for you. Python lists the four that CPython needs, with the measured values.

max_heap_words in a limits map is applied by the process that owns the instance, when it starts the request's runner (the process that runs the request). A direct wasm:call/3 does not apply it, even if you pass the key.

Per worker, in the options map

settingdefaultwhat it controls
rootscratchwhich of the reaper's roots the worker's request directories go under
trustedfalsewhether a mode => write mount is allowed at all
capture_timeout60 sone snapshot capture and its hooks, at start_link/2, and nothing before it. CPython needs about 90 s and so must raise it
runner_min_heap_wordsthe adapter'sa heap floor for each request's runner: 200,000 words for wasm_lua and wasm_javascript, 1,500,000 for wasm_python on the compiled tier and 1,000,000 on the interpreter, none for an adapter without defaults/1. 0 turns it off; see How a heap floor works
capture_min_heap_wordsthe adapter'sthe same, for the process that captures the snapshot. No shipped adapter sets one; see How a heap floor works
restore_aheadfalserestore the next request's instance while the worker waits; see Restore the next instance ahead. Needs a snapshot capability and imports that are all functions. Each idle worker holds one restored instance: its page table (a list of the image's pages it reads), not a copy of the image
compiledfalsetrue runs requests in the compiled tier: it sets fuel => infinity, compile => true, compile_after => 1 and compile_quality => baseline under your own limits. Only the deadline stops a runaway; see Hosting scripting languages

start_link/2,3 refuses to start in these cases:

  • a root the reaper does not have: {error, {unknown_root, Root, Known}};
  • compiled => true with a finite fuel in limits: {error, {bad_option, compiled, #{fuel => N}}};

One image for a pool

Workers started with the same adapter and equal options share one image: a worker whose artifact gives the same store key as a live worker's holds that worker's image instead of loading or capturing its own. Workers that start while the first one loads or captures wait for it, at most capture_timeout and 30 seconds, then capture their own. The image is freed with the last worker that holds it. See Run a pool from one image.

Per node, for the reaper

The reaper cleans up after each request, once the request has been answered. Configure it in the wasm application environment:

settingdefaultwhat it controls
scratch_rootsunsetthe directories for request files, as #{RootId => Dir}. If set, the reaper starts with the application and cleans up what a crashed node left. If unset, it uses a directory that only this node uses, removed at a clean shutdown. Only one node may use each directory
reaper_options#{}the settings below, as a map; an unknown key refuses the start

Inside reaper_options:

settingdefaultwhat it limits
max_cleanup_jobs8cleanup jobs running at once
cleanup_queue_len256jobs waiting. With max_cleanup_jobs, this sets how many requests the reaper accepts (admission)
cleanup_retries3attempts after the first failure
cleanup_backoff1 s, 4 s, 16 sbetween those attempts
cleanup_timeout30 sone callback, not one job
cleanup_job_deadline120 sthe whole job, every callback and action together
max_cleanup_actions64actions an adapter may register per request
max_cleanup_operations_per_request256cleanup operations (register, withdraw, transfer) one request may run

The last three are separate limits on purpose. Without them, a job with eight actions and a cleanup/1 could use nine callback timeouts, and an adapter stuck in a loop could register actions until the reaper ran out of memory.

When the reaper holds max_cleanup_jobs + cleanup_queue_len requests, submit returns {error, #{kind => cleanup_saturated}}. You can retry it later. This is better than a leak you cannot see. wasm_script_worker:cleanup_stats/0 shows how close you are to the limit.

Node-wide

The other settings of the wasm application environment, such as worker_timeout, snapshot_dir and its limits, code_cache_dir and page_limit, are in Configuration, each with its default and the page that explains it.

Read this next

Tuning.