{"id":20485266,"url":"https://github.com/runnable/cluster-man","last_synced_at":"2025-04-13T14:53:06.186Z","repository":{"id":30087907,"uuid":"33637546","full_name":"Runnable/cluster-man","owner":"Runnable","description":"Extendable and easy-to-use node cluster management.","archived":false,"fork":false,"pushed_at":"2016-07-15T00:35:53.000Z","size":409,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-11T04:18:08.422Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Runnable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-08T23:22:11.000Z","updated_at":"2016-01-13T23:14:22.000Z","dependencies_parsed_at":"2022-08-28T18:24:54.422Z","dependency_job_id":null,"html_url":"https://github.com/Runnable/cluster-man","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fcluster-man","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fcluster-man/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fcluster-man/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fcluster-man/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Runnable","download_url":"https://codeload.github.com/Runnable/cluster-man/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339226,"owners_count":21087215,"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-15T16:29:05.995Z","updated_at":"2025-04-13T14:53:06.167Z","avatar_url":"https://github.com/Runnable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cluster-man\n\n![Build Status](https://travis-ci.org/Runnable/cluster-man.svg?branch=master)\n![Dependency Status](https://david-dm.org/Runnable/cluster-man.svg)\n![devDependency Status](https://david-dm.org/Runnable/cluster-man/dev-status.svg)\n\n[![NPM](https://nodei.co/npm/cluster-man.png?compact=true)](https://nodei.co/npm/cluster-man)\n\nExtendable and easy-to-use node cluster management.\n\n## Basic Usage\n\n**Via Environment Configuration**\n\nBy Default cluster-man configure itself via `process.env` by using the following\nvariables:\n\n- `process.env.CLUSTER_WORKERS` (Integer) - Number of workers to fork from the\n  master process when the cluster is started.\n- `process.env.CLUSTER_DEBUG` (String) - Prefix for cluster event logging via\n  [debug](https://www.npmjs.com/package/debug)\n\nHere's an example of how to use cluster man with as little configuration as\npossible:\n\n```js\n// Load your environment\nrequire('loadenv')();\n\n// Grab a copy of the cluster manager class\nvar ClusterManager = require('cluster-man');\n\n// Instantiate a new manager using environment variable configuration\nvar manager = new ClusterManager(function () {\n  // This is the closure called after worker processes are forked\n});\n\n// Finally, start your cluster!\nmanager.start();\n```\n\n**Via Custom Options**\n\nDevelopers can also instantiate a `ClusterManager` using options to configure\nhow the manager operates, like so:\n\n```js\nvar ClusterManager = require('cluster-man');\nvar manager = new ClusterManager({\n  // Worker processes execute this on process start:\n  worker: function () {\n    // ...\n  },\n\n  // Master process executes this when you call `manager.start()`:\n  master: function () {\n    // ...\n  },\n\n  // Explicitly tell it the number of workers to fork:\n  numWorkers: 16,\n\n  // Tell it not to kill the master process on an un-handled error\n  // (sometimes useful, not recommended)\n  killOnError: false,\n\n  // Perform some action before the master process exits due to an error\n  beforeExit: function(err, done) {\n    // Do what you need to before the process is killed...\n\n    // Then call the `done` function\n    done();\n  }\n});\n\n// Start the cluster!\nmanager.start();\n```\n\n## API Documentation\n\nFor the full API documentation, please visit http://runnable.github.io/cluster-man/\n\n## Extending ClusterManager\n\nWhile we think that the basic behaviors encapsulated by cluster-man represent a\nreasonable approach to handling clustering, it stands to reason that there will\nbe times when a developer needs to handle clustering in a specific way for their\napplication.\n\nTo aid such specialized behaviors the `ClusterManager` class was designed to be\nextendable via prototypal inheritance. Furthermore, instances expose the node\n`cluster` directly so additional eventing can easily be added.\n\n\n**Example: Adding additional cluster event listeners**\n```js\nvar app = require('./lib/app.js');\nvar ClusterManager = require('cluster-man');\n\n// Create a new cluster manager for your application\nvar manager = new ClusterManager(function () {\n  app.start();\n});\n\n// Spawn new workers when others die...\nmanager.cluster.on('exit', function (worker, code, signal) {\n  var delta = manager.options.numWorkers - manager.workers.length;\n  for (var i = 0; i \u003c delta; i++) {\n    this.createWorker();\n  }\n});\n\n// Start the cluster\nmanager.start();\n```\n\n**Example: Worker Start/Stop Monitoring**\n\nHere's an example of how to extend `ClusterManager` to log worker start and stop\ninformation with `monitor-dog`:\n\n```js\nvar ClusterManager = require('cluster-man');\nvar monitor = require('monitor-dog');\nvar inherits = require('util').inherits;\nvar app = require('./lib/app.js');\n\nfunction AppManager() {\n  ClusterManager.apply(this, arguments);\n}\ninherits(AppManager, ClusterManager);\n\n// Override `_startWorker` since this manager only works for this particular app\nAppManager.prototype._startWorker = function () {\n  app.start();\n};\n\n// Increment a `workers` key in datadog when a worker is created\nAppManager.prototype.createWorker = function() {\n  var worker = ClusterManager.prototype.createWorker.apply(this, arguments);\n  monitor.increment('workers');\n  return worker;\n};\n\n// Decrement the `workers` key when a worker dies\nAppManager.prototype.exit = function (worker, code, signal) {\n  ClusterManager.prototype.exit.call(this, worker, code, signal);\n  monitor.increment('workers', -1);\n};\n\n// Start the custom cluster\nvar manager = new AppManager();\nmanager.start();\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunnable%2Fcluster-man","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunnable%2Fcluster-man","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunnable%2Fcluster-man/lists"}