Embed presentation
Downloaded 26 times




![var http = require("http");
var cluster = require("cluster");
var numCPUs = require("os").cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
for (var id in cluster.workers) {
console.log("Killing " + id);
cluster.workers[id].kill();
}
}](https://image.slidesharecdn.com/09-applicationscaling-140724115423-phpapp02/85/Node-js-Spplication-Scaling-5-320.jpg)



The document discusses using Node.js clustering to create a basic HTTP server that scales across CPU cores. It forks a worker process for each CPU core using the cluster module. Workers listen on port 8000 and log which process ID handles each request.




![var http = require("http");
var cluster = require("cluster");
var numCPUs = require("os").cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
for (var id in cluster.workers) {
console.log("Killing " + id);
cluster.workers[id].kill();
}
}](https://image.slidesharecdn.com/09-applicationscaling-140724115423-phpapp02/85/Node-js-Spplication-Scaling-5-320.jpg)

