{"comment":{"created_at":"2011-10-17T04:12:35Z","body":"maybe a node-app binary that either takes 1 arg of a package.json, or else scans CWD for package.json\r\n\r\nthen have a cluster section that defines things such as workers like:\r\n\r\n\"cluster:\" {\r\n  \"master\": \"master.js\",\r\n  \"workers: {\r\n     \"worker1.js\": \"\" // default to # of CPUs\r\n     \"worker2.js\": 2, // 2 workers\r\n  }\r\n}\r\n\r\nI think having a new binary for things like cluster could help flush out an overall \"app\" feel to the binary, and the default node binary be the standard \"no magic\" expectation.\r\n\r\n","updated_at":"2011-10-17T04:12:35Z","url":"https://api.github.com/repos/joyent/node/issues/comments/2424875","id":2424875,"user":{"gravatar_id":"c6abf37c059c2eb548319c49bf5125ea","avatar_url":"https://secure.gravatar.com/avatar/c6abf37c059c2eb548319c49bf5125ea?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/aikar","id":58008,"login":"aikar"}},"action":"created","issue":{"number":1879,"created_at":"2011-10-13T14:09:45Z","pull_request":{"diff_url":"https://github.com/joyent/node/pull/1879.diff","patch_url":"https://github.com/joyent/node/pull/1879.patch","html_url":"https://github.com/joyent/node/pull/1879"},"body":"\r\n- improved extensibility\r\n- added -n, --workers <n>\r\n- added -r, --require <file>\r\n- added worker incr / decr functionality\r\n- added worker removal functionality\r\n- refactored / exposed worker spawning\r\n- delegate arbitrary messages\r\n- message master when listening\r\n \r\nThe main goal of this commit is to make cluster.js\r\nextensible. not to make assumptions with re-spawning\r\nlogic etc, but to facilitate it. logging and other \r\nrelated tasks are then delegated as well.\r\n\r\nTo \"plugin\" in master logic you use `--require`, as `$ node cluster`\r\nwill not exec the script for the master process. ex:\r\n\r\n      $ node cluster app\r\n\r\nvs:\r\n\r\n      $ node cluster -r master app\r\n\r\nwhere _./master.js_ contains `process.on()` event\r\nlisteners for logging, logic for re-spawning etc.\r\n\r\nI'm not 100% sold on `--require`, but it would be more\r\nabstract than cluster-specific module loading etc.\r\nThe one benefit of doing something cluster-specific,\r\nis that you could truly encapsulate cluster \"plugins\"\r\nwhich may contain both master and worker logic. For example\r\nsuppose you have a plugin _./stats.js_ which may aggregate/relay/display\r\nrequest/connection statistics etc in master, and send messages to master\r\nfrom the worker(s). perhaps it would look something like this:\r\n\r\n```js\r\n  exports.master = function(){\r\n    process.on('message', function(){ // socket.io UI blah blah  })\r\n  };\r\n```\r\n\r\n```js\r\n  exports.worker = function(server){\r\n    server.on('connection', function(){\r\n      ... process.send(whatever)\r\n    });\r\n  };\r\n```\r\n\r\n these `--require`d scripts would be useful as mentioned for restart logic\r\n and other tasks as well, ex:\r\n\r\n```js\r\n  process.on('worker killed', function(worker){\r\n    console.log('  worker %d killed', worker.id);\r\n    require('cluster').spawn();\r\n  });\r\n```\r\n\r\nor things like REPLs which can manipulate the cluster with the\r\nmethods I've exposed in this patch.\r\n\r\ncheers!\r\n","comments":3,"title":"refactored cluster module","updated_at":"2011-10-17T04:12:35Z","url":"https://api.github.com/repos/joyent/node/issues/1879","id":1900456,"assignee":null,"milestone":null,"closed_at":null,"user":{"gravatar_id":"f1e3ab214a976a39cfd713bc93deb10f","avatar_url":"https://secure.gravatar.com/avatar/f1e3ab214a976a39cfd713bc93deb10f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/visionmedia","id":25254,"login":"visionmedia"},"html_url":"https://github.com/joyent/node/issues/1879","labels":[{"name":"cluster","url":"https://api.github.com/repos/joyent/node/labels/cluster","color":"e10c02"}],"state":"open"},"legacy":{"issue_id":1900456,"comment_id":2424875}}