File: clustering/webserver_fork.js

Recommend this page to a friend!
  Classes of Igor Escobar   Terminal Crossword   clustering/webserver_fork.js   Download  
File: clustering/webserver_fork.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Terminal Crossword
Generate a crosswords board on a text console
Author: By
Last change:
Date: 2 years ago
Size: 659 bytes
 

Contents

Class file image Download
var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('online', function(worker, code, signal) { console.log('worker ' + worker.process.pid + ' online'); }); cluster.on('exit', function(worker, code, signal) { console.log('worker ' + worker.process.pid + ' died'); }); } else { // Workers can share any TCP connection // In this case its a HTTP server http.createServer(function(req, res) { res.writeHead(200); res.end("Hello World!\n"); }).listen(8000); }