{"id":18851595,"url":"https://github.com/eviltik/evilcluster","last_synced_at":"2026-02-03T22:30:18.643Z","repository":{"id":26849372,"uuid":"110416639","full_name":"eviltik/evilcluster","owner":"eviltik","description":"NodeJS Spawn/Fork Cluster Manager with events manager inside","archived":false,"fork":false,"pushed_at":"2023-01-07T10:41:01.000Z","size":333,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T21:35:09.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/eviltik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-12T08:25:46.000Z","updated_at":"2024-06-14T04:31:07.000Z","dependencies_parsed_at":"2023-01-14T05:24:03.978Z","dependency_job_id":null,"html_url":"https://github.com/eviltik/evilcluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eviltik%2Fevilcluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eviltik%2Fevilcluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eviltik%2Fevilcluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eviltik%2Fevilcluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eviltik","download_url":"https://codeload.github.com/eviltik/evilcluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239788487,"owners_count":19697210,"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":[],"created_at":"2024-11-08T03:35:22.624Z","updated_at":"2026-02-03T22:30:18.605Z","avatar_url":"https://github.com/eviltik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# evilcluster\n\n![Node.js CI](https://github.com/eviltik/evilcluster/workflows/Node.js%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/evilcluster.svg)](https://badge.fury.io/js/evilcluster)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n[![Dependency Status](https://david-dm.org/eviltik/evilcluster.svg)](https://david-dm.org/eviltik/evilcluster)\n\nMonolithic approach of nodejs clustering.\n\n## What ? why ?\n\nSometime, you can make the choice to **not have** a microservice architecture :\n\n* when you \"pkg\" (https://github.com/zeit/pkg) your nodejs application\n* when the logic of microservices is not \"appropriated\" ( ... )\n* when you want to have only one \"Windows Service\" (see https://nssm.cc/)\nwith all your modules inside\n\n\n## Best practice microservice design\n\nBelow a classical design of microservices running on the same box.\n\nUsually, master processes and forks talk each other using IPC (process.send).\nOnly a boolean (cluster.isMaster) is available to handle code running in\nforks vs master process.\n\nProcess 1 can not speak natively with process 2 unless if you implement it,\na kind of gateway between them (webservices, websockets, tcp, redis, ...).\nThis is a best practice because of scalability and deployment facility.\n\n\n```\n\n  process 1\n      │\n      │\n cluster.fork()\n      │\n      ├──── fork 1\n      │\n cluster.fork()\n      │\n      └──── fork n\n\n\n  process 2\n      │\n      │\n cluster.fork()\n      │\n      ├──── fork 1\n      │\n cluster.fork()\n      │\n      └──── fork n\n\n```\n\n\n## Monolithic design approach\n\nNow, if you **NEED** to **NOT** have many different standalone processes,\nyou are thinking about a monolithic architecture, and you will have to\nfind a way to monitor spawned processes, speak between master/spawns/forks\nprocesses, handle logs, ...\n\nThis (poc) module aims at a pseudo monolithic architecture. The main process **SPAWN** workers.\nThen spawned workers **MAY FORKS**.\n\nSo:\n* cluster.isMaster is true when it's the main process\n* cluster.isSpawn is true when it's a spawned worker\n* cluster.isFork is true when it's a fork of a spawned worker\n\n```\n    main process\n          │\n          │\n child_process.spawn()\n          │\n          ├───────── worker 1\n          │             │\n          │        cluster.fork()\n          │             │\n          │             ├──── fork 1\n          │             │\n          │        cluster.fork()\n          │             │\n          │             └──── fork n\n          │\n child_process.spawn()\n          │\n          ├───────── worker 2\n          │             │\n          │        cluster.fork()\n          │             │\n          │             ├──── fork 1\n          │             │\n          │        cluster.fork()\n          │             │\n          │             └──── fork n\n  child_process.spawn()\n          │\n          ├─────── worker 3 (no fork wanted)\n          ¦\n          ¦\n\n```\n\n\nReal example:\n\n```\n        my app\n          │\n          │\n          ├── webserverFrontend\n          │          │\n          │          ├──── fork 1\n          │          │\n          │          └──── fork n\n          │\n          ├── webserverApi\n          │          │\n          │          ├──── fork 1\n          │          │\n          │          └──── fork n\n          │\n          ├── inMemoryDatastore (only one master process)\n          │\n          └── backgroundTaskManager ...\n\n```\n\n\n## Inter-processes communication\n\n(DOC/TODO)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feviltik%2Fevilcluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feviltik%2Fevilcluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feviltik%2Fevilcluster/lists"}