Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 2.17 KB

cluster.md

File metadata and controls

60 lines (43 loc) · 2.17 KB

Clustering

OpenTMI uses Node's Cluster module to manage multiple node worker processes. Distributing requests to multiple workers allows OpenTMI to use all the cores available on the host machine.

There is admin API to manage clusters and current states.

To start OpenTMI in cluster mode you need to run the npm script cluster

npm run cluster

Master startup procedure

Master process startup consists of two parts, subscribing to event sources and spawning workers.

subscribed events

Event name Reaction
masterStatus Emits event containing current machine/worker status to all the workers.
workerRestartNeeded Starts worker update procedure.
systemRestartNeeded Marks that the server needs a restart.
* Broadcasted messages are logged.

Worker spawning procedure

OpenTMI starts a worker process for each cpu core available on the host machine.

Workers are started one by one serially.

-- clustering startup image --

Worker update procedure

It is possible to trigger an update that reloads all workers without any downtime.

There are two ways to trigger the update procedure, either manually via the API or automatically by starting the server with --auto-reload command line parameter. Auto reload restarts all the workers whenever a change is detected in the app directory of the server.

npm run cluster --auto-reload

Changes to source files that the master process is using do not trigger an automatic restart as those changes will not become visible unless the whole server is restarted.

The update is a rolling restart that kills and then restarts workers one by one, roughly in a similar manner as seen in the startup procedure.

-- clustering update image --

Worker crashes

When a worker crashes OpenTMI automatically attempts to spawn a new worker to replace it.