Permalink
Browse files

Merge pull request #9 from benma/master

node.js using three cores
  • Loading branch information...
2 parents 464260d + 6cbed69 commit f49720b9dcc565d7c269adbf4d6b91eeda7c323e @snoyberg snoyberg committed Apr 17, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 pong/node.js
View
16 pong/node.js
@@ -1,5 +1,13 @@
var http = require('http');
-http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('PONG');
-}).listen(3000, "127.0.0.1");
+var cluster = require('cluster');
+
+if(cluster.isMaster) {
+ for(var i = 0; i < 3; i++) {
+ cluster.fork();
+ }
+} else {
+ http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('PONG');
+ }).listen(3000, "127.0.0.1");
+}

0 comments on commit f49720b

Please sign in to comment.