
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
cluster-rolling-restart
Advanced tools
A simple way to turn express into a clustered server with support for rolling restart and cache synchronization.
A simple way to turn express into a clustered server with support for rolling restart and cache synchronization.
npm install cluster-rolling-restart
const cluster = require("cluster-rolling-restart");
const express = require("express");
const app = express();
app.get("/", (req, res) => res.send(`I'm pid ${process.pid}`));
app.get("/reload", (req, res) => process.send({ cmd: "reload" }));
app.get("/reload-reset", (req, res) => process.send({ cmd: "reload-reset" }));
cluster.startCluster(() => app.listen(8080));
> sysctl -n hw.ncpu
8
> start
> node server.js
master starting 8 workers 🌎
worker up 77653
worker up 77655
worker up 77652
worker up 77654
worker up 77658
worker up 77657
worker up 77656
worker up 77659
> curl http://localhost:8080/reload
reload requested 👍
worker down 77659
worker up 77662
worker down 77658
worker up 77663
worker down 77657
worker up 77664
worker down 77656
worker up 77665
worker down 77655
worker up 77666
worker down 77654
worker up 77667
worker down 77653
worker up 77668
worker down 77652
worker up 77669
reload complete ✅
To use cache synchronization, you send the data you want to cache to the master process. You then listen for events from the master, and when a saveCommand
event arrives, you update your cache with the data in the event.
Send data to save to master...
async save(id, data) {
if (clusterEnabled) {
process.send({
cmd: "saveBroadcast",
pid: process.pid,
id,
data,
name: this.name,
});
}
return this.dataSource.set(id, data).get(id);
}
Listen for save event and update cache...
process.on("message", ({ cmd, id, pid, data, name }) => {
if (cmd && id && data && process.pid !== pid) {
if (cmd === "saveCommand") {
const ds = DataSourceFactory.getDataSource(name);
ds.clusterSave(id, ModelFactory.loadModel(observer, ds, data, name));
return;
}
if (cmd === "deleteCommand") {
const ds = DataSourceFactory.getDataSource(name);
ds.clusterDelete(id);
return;
}
}
});
FAQs
A simple way to turn express into a clustered server with support for rolling restart and cache synchronization.
The npm package cluster-rolling-restart receives a total of 27 weekly downloads. As such, cluster-rolling-restart popularity was classified as not popular.
We found that cluster-rolling-restart demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.