throngでwebサーバーをクラスタリング #nodejs #express #heroku

HerokuでNode.jsのアプリをExpressで作って、クラスタリングを試すのにthrongを使ったのでwebサーバーの起動方法をメモ

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

END

Close