Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune queue limit #2488

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ autoAdmin: true
# Number of worker processes
#clusterLimit: 1

# Job concurrency per worker
# Job concurrency per worker (Default: deliver=cpu x 8, inbox=cpu x 1)
# deliverJobConcurrency: 128
# inboxJobConcurrency: 16

# Job rate limiter
# Job rate limiter (Default: nolimit, 変更しないことを推奨)
# deliverJobPerSec: 128
# inboxJobPerSec: 16

Expand Down
10 changes: 8 additions & 2 deletions src/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DriveFile } from '../models/entities/drive-file';
import { getJobInfo } from './get-job-info';
import { IActivity } from '../remote/activitypub/type';
import { dbQueue, deliverQueue, inboxQueue, objectStorageQueue } from './queues';
import { cpus } from 'os';

function renderError(e: Error): any {
return {
Expand All @@ -27,6 +28,9 @@ const inboxLogger = queueLogger.createSubLogger('inbox');
const dbLogger = queueLogger.createSubLogger('db');
const objectStorageLogger = queueLogger.createSubLogger('objectStorage');

export const deliverJobConcurrency = config.deliverJobConcurrency || ((cpus().length || 4) * 8);
export const inboxJobConcurrency = config.inboxJobConcurrency || ((cpus().length || 4) * 1);

deliverQueue
.on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`))
.on('active', (job) => deliverLogger.debug(`active ${getJobInfo(job, true)} to=${job.data.to}`))
Expand Down Expand Up @@ -207,8 +211,8 @@ export function createCleanRemoteFilesJob() {

export default function() {
if (!envOption.onlyServer) {
deliverQueue.process(config.deliverJobConcurrency || 128, processDeliver);
inboxQueue.process(config.inboxJobConcurrency || 16, processInbox);
deliverQueue.process(deliverJobConcurrency, processDeliver);
inboxQueue.process(inboxJobConcurrency, processInbox);
processDb(dbQueue);
procesObjectStorage(objectStorageQueue);
}
Expand All @@ -219,9 +223,11 @@ export function destroy() {
deliverLogger.succ(`Cleaned ${jobs.length} ${status} jobs`);
});
deliverQueue.clean(0, 'delayed');
deliverQueue.clean(0, 'wait');

inboxQueue.once('cleaned', (jobs, status) => {
inboxLogger.succ(`Cleaned ${jobs.length} ${status} jobs`);
});
inboxQueue.clean(0, 'delayed');
inboxQueue.clean(0, 'wait');
}
4 changes: 2 additions & 2 deletions src/queue/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import config from '../config';
import { initialize as initializeQueue } from './initialize';
import { DbJobData, DeliverJobData, InboxJobData, ObjectStorageJobData } from './types';

export const deliverQueue = initializeQueue<DeliverJobData>('deliver', config.deliverJobPerSec || 128);
export const inboxQueue = initializeQueue<InboxJobData>('inbox', config.inboxJobPerSec || 16);
export const deliverQueue = initializeQueue<DeliverJobData>('deliver', config.deliverJobPerSec || -1);
export const inboxQueue = initializeQueue<InboxJobData>('inbox', config.inboxJobPerSec || -1);
export const dbQueue = initializeQueue<DbJobData>('db');
export const objectStorageQueue = initializeQueue<ObjectStorageJobData>('objectStorage');