From 1db4951395ff9edbe20620084c1e2c4ca2944a72 Mon Sep 17 00:00:00 2001 From: Yonle Date: Tue, 31 Oct 2023 14:16:43 +0700 Subject: [PATCH] allow for setting number of clusters via config.js Signed-off-by: Yonle --- bouncer/bouncer2.js | 1 + config.js.example | 2 ++ index.js | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bouncer/bouncer2.js b/bouncer/bouncer2.js index b2e3920..36906b4 100644 --- a/bouncer/bouncer2.js +++ b/bouncer/bouncer2.js @@ -93,6 +93,7 @@ function terminate_sess(id) { socks.forEach(sock => { if (sock.id !== id) return; sock.terminate(); + socks.delete(sock); }); } diff --git a/config.js.example b/config.js.example index 6d304e6..e3b882b 100644 --- a/config.js.example +++ b/config.js.example @@ -11,6 +11,8 @@ module.exports = { // 2 -> Accurate, But every clients will connects to numbers of mode: 1, + clusters: 1, + // Server information. // Only for when nostr client requesting server information. server_meta: { diff --git a/index.js b/index.js index 1ba3581..d942680 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +const config = require("./config"); const cluster = require("cluster"); const fs = require("fs"); const os = require("os"); @@ -7,7 +8,7 @@ if (!process.env.NO_CLUSTERS && cluster.isPrimary) { fs.rmSync(".temporary.db"); } catch {} - const numClusters = process.env.CLUSTERS || (os.availableParallelism ? os.availableParallelism() : (os.cpus().length || 2)) + const numClusters = process.env.CLUSTERS || config.clusters || (os.availableParallelism ? os.availableParallelism() : (os.cpus().length || 2)) console.log(`Primary ${process.pid} is running. Will fork ${numClusters} clusters.`);