Rammerhead includes built-in multi-threading support through Node.js’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
cluster module and the sticky-session-custom package. When enabled, a master process accepts connections and routes each request to a worker process, distributing load across CPU cores while ensuring every request belonging to a session lands on the same worker.
Enabling workers
Two options inconfig.js control multi-threading:
enableWorkers is automatically false on single-core machines so that development environments do not incur the overhead of the cluster module. On a production server with multiple cores, it is true by default.
To override the defaults in your root config.js:
Why sticky sessions matter
Each Rammerhead session is stored in memory on the worker that created it. If a second request for the same session is sent to a different worker, that worker has no knowledge of the session and will reject or mishandle the request. Sticky session routing ensures all requests for a given session always reach the same worker.How request routing works
The master process usessticky-session-custom to route incoming connections. Before a connection is handed off, the master reads the raw HTTP request bytes and extracts the session ID. It then hashes the session ID to a consistent worker index.
The extraction logic is implemented in generatePrehashArray inside src/server/index.js:
- URL path — for proxied page requests in the form
/<sessionId>/<encoded-url> - Query parameters — for management endpoints such as
/editsession?id=<sessionId> Refererheader — for sub-resources (images, scripts) fetched by the browser where the URL itself does not contain the session ID
rammerhead.js), a single space character is used as the hash input, distributing these requests round-robin across workers.
sticky-session-custom converts the returned character-code array into a consistent hash and maps it to a worker, ensuring repeatability.
Stale session cleanup
Session file cleanup (deleting sessions that have not been used for three days) only runs on the master process. Worker processes havestaleCleanupOptions set to null to avoid multiple workers competing to delete the same files:
fileCacheSessionConfig.staleCleanupOptions is respected exactly once, by the master.
The dontListen option
When enableWorkers is true, the RammerheadProxy constructor receives dontListen: true. This prevents the proxy from calling server.listen() itself. Instead, sticky-session-custom takes ownership of the socket binding and hands off pre-accepted connections to the correct worker:
Dual-port vs. single-port configuration
- Dual-port (default)
- Single-port
When Both load balancers use the same
crossDomainPort is set, sticky-session-custom creates two separate load balancers — one for the main port and one for the cross-domain port:generatePrehashArray function, so a request on the cross-domain port for a given session routes to the same worker as the main-port requests for that session.Recommended worker count
Setworkers to os.cpus().length (the default). This matches one worker per logical CPU, keeping context-switching low: