Skip to content

Commit 80afa02

Browse files
authored
Merge pull request #58 from adorableio/add-concurrency
Add concurrency
2 parents d225599 + 8515ae0 commit 80afa02

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed

index.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import 'babel-polyfill';
1+
require('babel-register');
22

33
require('./src/server');

package-lock.json

Lines changed: 36 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"babel-jest": "^19.0.0",
1818
"babel-plugin-transform-object-rest-spread": "^6.23.0",
1919
"babel-plugin-transform-regenerator": "^6.24.1",
20-
"babel-polyfill": "^6.23.0",
2120
"babel-preset-env": "^1.4.0",
21+
"babel-register": "^6.24.1",
2222
"babel-watch": "^2.0.6",
2323
"colors": "^0.6.2",
2424
"express": "^4.8.0",
25+
"express-cluster": "0.0.4",
2526
"find-port": "^1.0.0",
2627
"gm": "^1.16.0",
2728
"newrelic": "^1.27.2",

src/server.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
require('babel-register');
2+
13
if (process.env.NODE_ENV === 'production') {
24
// eslint-disable-next-line no-console
35
console.log('LOADING NEW RELIC');
46
require('newrelic');
57
}
68

79
import express from 'express';
10+
import cluster from 'express-cluster';
811
import path from 'path';
912
import favicon from 'serve-favicon';
1013
import findPort from 'find-port';
@@ -15,6 +18,8 @@ const app = express();
1518
const basePath = path.join(__dirname, '..');
1619
const faviconPath = path.join(basePath, 'src', 'favicon.ico');
1720

21+
const webConcurrency = process.env.WEB_CONCURRENCY || 1;
22+
1823
app.set('trust proxy', true);
1924

2025
app.use(favicon(faviconPath));
@@ -42,12 +47,15 @@ const listen = (port) => {
4247
};
4348

4449
const port = process.env.PORT || 3002;
45-
if (port > 3002) {
46-
listen(port);
47-
} else {
48-
findPort(port, port + 100, function(ports) {
49-
return listen(ports[0]);
50-
});
51-
}
50+
51+
cluster(function() {
52+
if (port > 3002) {
53+
listen(port);
54+
} else {
55+
findPort(port, port + 100, function(ports) {
56+
return listen(ports[0]);
57+
});
58+
}
59+
}, { count: webConcurrency });
5260

5361
export default app;

0 commit comments

Comments
 (0)