Node.js based forum software built for the modern web
fix: update maxWorkers strategy to set up more workers per CPU as AP is mostly network-bound. Previous was 1-per CPU (min 1); now using os.availableParallelism() * 2
Julian Lama0fa24563e95
diff --git a/src/activitypub/send.js b/src/activitypub/send.jsindex 7822a21693..e1316a3f2e 100644--- a/src/activitypub/send.js+++ b/src/activitypub/send.js@@ -8,10 +8,6 @@ const winston = require('winston');const db = require('../database');-// ----------------------------------------------------------------------------// SendPool — worker pool management for outbound federation-// ----------------------------------------------------------------------------const SendPool = {pool: [],free: [],@@ -24,11 +20,8 @@ const SendPool = {maxWorkers: 0,};-SendPool.maxWorkers = Math.max(1, os.cpus().length - 1);+SendPool.maxWorkers = Math.max(4, os.availableParallelism() * 2);-/**- * Initialize the send pool — fork workers and wait for ready signals.- */SendPool.init = function (activityPub) {if (activityPub) {SendPool._activityPub = activityPub;@@ -38,9 +31,6 @@ SendPool.init = function (activityPub) {}};-/**- * Fork a new worker process and set up message/exit handlers.- */SendPool.forkWorker = function () {const workerPath = path.join(__dirname, 'sendWorker.js');const proc = fork(workerPath, [], {@@ -89,9 +79,6 @@ SendPool.forkWorker = function () {SendPool.pool.push(proc);};-/**- * Handle worker exit — re-queue in-flight task if any.- */SendPool.handleWorkerExit = function (proc, code) {winston.warn(`[activitypub/send] Worker exited with code ${code}`);@@ -127,9 +114,6 @@ SendPool.handleWorkerExit = function (proc, code) {}};-/**- * Handle a result from a worker — analytics on success, re-queue on failure.- */SendPool.handleResult = function (message) {const { id, success, error } = message;const task = SendPool.pending.get(id);@@ -171,9 +155,6 @@ SendPool.handleResult = function (message) {}};-/**- * Re-queue a task to the Redis retry queue with exponential backoff.- */SendPool.requeueTask = function (task) {const oneMinute = 1000 * 60;const maxDelay = 60 * 60 * 1000; // 1 hour@@ -207,9 +188,6 @@ SendPool.requeueTask = function (task) {db.setObjectBulk(retryQueuedSet);};-/**- * Clear the stuck-task timer for a task.- */SendPool.clearTaskTimer = function (taskId) {const timer = SendPool.taskTimers.get(taskId);if (timer) {@@ -218,9 +196,6 @@ SendPool.clearTaskTimer = function (taskId) {}};-/**- * Dispatch a task to an available worker.- */SendPool.dispatch = function (taskId, task) {if (SendPool.free.length === 0) {// No free workers — task stays in pending queue@@ -265,11 +240,6 @@ SendPool.dispatch = function (taskId, task) {return true;};-/**- * Drain loop — dispatch tasks from Redis queue to available workers.- * Active mode: tight loop with setImmediate yield between batches.- * Idle mode: 10-second setTimeout before checking again.- */SendPool.drainLoop = async function () {if (SendPool.draining) {return;@@ -367,9 +337,6 @@ SendPool.drainLoop = async function () {}};-/**- * Graceful shutdown — stop drain loop, shutdown workers, wait, then kill.- */SendPool.shutdown = function () {SendPool.isShuttingDown = true;SendPool.draining = false;diff --git a/src/activitypub/sendWorker.js b/src/activitypub/sendWorker.jsindex 5af159f558..84d57654f8 100644--- a/src/activitypub/sendWorker.js+++ b/src/activitypub/sendWorker.js@@ -158,9 +158,9 @@ process.on('message', async (message) => {// Debug: log full request detailsif (DEBUG) {- winston.debug(`[activitypub/send] REQUEST uri=${uri}`);- winston.debug(`[activitypub/send] REQUEST headers=${JSON.stringify(headers)}`);- winston.debug(`[activitypub/send] REQUEST payload=${payload.substring(0, 500)}`);+ winston.verbose(`[activitypub/send] REQUEST uri=${uri}`);+ winston.verbose(`[activitypub/send] REQUEST headers=${JSON.stringify(headers)}`);+ winston.verbose(`[activitypub/send] REQUEST payload=${payload.substring(0, 500)}`);}// POST — redirect: 'manual' prevents SSRF via HTTP redirect@@ -209,8 +209,8 @@ process.on('message', async (message) => {// Debug: log full response detailsif (DEBUG) {- winston.debug(`[activitypub/send] RESPONSE status=${response.status} headers=${JSON.stringify(Object.fromEntries(response.headers.entries()))}`);- winston.debug(`[activitypub/send] RESPONSE body=${bodyText.substring(0, 1000)}`);+ winston.verbose(`[activitypub/send] RESPONSE status=${response.status} headers=${JSON.stringify(Object.fromEntries(response.headers.entries()))}`);+ winston.verbose(`[activitypub/send] RESPONSE body=${bodyText.substring(0, 1000)}`);}process.send({