© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var http = require("http");
var cluster = require(...
M
W
The difference between 'fork' and
'online' is that fork is emitted when
the master forks a worker, and 'online'
is emi...
var http = require("http");
var cluster = require("cluster");
var numCPUs = require("os").cpus().length;
if (cluster.isMas...
var http = require("http");
var cluster = require("cluster");
var numCPUs = require("os").cpus().length;
if (cluster.isMas...
if (cluster.isMaster) {
var worker = cluster.fork();
worker.send('hi there');
} else if (cluster.isWorker) {
process.on('m...
Node.js Spplication Scaling
Node.js Spplication Scaling
Upcoming SlideShare
Loading in …5
×

Node.js Spplication Scaling

535
-1

Published on

Node.js Spplication Scaling

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
535
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Node.js Spplication Scaling

  1. 1. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var http = require("http"); var cluster = require("cluster"); var numCPUs = require("os").cpus().length; if (cluster.isMaster) { for (var i = 0; i < numCPUs; i++) { console.log("Forking child"); cluster.fork(); } } else { http.createServer(function (request, response) { console.log(process.pid + ": request for " + request.url); response.writeHead(200); response.end("Hello World!"); }).listen(8000); }
  2. 2. M W The difference between 'fork' and 'online' is that fork is emitted when the master forks a worker, and 'online' is emitted when the worker is running.
  3. 3. var http = require("http"); var cluster = require("cluster"); var numCPUs = require("os").cpus().length; if (cluster.isMaster) { cluster.on("fork", function (worker) { console.log("Attempting to fork worker"); }); cluster.on("online", function (worker) { console.log("Successfully forked worker"); }); for (var i = 0; i < numCPUs; i++) { cluster.fork(); } } else { // implement worker code }
  4. 4. 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(); } }
  5. 5. if (cluster.isMaster) { var worker = cluster.fork(); worker.send('hi there'); } else if (cluster.isWorker) { process.on('message', function (msg) { process.send(msg); }); }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×