Last active
January 4, 2017 14:38
-
-
Save apaleslimghost/8a1b1e7a7f28991f1b8174a827dab00e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os'); | |
const throng = require('throng'); | |
const cluster = require('cluster'); | |
module.exports = ({defaultPort, app}) => { | |
const port = process.env.PORT || defaultPort; | |
const workers = process.env.WEB_CONCURRENCY ? | |
parseInt(process.env.WEB_CONCURRENCY, 10) : | |
os.cpus().length; | |
throng({ | |
workers, | |
master() { | |
console.log(`Starting ${workers} workers`); | |
}, | |
start() { | |
app.listen(port, () => console.log(`Worker ${process.pid} listening on port ${port}`)); | |
}, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment