From e4bf0392af81fc48bd2e5c1c321a543b347892c2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 28 Jul 2018 03:55:41 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=BF=E6=95=B0?= =?UTF-8?q?=E3=82=92=E5=88=B6=E9=99=90=E3=81=99=E3=82=8B=E3=82=AA=E3=83=97?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/example.yml | 3 +++ src/config/types.ts | 2 ++ src/index.ts | 10 ++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.config/example.yml b/.config/example.yml index 05dc43c44..b84a50c52 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -131,3 +131,6 @@ drive: # Ghost account is an account used for the purpose of delegating # followers when putting users in the list. # ghost: user-id-of-your-ghost-account + +# Clustering +# clusterLimit: 1 diff --git a/src/config/types.ts b/src/config/types.ts index a3d55e284..f220e1582 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -92,6 +92,8 @@ export type Source = { }; google_maps_api_key: string; + + clusterLimit?: number; }; /** diff --git a/src/index.ts b/src/index.ts index 9c16c4d22..eae25762e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,7 +66,7 @@ async function masterMain() { Logger.succ('Misskey initialized'); - spawnWorkers(() => { + spawnWorkers(config.clusterLimit, () => { Logger.succ('All workers started'); Logger.info(`Now listening on port ${config.port} on ${config.url}`); }); @@ -137,14 +137,16 @@ async function init(): Promise { return config; } -function spawnWorkers(onComplete: Function) { +function spawnWorkers(limit: number, onComplete: Function) { // Count the machine's CPUs const cpuCount = os.cpus().length; - const progress = new ProgressBar(cpuCount, 'Starting workers'); + const count = limit || cpuCount; + + const progress = new ProgressBar(count, 'Starting workers'); // Create a worker for each CPU - for (let i = 0; i < cpuCount; i++) { + for (let i = 0; i < count; i++) { const worker = cluster.fork(); worker.on('message', message => { if (message === 'ready') {