From df66dccbc2f792614af9850fc2e0da570ef0e04a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 14 Jul 2015 14:18:45 +0200 Subject: [PATCH 1/2] run webserver on all available cores, resolves #6 --- index.js | 29 ++++++++++++++++------------- package.json | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 2e2e47bf..5f043b26 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,20 @@ -var cluster = require('cluster'), - app = require('./app'), - multicore = false, - port = ( process.env.PORT || 3100 ); +var Cluster = require('cluster2'), + app = require('./app'), + port = ( process.env.PORT || 3100 ), + multicore = true; /** cluster webserver across all cores **/ -// if( multicore ){ - // @todo: not finished yet - // cluster(app) - // .use(cluster.stats()) - // .listen( process.env.PORT || 3100 ); -// } -if (!multicore){ - console.log( 'listening on ' + port ); - app.listen( process.env.PORT || 3100 ); +if( multicore ){ + var c = new Cluster({ port: port }); + c.listen(function(cb){ + console.log( 'worker: listening on ' + port ); + cb(app); + }); } + +/** run server on the default setup (single core) **/ +else { + console.log( 'listening on ' + port ); + app.listen( port ); +} \ No newline at end of file diff --git a/package.json b/package.json index b59a6ffc..39bd8473 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ }, "dependencies": { "async": "^0.9.0", + "cluster2": "^0.4.26", "express": "^4.8.8", "geojson": "^0.2.1", "geojson-extent": "^0.3.1", From e3efeb66d18374524f89696754db0a024c27dc73 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 3 Aug 2015 12:01:32 +0200 Subject: [PATCH 2/2] change dependency to git url until PR merged upstream, test travis against 0.10,0.12 --- .travis.yml | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4ca5cafc..f2a4e06a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,5 @@ language: node_js script: "npm run unit" node_js: - "0.10" + - "0.12" sudo: false \ No newline at end of file diff --git a/package.json b/package.json index 4610d0e4..dcf30f49 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "dependencies": { "async": "^0.9.0", - "cluster2": "^0.4.26", + "cluster2": "git://github.com/missinglink/cluster2.git#node_zero_twelve", "express": "^4.8.8", "geojson": "^0.2.1", "geojson-extent": "^0.3.1",