Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Production operations

Pyroxide removes a separate broker and worker service, but it does not remove operational decisions. Because the engine lives inside the application, capacity, shutdown, and native-code risk belong in the application’s design.

Start with a canary using representative payloads and failure cases.

Configuration

Set environment variables before importing pyroxide. Runtime engine settings are process-global unless documented as scoped.

VariableMeaningDefault
PYROXIDE_WORKERSIn-process worker threadslogical CPU count
PYROXIDE_QUEUE_CAPACITYPending submissions across both queues10000
PYROXIDE_QUEUE_TIMEOUT_MSAdmission wait; 0 rejects immediately1000
PYROXIDE_MAX_PROCESSESConcurrent isolated coordinators/processesmin(logical CPUs, 8)
PYROXIDE_SHM_THRESHOLDSerialized frame size that selects shared memory1048576
PYROXIDE_MAX_IPC_FRAME_BYTESMaximum accepted IPC frame67108864
PYROXIDE_MAX_NATIVE_OUTPUT_BYTESMaximum copied native byte-buffer result67108864
PYROXIDE_MAX_TASKS_PER_WORKERIsolated tasks before recycle; 0 disables100
PYROXIDE_WORKER_STARTUP_TIMEOUT_SECIsolated worker startup timeout5
PYROXIDE_IDLE_TIMEOUT_SECIdle time before eligible worker reaping60
PYROXIDE_MIN_WORKERSExisting idle workers protected from reaping0
PYROXIDE_WASM_MEMORY_LIMIT_BYTESPer-invocation WASM memory limit104857600
PYROXIDE_WASM_TIMEOUT_MSWASM epoch deadline1000
PYROXIDE_WASM_TICK_MSEpoch increment interval10
PYROXIDE_CACHE_DIRNative compiler cache~/.pyroxide/cache
PYROXIDE_COMPILER_TIMEOUT_SECPer native compiler command timeout300
PYROXIDE_DISABLE_COMPILATIONReject runtime source compilationdisabled

Invalid integer engine settings fail during import instead of silently selecting an unsafe value. PYROXIDE_MIN_WORKERS cannot exceed PYROXIDE_MAX_PROCESSES. WASM memory cannot exceed 2**31 - 1 bytes.

Task-count recycling replaces an isolated worker synchronously, so the task that crosses the limit pays process startup cost. Latency-sensitive services can set PYROXIDE_MAX_TASKS_PER_WORKER=0 after validating that their workload does not accumulate worker state or memory. Keep recycling enabled when bounding long-lived worker growth matters more than that occasional pause.

Backpressure

Choose queue capacity from the maximum memory you can retain while work waits, not only desired throughput. Submission raises BufferError after the queue timeout. Batch admission requires room for the whole batch.

Application code should decide whether to retry, shed load, or return a service error. Unbounded retries defeat backpressure.

Metrics

import pyroxide

metrics = pyroxide.stats()
KeyMeaning
worker_countConfigured in-process worker threads
max_processesMaximum concurrent isolated workers
queue_capacityPending admission capacity
queued_tasksAccepted tasks not yet taken by a worker
running_tasksTasks currently executing
active_tasksTask records still retained by handles
submitted_tasksLifetime accepted submissions
rejected_tasksLifetime capacity/channel rejections
completed_tasksLifetime successful completions
failed_tasksLifetime failed completions
cancelled_tasksLifetime effective cancellations

Fields are read independently. During concurrent activity, stats() is an approximate cross-field snapshot and may combine values from nearby moments; use quiescent readings for drain or leak checks. If you require a linearizable cross-field snapshot, open an issue with your use case.

Counters are process-local and reset on restart. Export them with labels supplied by your application; Pyroxide does not run a metrics server.

Shutdown

pyroxide.shutdown(wait=True, cancel_pending=False)
  • The default stops admission, drains accepted work, and joins workers.
  • cancel_pending=True cancels work that has not started. Running in-process work still completes; running isolated work is not automatically user-cancelled.
  • wait=False initiates shutdown and returns promptly.
  • A Pyroxide worker task cannot call shutdown(wait=True) because shutdown would wait for that task. Use wait=False or shut down from another thread.
  • Shutdown is idempotent and irreversible in the process.

Set an application-level termination grace period long enough for the largest non-interruptible in-process task, or isolate work that must be forcibly stopped.

Process models

Initialize Pyroxide after process managers fork or preload application code. A broker or WebAssembly runtime inherited across fork() raises ForkSafetyError. Spawn-based child processes can initialize their own runtime normally.

Do not recursively submit isolated Pyroxide tasks from an isolated worker. The worker executes its decorated Python callable directly to avoid a nested broker.

Security checklist

  • Prefer precompiled WASM and native artifacts with provenance checks.
  • Set PYROXIDE_DISABLE_COMPILATION=1 when runtime compilation is unused.
  • Treat native libraries as part of the trusted computing base.
  • Do not describe process isolation as a permission sandbox.
  • Bound request size below the IPC and WASM limits at the application boundary.
  • Run the host service with least filesystem and network privilege.
  • Track Pyroxide, Wasmtime, PyO3, and Rust security advisories.

See SECURITY.md for reporting and support policy.