--- Title: 'throngでwebサーバーをクラスタリング #nodejs #express #heroku' Keywords: - nodejs - express - heroku Author: hiro_y Web: 'https://mimemo.io/m/WrRz7l7QKGNaA6n' --- HerokuでNode.jsのアプリをExpressで作って、クラスタリングを試すのに[throng](https://github.com/hunterloftis/throng)を使ったのでwebサーバーの起動方法をメモ ```js const throng = require('throng'); // 中略 throng({ workers: config.webConcurrency, lifetime: Infinity, master: () => { console.log('Started master'); }, start: (id) => { app.listen(config.port, () => { console.log(`Started worker ${id} on port: ${config.port}`); }); process.on('SIGTERM', () => { console.log(`Worker ${id} exiting...`); process.exit(); }); }, }); ``` 参考: [Optimizing Node.js Application Concurrency | Heroku Dev Center](https://devcenter.heroku.com/articles/node-concurrency)