{"_id":"mob","_rev":"32-fd0c8594fc4173f1fccc6621f0d2e60d","name":"mob","description":"simple multi-process applications","dist-tags":{"latest":"0.0.9"},"versions":{"0.0.1":{"name":"mob","version":"0.0.1","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"email":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"_id":"mob@0.0.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"4f7048a9e5be39073906b5e78db2611ba57c79c1","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.1.tgz","integrity":"sha512-8s2TWsy4j66O7TSXJZfiPtHjQAMnh4wbZmXUCTsozR2z250h2lDEU+Ki8A3BMhHVbkflZHEIJdBEHCywEx2PoQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFtg61OWL2zustKcoqM1dluuoeFZJaGxWYBV8OJuBTw0AiB0kPriiU93NlGtq1B3lQjk36DIFgBybbi911EAdgwCwA=="}]},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"directories":{}},"0.0.2":{"name":"mob","version":"0.0.2","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"email":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"_id":"mob@0.0.2","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"5ef56309bc526f60a893efd6d673e55cf353c60b","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.2.tgz","integrity":"sha512-lDCIRfFtafo7uJZYzbXkfn+3JI934uaN1W+yS2rtHiBY8jL+9n863IUW3lzfVtiwYHqj6RYDtVAFBTnDxZsuMQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBEFEF7RWSVeWvFqjUTdKmFAVGxCS5W61bXSstMvP8Z2AiEAgzJx1z5FFiffnf178asVrun3nSV9u4I5VurdgDKKDWc="}]},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"directories":{}},"0.0.4":{"name":"mob","version":"0.0.4","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"email":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"_id":"mob@0.0.4","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"f22b235730a71720e9ac8d01a642851c7e744841","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.4.tgz","integrity":"sha512-JFbTfPnnVos9r6XhOUXWgepqfWU6l3tU5vic4C8sIwWvn56fl1h+0HF/1mG45NJscSyvDYYRhyQEfeMSQrRWnw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKEWwRUeznbaN4jdE3dayr0FLbfq6sJSnHlRn18Oq3kAIhALZzvyJBk94MiHfzABkVNGp7HdcxJWnjr5Q/Yh+YT56b"}]},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"directories":{}},"0.0.5":{"name":"mob","version":"0.0.5","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"email":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"_id":"mob@0.0.5","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"5a695796f477daf6f0708ee4e08dc5a934046723","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.5.tgz","integrity":"sha512-1IHuTy7rRanc9YkEucMcsj4BFuGtKmL2SWP76sR7sD4A8JM8QaUHs5l0w9GDOIrloa9V/4wX1uH+eWAP7I8wuw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCLGBOSnaMSieF1QvzdbOZpow/yz+fABlJ2sZfSmVgrQAIhAOLKqSZx569BJJfTOfX3s6NlDnrYmUiuD0YkzfsUL1Il"}]},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"directories":{}},"0.0.7":{"name":"mob","version":"0.0.7","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"mail":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"readme":"\n\n# mob\n\nA simple toolkit for parallelizing node.js apps over several processes, built on top of the `cluster` module.\n\n    $ npm install mob\n\n### usage\n\nA mob-based app runs as two or more processes - the Kingpin (master), and one or more Mobsters (workers).\n\nThe **Kingpin**'s only function is to **keep the cluster running** by launching and reviving children,\nand to **route messages** between them. It should contain no application logic whatsoever,\nwhich is to ensure that bugs in your app don't end up crashing your server, but just temporarily break the affected child process.\n\n**Mobsters** are the actual workers that run your **application logic**.\nMobsters have different **roles**, so the application breaks down in several worker types,\neach of which specializes in different functionality, and exports it to the cluster just like a CommonJS module exports its API.\n\nThe main script will look like this:\n\n**main.js**\n```javascript\n\nrequire('mob')\n  .start('myapp') //  starts the app and sets the process.title prefix for all processes.\n  .base(module)   //  optional, all roles will have their paths resolved relatively to this module.\n\n  //  .role() accepts three parameters:\n  //  - the name of the role to be used with `mob.require()`;\n  //  - the module to require in child processes assigned with this role;\n  //  - any options, currently only the number of worker processes to spin up and keep alive.\n\n    .role('back',  \"./background-worker.js\", {workers: 4})\n    .role('front', \"./http-server.js\", {workers: 2});\n```\n\n`$ node main` will launch this script in as a Kingpin,\nwhich in turn will launch the 6 specialized child processes,\nin this case 4 background workers and 2 frontend processes.\n\n**background-worker.js**\n```javascript\n\nconsole.log('Background worker ' + process.pid + ' running.' );\n\nexports.foo = function () {\n  console.log('Bar! My pid is ' + process.pid);\n};\n```\n\n**http-server.js**\n```javascript\n\nvar mob = require('mob');\n\n//  Get a remoting proxy to the 'back' role's interface.\nvar back = mob.require('back');\n\n//  Because mob is based on cluster,\n//  all 2 'http-server' processes share the same server handle:\n\nvar http = require('http');\nhttp.createServer(function (req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'});\n  res.end('Hello World\\n');\n\n  console.log('Server ' + process.pid + ' served an http request.');\n\n  //  This will call foo on any one of the 4 'back' processes.\n  back.foo();\n\n  //  The proxy load-balances between all 4 processes, so\n  //    next time `back.foo();` gets called it might hit a different process.\n\n}).listen(1337, \"127.0.0.1\");\nconsole.log('Server ' + process.pid + ' running at http://127.0.0.1:1337/');\n```\n\n\n# mobsters!\n\n### exchanging messages\n\n`mob.require()` is built on a very simple message-exchange mechanism\npowered by `process.send()` and `worker.send()`. This mechanism is also exposed to application code in Mobster processes.\n\nTo send a message to all processes, do:\n```javascript\nrequire('mob')\n    .send( myobj );\n```\n\nTo send a message to all `back` processes, you could:\n```javascript\nrequire('mob')\n    .all('back').send( myobj );\n```\n\nTo send a message to a random `back` process:\n```javascript\nrequire('mob')\n    .any('back').send( myobj );\n```\n\nFinally, to target a particular process by `pid`, do:\n```javascript\nrequire('mob')\n    .pid( somepid ).send( myobj );\n```\n\nTo listen for messages:\n```javascript\nrequire('mob').on('message', handler);\n```\n\nKeep in mind that messages are passed around as JSON, so this is only good for exchaning data.\n\n\n### mobster export proxies\n\n`mob.require()` is not `require()` -\nyou are not dealing with the `module.exports` object directly, but with a proxy.\n**Only functions are proxied**, any other exported properties are ignored.\n\nMobster proxies created with `mob.require()` load-balance between workers,\nwhich means Mobsters' exports are only good if they are stateless.\nIf you want to reuse state,\nfor example because you're using an in-process key/value store like node-dirty or divan,\nyou should extract it in its own Mobster with only one worker.\n\n\n### passing callbacks\n\nThe `mob.require()` facility supports exchanging callbacks between processes, but two major limitations apply.\n\nFirst, currently **a callback can be invoked only once**, after which it is de-referenced\nand any further messages pushing data to that callback will be ignored.\n\nAlso, **make sure you do call back**, or else you will leak memory,\nas each callback is retained locally in the calling process and transported over to the other process\nas a numeric ID - and if you do not call back, this hard reference currently does not get collected.\n\n\n# license\n\nMIT.\n\n","readmeFilename":"README.md","_id":"mob@0.0.7","dist":{"shasum":"6de677281f83cfbb820d7888aaece85b28956a2d","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.7.tgz","integrity":"sha512-WBkreKPVBltLU3rdvFh/p8e/MaAzDQDjKDd1R0fhUy0GLczIGo7O7l2yKhq+f5tumzsotXWp2cfNJHTwJQZkkQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCTOy0WAyb064520O+NFh44DxwA5zEAVk9PDJ9a5muZXAIhAIOH4aGeRcfRJdbuyr6Vqcy1GnEQN005pe7VYsaylKjG"}]},"_from":".","_npmVersion":"1.2.15","_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"directories":{}},"0.0.8":{"name":"mob","version":"0.0.8","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"mail":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"readme":"\n\n# mob\n\nA simple toolkit for parallelizing node.js apps over several processes, built on top of the `cluster` module.\n\n    $ npm install mob\n\n### usage\n\nA mob-based app runs as two or more processes - the Kingpin (master), and one or more Mobsters (workers).\n\nThe **Kingpin**'s only function is to **keep the cluster running** by launching and reviving children,\nand to **route messages** between them. It should contain no application logic whatsoever,\nwhich is to ensure that bugs in your app don't end up crashing your server, but just temporarily break the affected child process.\n\n**Mobsters** are the actual workers that run your **application logic**.\nMobsters have different **roles**, so the application breaks down in several worker types,\neach of which specializes in different functionality, and exports it to the cluster just like a CommonJS module exports its API.\n\nThe main script will look like this:\n\n**main.js**\n```javascript\n\nrequire('mob')\n  .start('myapp') //  starts the app and sets the process.title prefix for all processes.\n  .base(module)   //  optional, all roles will have their paths resolved relatively to this module.\n\n  //  .role() accepts three parameters:\n  //  - the name of the role to be used with `mob.require()`;\n  //  - the module to require in child processes assigned with this role;\n  //  - any options, currently only the number of worker processes to spin up and keep alive.\n\n    .role('back',  \"./background-worker.js\", {workers: 4})\n    .role('front', \"./http-server.js\", {workers: 2});\n```\n\n`$ node main` will launch this script in as a Kingpin,\nwhich in turn will launch the 6 specialized child processes,\nin this case 4 background workers and 2 frontend processes.\n\n**background-worker.js**\n```javascript\n\nconsole.log('Background worker ' + process.pid + ' running.' );\n\nexports.foo = function () {\n  console.log('Bar! My pid is ' + process.pid);\n};\n```\n\n**http-server.js**\n```javascript\n\nvar mob = require('mob');\n\n//  Get a remoting proxy to the 'back' role's interface.\nvar back = mob.require('back');\n\n//  Because mob is based on cluster,\n//  all 2 'http-server' processes share the same server handle:\n\nvar http = require('http');\nhttp.createServer(function (req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'});\n  res.end('Hello World\\n');\n\n  console.log('Server ' + process.pid + ' served an http request.');\n\n  //  This will call foo on any one of the 4 'back' processes.\n  back.foo();\n\n  //  The proxy load-balances between all 4 processes, so\n  //    next time `back.foo();` gets called it might hit a different process.\n\n}).listen(1337, \"127.0.0.1\");\nconsole.log('Server ' + process.pid + ' running at http://127.0.0.1:1337/');\n```\n\n\n# mobsters!\n\n### exchanging messages\n\n`mob.require()` is built on a very simple message-exchange mechanism\npowered by `process.send()` and `worker.send()`. This mechanism is also exposed to application code in Mobster processes.\n\nTo send a message to all processes, do:\n```javascript\nrequire('mob')\n    .send( myobj );\n```\n\nTo send a message to all `back` processes, you could:\n```javascript\nrequire('mob')\n    .all('back').send( myobj );\n```\n\nTo send a message to a random `back` process:\n```javascript\nrequire('mob')\n    .any('back').send( myobj );\n```\n\nFinally, to target a particular process by `pid`, do:\n```javascript\nrequire('mob')\n    .pid( somepid ).send( myobj );\n```\n\nTo listen for messages:\n```javascript\nrequire('mob').on('message', handler);\n```\n\nKeep in mind that messages are passed around as JSON, so this is only good for exchaning data.\n\n\n### mobster export proxies\n\n`mob.require()` is not `require()` -\nyou are not dealing with the `module.exports` object directly, but with a proxy.\n**Only functions are proxied**, any other exported properties are ignored.\n\nMobster proxies created with `mob.require()` load-balance between workers,\nwhich means Mobsters' exports are only good if they are stateless.\nIf you want to reuse state,\nfor example because you're using an in-process key/value store like node-dirty or divan,\nyou should extract it in its own Mobster with only one worker.\n\n\n### passing callbacks\n\nThe `mob.require()` facility supports exchanging callbacks between processes, but two major limitations apply.\n\nFirst, currently **a callback can be invoked only once**, after which it is de-referenced\nand any further messages pushing data to that callback will be ignored.\n\nAlso, **make sure you do call back**, or else you will leak memory,\nas each callback is retained locally in the calling process and transported over to the other process\nas a numeric ID - and if you do not call back, this hard reference currently does not get collected.\n\n\n# license\n\nMIT.\n\n","readmeFilename":"README.md","_id":"mob@0.0.8","dist":{"shasum":"60880236797bb0d8d0d2d854eafc67876cd05d04","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.8.tgz","integrity":"sha512-P+FJ2Yx+PY5p8Qb2C5PtNpM7OyCdiMeOjATVET3YsB8Drd4LsRc1Fr/OLehAK7Xe47mfha4GP9Xx0AXTq8fJOA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC7br2G9nu5n0vdF2MYUcGsTFY9K1HsPij215M7SysAOAIgUCukMYQLK86USNOe0hAIZ2MSP78SDrA3zV1KKuQHbds="}]},"_from":".","_npmVersion":"1.2.15","_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}]},"0.0.9":{"name":"mob","version":"0.0.9","description":"simple multi-process applications","keywords":["cluster","child","process","message","passing","procfile"],"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"main":"./index.js","bugs":{"mail":"tutini@gmail.com","url":"http://github.com/hdachev/node-mob/issues"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"},"readme":"\n\n# mob\n\nA simple toolkit for parallelizing node.js apps over several processes, built on top of the `cluster` module.\n\n    $ npm install mob\n\n### usage\n\nA mob-based app runs as two or more processes - the Kingpin (master), and one or more Mobsters (workers).\n\nThe **Kingpin**'s only function is to **keep the cluster running** by launching and reviving children,\nand to **route messages** between them. It should contain no application logic whatsoever,\nwhich is to ensure that bugs in your app don't end up crashing your server, but just temporarily break the affected child process.\n\n**Mobsters** are the actual workers that run your **application logic**.\nMobsters have different **roles**, so the application breaks down in several worker types,\neach of which specializes in different functionality, and exports it to the cluster just like a CommonJS module exports its API.\n\nThe main script will look like this:\n\n**main.js**\n```javascript\n\nrequire('mob')\n  .start('myapp') //  starts the app and sets the process.title prefix for all processes.\n  .base(module)   //  optional, all roles will have their paths resolved relatively to this module.\n\n  //  .role() accepts three parameters:\n  //  - the name of the role to be used with `mob.require()`;\n  //  - the module to require in child processes assigned with this role;\n  //  - any options, currently only the number of worker processes to spin up and keep alive.\n\n    .role('back',  \"./background-worker.js\", {workers: 4})\n    .role('front', \"./http-server.js\", {workers: 2});\n```\n\n`$ node main` will launch this script in as a Kingpin,\nwhich in turn will launch the 6 specialized child processes,\nin this case 4 background workers and 2 frontend processes.\n\n**background-worker.js**\n```javascript\n\nconsole.log('Background worker ' + process.pid + ' running.' );\n\nexports.foo = function () {\n  console.log('Bar! My pid is ' + process.pid);\n};\n```\n\n**http-server.js**\n```javascript\n\nvar mob = require('mob');\n\n//  Get a remoting proxy to the 'back' role's interface.\nvar back = mob.require('back');\n\n//  Because mob is based on cluster,\n//  all 2 'http-server' processes share the same server handle:\n\nvar http = require('http');\nhttp.createServer(function (req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'});\n  res.end('Hello World\\n');\n\n  console.log('Server ' + process.pid + ' served an http request.');\n\n  //  This will call foo on any one of the 4 'back' processes.\n  back.foo();\n\n  //  The proxy load-balances between all 4 processes, so\n  //    next time `back.foo();` gets called it might hit a different process.\n\n}).listen(1337, \"127.0.0.1\");\nconsole.log('Server ' + process.pid + ' running at http://127.0.0.1:1337/');\n```\n\n\n# mobsters!\n\n### exchanging messages\n\n`mob.require()` is built on a very simple message-exchange mechanism\npowered by `process.send()` and `worker.send()`. This mechanism is also exposed to application code in Mobster processes.\n\nTo send a message to all processes, do:\n```javascript\nrequire('mob')\n    .send( myobj );\n```\n\nTo send a message to all `back` processes, you could:\n```javascript\nrequire('mob')\n    .all('back').send( myobj );\n```\n\nTo send a message to a random `back` process:\n```javascript\nrequire('mob')\n    .any('back').send( myobj );\n```\n\nFinally, to target a particular process by `pid`, do:\n```javascript\nrequire('mob')\n    .pid( somepid ).send( myobj );\n```\n\nTo listen for messages:\n```javascript\nrequire('mob').on('message', handler);\n```\n\nKeep in mind that messages are passed around as JSON, so this is only good for exchaning data.\n\n\n### mobster export proxies\n\n`mob.require()` is not `require()` -\nyou are not dealing with the `module.exports` object directly, but with a proxy.\n**Only functions are proxied**, any other exported properties are ignored.\n\nMobster proxies created with `mob.require()` load-balance between workers,\nwhich means Mobsters' exports are only good if they are stateless.\nIf you want to reuse state,\nfor example because you're using an in-process key/value store like node-dirty or divan,\nyou should extract it in its own Mobster with only one worker.\n\n\n### passing callbacks\n\nThe `mob.require()` facility supports exchanging callbacks between processes, but two major limitations apply.\n\nFirst, currently **a callback can be invoked only once**, after which it is de-referenced\nand any further messages pushing data to that callback will be ignored.\n\nAlso, **make sure you do call back**, or else you will leak memory,\nas each callback is retained locally in the calling process and transported over to the other process\nas a numeric ID - and if you do not call back, this hard reference currently does not get collected.\n\n\n# license\n\nMIT.\n\n","readmeFilename":"README.md","_id":"mob@0.0.9","dist":{"shasum":"a5e791d66408c3dc0bd461c56d7b178d2b5d3749","tarball":"https://registry.npmjs.org/mob/-/mob-0.0.9.tgz","integrity":"sha512-JljrJwbnWOu3DUXtr+QMCJwMfYIbf7gtmmhL7ADxP78hnk2ps7Ba+cXpaX/xngqhNBfpRGKyvhjNzeaaVQaY0Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICx+ffTqk9JdjVCacnyKYB1FZJzm9XR3FOibx0za6dHqAiBY2ClCGbOR7fM2ZXVfHeLgIK+c/p/hjCjPLPX5l3XAOQ=="}]},"_from":".","_npmVersion":"1.2.15","_npmUser":{"name":"hdachev","email":"tutini@gmail.com"},"maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}]}},"readme":"\n\n# mob\n\nA simple toolkit for parallelizing node.js apps over several processes, built on top of the `cluster` module.\n\n    $ npm install mob\n\n### usage\n\nA mob-based app runs as two or more processes - the Kingpin (master), and one or more Mobsters (workers).\n\nThe **Kingpin**'s only function is to **keep the cluster running** by launching and reviving children,\nand to **route messages** between them. It should contain no application logic whatsoever,\nwhich is to ensure that bugs in your app don't end up crashing your server, but just temporarily break the affected child process.\n\n**Mobsters** are the actual workers that run your **application logic**.\nMobsters have different **roles**, so the application breaks down in several worker types,\neach of which specializes in different functionality, and exports it to the cluster just like a CommonJS module exports its API.\n\nThe main script will look like this:\n\n**main.js**\n```javascript\n\nrequire('mob')\n  .start('myapp') //  starts the app and sets the process.title prefix for all processes.\n  .base(module)   //  optional, all roles will have their paths resolved relatively to this module.\n\n  //  .role() accepts three parameters:\n  //  - the name of the role to be used with `mob.require()`;\n  //  - the module to require in child processes assigned with this role;\n  //  - any options, currently only the number of worker processes to spin up and keep alive.\n\n    .role('back',  \"./background-worker.js\", {workers: 4})\n    .role('front', \"./http-server.js\", {workers: 2});\n```\n\n`$ node main` will launch this script in as a Kingpin,\nwhich in turn will launch the 6 specialized child processes,\nin this case 4 background workers and 2 frontend processes.\n\n**background-worker.js**\n```javascript\n\nconsole.log('Background worker ' + process.pid + ' running.' );\n\nexports.foo = function () {\n  console.log('Bar! My pid is ' + process.pid);\n};\n```\n\n**http-server.js**\n```javascript\n\nvar mob = require('mob');\n\n//  Get a remoting proxy to the 'back' role's interface.\nvar back = mob.require('back');\n\n//  Because mob is based on cluster,\n//  all 2 'http-server' processes share the same server handle:\n\nvar http = require('http');\nhttp.createServer(function (req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'});\n  res.end('Hello World\\n');\n\n  console.log('Server ' + process.pid + ' served an http request.');\n\n  //  This will call foo on any one of the 4 'back' processes.\n  back.foo();\n\n  //  The proxy load-balances between all 4 processes, so\n  //    next time `back.foo();` gets called it might hit a different process.\n\n}).listen(1337, \"127.0.0.1\");\nconsole.log('Server ' + process.pid + ' running at http://127.0.0.1:1337/');\n```\n\n\n# mobsters!\n\n### exchanging messages\n\n`mob.require()` is built on a very simple message-exchange mechanism\npowered by `process.send()` and `worker.send()`. This mechanism is also exposed to application code in Mobster processes.\n\nTo send a message to all processes, do:\n```javascript\nrequire('mob')\n    .send( myobj );\n```\n\nTo send a message to all `back` processes, you could:\n```javascript\nrequire('mob')\n    .all('back').send( myobj );\n```\n\nTo send a message to a random `back` process:\n```javascript\nrequire('mob')\n    .any('back').send( myobj );\n```\n\nFinally, to target a particular process by `pid`, do:\n```javascript\nrequire('mob')\n    .pid( somepid ).send( myobj );\n```\n\nTo listen for messages:\n```javascript\nrequire('mob').on('message', handler);\n```\n\nKeep in mind that messages are passed around as JSON, so this is only good for exchaning data.\n\n\n### mobster export proxies\n\n`mob.require()` is not `require()` -\nyou are not dealing with the `module.exports` object directly, but with a proxy.\n**Only functions are proxied**, any other exported properties are ignored.\n\nMobster proxies created with `mob.require()` load-balance between workers,\nwhich means Mobsters' exports are only good if they are stateless.\nIf you want to reuse state,\nfor example because you're using an in-process key/value store like node-dirty or divan,\nyou should extract it in its own Mobster with only one worker.\n\n\n### passing callbacks\n\nThe `mob.require()` facility supports exchanging callbacks between processes, but two major limitations apply.\n\nFirst, currently **a callback can be invoked only once**, after which it is de-referenced\nand any further messages pushing data to that callback will be ignored.\n\nAlso, **make sure you do call back**, or else you will leak memory,\nas each callback is retained locally in the calling process and transported over to the other process\nas a numeric ID - and if you do not call back, this hard reference currently does not get collected.\n\n\n# license\n\nMIT.\n\n","maintainers":[{"name":"hdachev","email":"tutini@gmail.com"}],"time":{"modified":"2022-06-20T00:34:54.906Z","created":"2012-05-15T20:50:34.516Z","0.0.1":"2012-05-15T20:50:37.233Z","0.0.2":"2012-05-16T10:20:30.256Z","0.0.3":"2012-05-18T13:14:57.779Z","0.0.4":"2012-05-18T13:30:44.093Z","0.0.5":"2012-05-23T23:33:39.385Z","0.0.6":"2013-03-24T14:36:48.729Z","0.0.7":"2013-03-25T18:33:10.668Z","0.0.8":"2013-04-05T10:50:54.883Z","0.0.9":"2013-06-09T08:00:39.923Z"},"author":{"name":"Hristo Dachev","email":"tutini@gmail.com"},"repository":{"type":"git","url":"git://github.com/hdachev/node-mob.git"}}