parent
3eff85a3d3
commit
f18f30cb79
@ -112,6 +112,11 @@ export async function masterMain() {
|
|||||||
await server();
|
await server();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.clusterLimit === 0) {
|
||||||
|
bootLogger.error("Configuration error: we can't create workers, `config.clusterLimit` is 0 (if you don't want to use clustering, set the environment variable `MK_DISABLE_CLUSTERING` to a non-empty value instead)", null, true);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
await spawnWorkers(config.clusterLimit);
|
await spawnWorkers(config.clusterLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,14 +186,8 @@ async function connectDb(): Promise<void> {
|
|||||||
|
|
||||||
async function spawnWorkers(limit = 1) {
|
async function spawnWorkers(limit = 1) {
|
||||||
const cpuCount = os.cpus().length;
|
const cpuCount = os.cpus().length;
|
||||||
const workers = Math.min(limit, cpuCount);
|
// in some weird environments, node can't count the CPUs; we trust the config in those cases
|
||||||
if (workers === 0) {
|
const workers = cpuCount === 0 ? limit : Math.min(limit, cpuCount);
|
||||||
const cause = cpuCount === 0
|
|
||||||
? 'you seem to have no CPUs (this may be caused by some "hardening" system)'
|
|
||||||
: "`config.clusterLimit` is 0 (if you don't want to use clustering, set the environment variable `MK_DISABLE_CLUSTERING` to a non-empty value instead)";
|
|
||||||
bootLogger.error(`Configuration error: we can't create workers, ${cause}`, null, true);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bootLogger.info(`Starting ${workers} worker${workers === 1 ? '' : 's'}...`);
|
bootLogger.info(`Starting ${workers} worker${workers === 1 ? '' : 's'}...`);
|
||||||
await Promise.all([...Array(workers)].map(spawnWorker));
|
await Promise.all([...Array(workers)].map(spawnWorker));
|
||||||
|
Loading…
Reference in New Issue
Block a user