2021-08-15 00:10:54 +02:00
|
|
|
// process.env.MONGOMS_DEBUG = "true";
|
2021-08-13 12:58:18 +02:00
|
|
|
import cluster from "cluster";
|
|
|
|
import os from "os";
|
2021-08-14 23:15:19 +02:00
|
|
|
import { initStats } from "./stats";
|
2021-08-13 12:58:18 +02:00
|
|
|
|
2021-08-13 13:18:45 +02:00
|
|
|
// TODO: add tcp socket event transmission
|
|
|
|
const cores = 1 || Number(process.env.threads) || os.cpus().length;
|
2021-08-13 12:58:18 +02:00
|
|
|
|
|
|
|
if (cluster.isMaster && !process.env.masterStarted) {
|
|
|
|
process.env.masterStarted = "true";
|
|
|
|
|
|
|
|
(async () => {
|
2021-08-14 23:15:19 +02:00
|
|
|
initStats();
|
2021-08-13 12:58:18 +02:00
|
|
|
|
2021-08-13 20:54:52 +02:00
|
|
|
if (cores === 1) {
|
|
|
|
require("./Server.js");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-13 12:58:18 +02:00
|
|
|
// Fork workers.
|
|
|
|
for (let i = 0; i < cores; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster.on("exit", (worker: any, code: any, signal: any) => {
|
|
|
|
console.log(`[Worker] died with pid: ${worker.process.pid} , restarting ...`);
|
|
|
|
cluster.fork();
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
} else {
|
|
|
|
require("./Server.js");
|
|
|
|
}
|