TotalFusionFOR TOTAL.JS AND NODE.JS

Reference

Options#

The options of fusion.configure({ python: {...} }), fusion.configure({ rust: {...} }) and fusion.configure({ go: {...} }) and fusion.configure({ wasm: {...} }):

OptionRuntimeDefault
workersboth1Processes in the pool. They start on demand.
concurrencyboth1Calls a worker runs at the same time.
timeoutboth30000Milliseconds per call (in a stream, without progress). 0 disables it.
maxQueueboth1000Calls waiting for a worker before QUEUE_FULL.
startTimeoutboth30000Milliseconds a worker has to become ready (raise it for big models).
cancelGraceboth2000Milliseconds a worker has to cancel a call before it is killed.
maxCallsbothneverReplace a worker after this many calls.
maxMemorybothno limitReplace a worker that uses more: bytes, '512mb', '1.5gb'.
healthIntervalboth10000Ping idle workers every N ms. 0 disables it.
healthTimeoutboth10000Milliseconds a worker has to answer a ping.
forwardStderrbothtrueShow what the workers write to their error output.
envbothprocess.envThe environment of the workers.
pathPython./pythonThe directory with your components.
pythonPythonThe interpreter command (wins over venv).
venvPythonA virtual environment whose interpreter is used.
preloadPythonnoneModules to import (running their @startup) before a worker is ready.
requirementsPythonrequirements.txtThe file that doctor checks.
binaryRust, GoThe path of the worker you built.
moduleWebAssemblyThe path of the .wasm file. See WebAssembly.
argsRust, GononeArguments for the worker.
cwdRust, Go, WebAssemblyfolder of the binary or moduleWorking directory of the worker.
shadowCopyRust, Gotrue on WindowsRun the worker from a copy, see Rust and Go.

Options of a single call (fusion.python(fn, args, options)): timeout, signal (an AbortSignal), idempotent and retries (see Retrying), and for a stream highWaterMark.

The methods: fusion.python(fn, args, options), fusion.rust(...) and fusion.go(...) and fusion.wasm(...) (or fusion.call(runtime, fn, args, options)), fusion.stream(...) and fusion.python.stream(...) / fusion.rust.stream(...) / fusion.go.stream(...) / fusion.wasm.stream(...), fusion.describe(runtime), fusion.warmup(runtime), fusion.watch(runtime), fusion.doctor(runtime), fusion.register(options) and fusion.sse($, stream) for Total.js, fusion.stats() and fusion.shutdown().

Per-call options#

fusion.python(fn, args, options), fusion.rust(...), fusion.go(...), fusion.wasm(...) and fusion.call(runtime, fn, args, options) accept:

Option
timeoutMilliseconds for this call. In a stream, the longest time without progress. 0 disables it.
signalAn AbortSignal: aborting it cancels the call.
idempotentThe call can be repeated on another worker if its worker dies. See Retrying.
retriesHow many times (default 1 when idempotent).
highWaterMarkIn a stream, how many chunks the worker may run ahead of the consumer (default 16).

Methods#

fusion.configure({ python: {...}, rust: {...}, go: {...}, wasm: {...} })Sets the options. It must run before the first call.
fusion.python(fn, args, options) / fusion.rust(...) / fusion.go(...) / fusion.wasm(...)Calls a function. Returns a promise.
fusion.call(runtime, fn, args, options)The same, with the runtime as an argument.
fusion.stream(runtime, fn, args, options) / fusion.python.stream(...) / fusion.rust.stream(...) / fusion.go.stream(...) / fusion.wasm.stream(...)Calls a function that sends chunks. Returns an async iterable with .toArray() and .cancel(). See Streaming.
fusion.describe(runtime)The contracts of the functions, read without calling them. A Python component is parsed, not imported; a Rust or Go binary is started with --describe; a WebAssembly module is started by its host.
fusion.warmup(runtime)Starts all the workers and waits until they are ready.
fusion.watch(runtime, options)Replaces the workers when the code changes. See Development.
fusion.doctor(runtime)Checks the environment. Returns { ok, checks, text }.
fusion.register(options)Total.js: registers the functions with a contract as actions. See Total.js 5.
fusion.sse($, stream)Total.js: sends a stream to the browser as Server-Sent Events.
fusion.flow(kind, runtime)Total.js Flow: the function make of a component (call, stream, events or stats). The components of Flow use it.
fusion.stats()What every pool is doing. See Working with the workers.
fusion.on(event, fn)The events of the workers. See Observing the workers.
fusion.shutdown()Stops the workers. They also end by themselves if the process exits.

The command#

npx totalfusion doctor [--runtime python|rust|go|wasm] [--path DIR] [--venv DIR] [--python COMMAND]
                       [--requirements FILE] [--preload a,b] [--binary FILE] [--module FILE] [--max-memory 2gb] [--json]

It exits with 0 when everything is in order (warnings are advice), 1 when something has to be fixed and 2 for a wrong usage.

Error codes#

See Errors and cancellation.

Edit this page on GitHub