Commit e8306a3123ec03616c9a5523a32f8b3d8423b309

Authored by Adhidarma Hadiwinoto
1 parent 6398fc28d2
Exists in master

Disable cluster mode

Showing 1 changed file with 2 additions and 1 deletions Inline Diff

lib/webservice/index.js
1 const CLUSTER_MODE = false;
1 const cluster = require('cluster'); 2 const cluster = require('cluster');
2 const numCPUs = require('os').cpus().length; 3 const numCPUs = require('os').cpus().length;
3 const express = require('express'); 4 const express = require('express');
4 5
5 const config = require('komodo-sdk/config'); 6 const config = require('komodo-sdk/config');
6 const logger = require('komodo-sdk/logger'); 7 const logger = require('komodo-sdk/logger');
7 8
8 const app = express(); 9 const app = express();
9 const listenPort = config.webservice.port || config.webservice.listen_port; 10 const listenPort = config.webservice.port || config.webservice.listen_port;
10 11
11 const routerPriceplan = require('./router/priceplan'); 12 const routerPriceplan = require('./router/priceplan');
12 13
13 app.use('/apikey/:apikey/priceplan', routerPriceplan); 14 app.use('/apikey/:apikey/priceplan', routerPriceplan);
14 15
15 if (cluster.isMaster) { 16 if (CLUSTER_MODE && cluster.isMaster) {
16 logger.info(`Master ${process.pid} is running`); 17 logger.info(`Master ${process.pid} is running`);
17 18
18 // Fork workers. 19 // Fork workers.
19 for (let i = 0; i < numCPUs; i += 1) { 20 for (let i = 0; i < numCPUs; i += 1) {
20 cluster.fork(); 21 cluster.fork();
21 } 22 }
22 23
23 cluster.on('exit', (worker) => { 24 cluster.on('exit', (worker) => {
24 logger.info(`worker ${worker.process.pid} died`); 25 logger.info(`worker ${worker.process.pid} died`);
25 }); 26 });
26 } else { 27 } else {
27 app.listen(listenPort, () => { 28 app.listen(listenPort, () => {
28 logger.info(`WEBSERVICE ${process.pid} listen on ${listenPort}`); 29 logger.info(`WEBSERVICE ${process.pid} listen on ${listenPort}`);
29 }); 30 });
30 } 31 }
31 32