{"id":19778321,"url":"https://github.com/npkgz/cluster-magic","last_synced_at":"2026-05-18T15:02:16.532Z","repository":{"id":57200981,"uuid":"119561747","full_name":"npkgz/cluster-magic","owner":"npkgz","description":"run multi-threaded node.js network applications using the native cluster module","archived":false,"fork":false,"pushed_at":"2023-07-19T02:38:47.000Z","size":72,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T12:22:43.378Z","etag":null,"topics":["cluster","hot-reload","library","module","nodejs","zero-downtime"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cluster-magic","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npkgz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-30T16:20:01.000Z","updated_at":"2023-11-29T16:17:34.000Z","dependencies_parsed_at":"2024-11-12T05:39:22.796Z","dependency_job_id":null,"html_url":"https://github.com/npkgz/cluster-magic","commit_stats":null,"previous_names":["andidittrich/node.cluster-magic"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/npkgz/cluster-magic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Fcluster-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Fcluster-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Fcluster-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Fcluster-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npkgz","download_url":"https://codeload.github.com/npkgz/cluster-magic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Fcluster-magic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263074504,"owners_count":23409776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cluster","hot-reload","library","module","nodejs","zero-downtime"],"created_at":"2024-11-12T05:28:54.721Z","updated_at":"2026-05-18T15:02:11.280Z","avatar_url":"https://github.com/npkgz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cluster-magic\n===========================================\n\nrun multi-threaded node.js network applications using the native [cluster module](https://nodejs.org/api/cluster.html)\n\n## Features ##\n\n* Run network applications within multiple processes multiplexed by node.js\n* Easy to use, configless\n* Standalone, no external process managers required\n* Respawn dead/failed workers\n* Gracefull application shutdown via `sigterm`\n* Hot-Reload/Hot-Restart via `sighup`\n* Delayed restart of failed processes to avoid infinite restart loops\n\n## Install ##\n\n```bash\n$ npm install cluster-magic --save\n$ yarn add cluster-magic\n```\n\n## Usage ##\n\nA working snippet is available in the [examples directory](examples/). Just run `node examples/startup.js`\n\n**File: startup.js**\n\nInitializes the cluster application\n\n```js\nconst _cluster = require('cluster-magic');\nconst _app = require('./application.js');\n\n// start the clustered app (8 workers)\n_cluster.init(_app, {\n    numWorkers: 8\n});\n```\n\n**File: application.js**\n\nYour socket based application which should be multiplexed\n\n```js\nconst net = require('net');\n\nfunction startup(){\n    const server = net.createServer((socket) =\u003e {\n        // connections never end\n    });\n    \n    server.listen(8000);\n}\n\nmodule.exports = {\n    // init hook\n    init: startup\n};\n```\n\n## Hot-Restart / Hot-Reload ##\n\nTo hot-restart (zero downtime) an application, just send a **SIGHUP** to the master process.\nThis spawns new workers and disconnects all current workers from the **cluster-proxy**\n\n**Example**\n\n```sh\n# send SIGHUP to process 12345\nkill -HUP 12345\n```\n\n## Signals ##\n\n* **SIGHUP** Restart workers\n* **SIGTERM** Gracefull application shutdown\n* **SIGINT** Gracefull application shutdown\n\n## Delayed Restarts ##\n\ncluster-magic comes with as simple delayed-restart policy which suppresses infinite restart loops.\n\n* In case a process dies, an internal counter will be incremented. \n* If a threshold of **10** is reached the process restart is delayed by `counter*200ms` to avoid infinite restart loops on internal application errors.\n  Well..this is may not what you expect from a \"clustered application\" but such an error requires that a **manual fix** will take place by the operations team (_logger.alert event is triggerd which **SHOULD** be observed)\n* The counter is decremented by 1 once per minute.\n\n## Environment ##\n\nTo specify the number of workers you can easily pass the environment variable `NUM_WORKERS` to the nodejs process. Default is set to `num_cpus*2`\n\n\n## License ##\ncluster-magic is OpenSource and licensed under the Terms of [The MIT License (X11)](http://opensource.org/licenses/MIT) - your're welcome to contribute","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpkgz%2Fcluster-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpkgz%2Fcluster-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpkgz%2Fcluster-magic/lists"}