From 94492180499c8600033d28148062a6633cb87369 Mon Sep 17 00:00:00 2001 From: KOBA789 Date: Fri, 5 Jan 2024 23:49:33 +0900 Subject: [PATCH] perf: Remove "process" queue stat counter for performance (MisskeyIO#325) --- packages/backend/src/boot/common.ts | 4 +-- .../backend/src/daemons/QueueStatsService.ts | 28 ++----------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/packages/backend/src/boot/common.ts b/packages/backend/src/boot/common.ts index ea8f615885..7bb09ca1aa 100644 --- a/packages/backend/src/boot/common.ts +++ b/packages/backend/src/boot/common.ts @@ -9,7 +9,6 @@ import { QueueProcessorService } from '@/queue/QueueProcessorService.js'; import { NestLogger } from '@/NestLogger.js'; import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js'; import { QueueStatsService } from '@/daemons/QueueStatsService.js'; -import { ServerStatsService } from '@/daemons/ServerStatsService.js'; import { ServerService } from '@/server/ServerService.js'; import { MainModule } from '@/MainModule.js'; @@ -24,8 +23,7 @@ export async function server() { if (process.env.NODE_ENV !== 'test') { app.get(ChartManagementService).start(); - // app.get(QueueStatsService).start(); - // app.get(ServerStatsService).start(); + app.get(QueueStatsService).start(); } return app; diff --git a/packages/backend/src/daemons/QueueStatsService.ts b/packages/backend/src/daemons/QueueStatsService.ts index ce87d94150..94329f4563 100644 --- a/packages/backend/src/daemons/QueueStatsService.ts +++ b/packages/backend/src/daemons/QueueStatsService.ts @@ -34,24 +34,8 @@ export class QueueStatsService implements OnApplicationShutdown { */ @bindThis public start(): void { - const log = [] as any[]; - ev.on('requestQueueStatsLog', x => { - ev.emit(`queueStatsLog:${x.id}`, log.slice(0, x.length ?? 50)); - }); - - let activeDeliverJobs = 0; - let activeInboxJobs = 0; - - const deliverQueueEvents = new Bull.QueueEvents(QUEUE.DELIVER, baseQueueOptions(this.config.redisForDeliverQueue, this.config.bullmqQueueOptions, QUEUE.DELIVER)); - const inboxQueueEvents = new Bull.QueueEvents(QUEUE.INBOX, baseQueueOptions(this.config.redisForInboxQueue, this.config.bullmqQueueOptions, QUEUE.INBOX)); - - deliverQueueEvents.on('active', () => { - activeDeliverJobs++; - }); - - inboxQueueEvents.on('active', () => { - activeInboxJobs++; + ev.emit(`queueStatsLog:${x.id}`, []); }); const tick = async () => { @@ -60,13 +44,13 @@ export class QueueStatsService implements OnApplicationShutdown { const stats = { deliver: { - activeSincePrevTick: activeDeliverJobs, + activeSincePrevTick: 0, // it's removed for performance reason active: deliverJobCounts.active, waiting: deliverJobCounts.waiting, delayed: deliverJobCounts.delayed, }, inbox: { - activeSincePrevTick: activeInboxJobs, + activeSincePrevTick: 0, // it's removed for performance reason active: inboxJobCounts.active, waiting: inboxJobCounts.waiting, delayed: inboxJobCounts.delayed, @@ -74,12 +58,6 @@ export class QueueStatsService implements OnApplicationShutdown { }; ev.emit('queueStats', stats); - - log.unshift(stats); - if (log.length > 200) log.pop(); - - activeDeliverJobs = 0; - activeInboxJobs = 0; }; tick();