Skip to content

Instantly share code, notes, and snippets.

@jmervine
Created April 9, 2014 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmervine/10308492 to your computer and use it in GitHub Desktop.
Save jmervine/10308492 to your computer and use it in GitHub Desktop.
// npm install restify
var payload = JSON.parse(require('fs').readFileSync('./bento.json', 'utf8'));
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork();
cluster.fork();
cluster.on('exit', function() {
console.log('starting new fork');
cluster.fork();
});
} else {
var restify = require('restify');
var server = restify.createServer();
function handle(req, res, next) {
if (Math.random() > 0.8) {
setTimeout(function() {
process.exit();
}, 3000);
} else {
setTimeout(function() {
res.json(payload);
next();
}, 500);
}
}
server.get(/.*/, handle);
server.listen(8888);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment