Skip to main content

Cluster Mode

A single Swift process uses one CPU core efficiently. To use all available cores, Prism can spawn multiple worker processes — each running its own copy of the server. PrismClusterManager handles spawning, monitoring, and restarting workers.

Quick Start

Multi-Process Server

Cluster Configuration

Configuration Options

Detecting Primary vs Worker

Process Role Detection
The primary process sets PRISM_WORKER=true and PRISM_WORKER_ID=N in the environment of each child process.

Managing Workers

Worker Management

Worker Status

Auto-Restart

When restartOnCrash is enabled, the manager monitors workers every second. If a worker exits with a non-zero status, it’s automatically replaced:

Practical Example

Production Cluster
All workers share the same port. On macOS, Network.framework handles port sharing via SO_REUSEPORT. Each incoming connection is distributed to one worker.
In containerized environments (Docker, Kubernetes), you often don’t need cluster mode — the orchestrator handles scaling by running multiple container instances. Use cluster mode when running on bare metal or a single VM where you want to saturate all CPU cores.