perf: Remove "process" queue stat counter for performance (MisskeyIO#325)

This commit is contained in:
KOBA789 2024-01-05 23:49:33 +09:00 committed by GitHub
parent 397e056b1e
commit 9449218049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 28 deletions

View file

@ -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;

View file

@ -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();