From 239d3f2dbfb602c20a8bcc89b0be2eeedcc6f3ae Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 7 Apr 2023 11:27:01 +0900 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E3=82=B8=E3=83=A7=E3=83=96?= =?UTF-8?q?=E3=82=AD=E3=83=A5=E3=83=BC=E7=94=A8Redis=E3=82=92=E5=88=A5?= =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC=E3=81=AB=E5=88=86=E9=9B=A2?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/docker_example.yml | 8 ++++++++ .config/example.yml | 8 ++++++++ .devcontainer/devcontainer.yml | 8 ++++++++ CHANGELOG.md | 1 + chart/files/default.yml | 8 ++++++++ packages/backend/src/config.ts | 11 +++++++++++ packages/backend/src/core/QueueModule.ts | 12 ++++++------ 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 13ecfac549..d93cc8b70e 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -70,6 +70,14 @@ redis: # #prefix: example-prefix # #db: 1 +#redisForJobQueue: +# host: redis +# port: 6379 +# #family: 0 # 0=Both, 4=IPv4, 6=IPv6 +# #pass: example-pass +# #prefix: example-prefix +# #db: 1 + # ┌─────────────────────────────┐ #───┘ Elasticsearch configuration └───────────────────────────── diff --git a/.config/example.yml b/.config/example.yml index fbdb7b0241..b61ed14809 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -70,6 +70,14 @@ redis: # #prefix: example-prefix # #db: 1 +#redisForJobQueue: +# host: localhost +# port: 6379 +# #family: 0 # 0=Both, 4=IPv4, 6=IPv6 +# #pass: example-pass +# #prefix: example-prefix +# #db: 1 + # ┌─────────────────────────────┐ #───┘ Elasticsearch configuration └───────────────────────────── diff --git a/.devcontainer/devcontainer.yml b/.devcontainer/devcontainer.yml index 4cc7ae3b59..1350e70157 100644 --- a/.devcontainer/devcontainer.yml +++ b/.devcontainer/devcontainer.yml @@ -70,6 +70,14 @@ redis: # #prefix: example-prefix # #db: 1 +#redisForJobQueue: +# host: redis +# port: 6379 +# #family: 0 # 0=Both, 4=IPv4, 6=IPv6 +# #pass: example-pass +# #prefix: example-prefix +# #db: 1 + # ┌─────────────────────────────┐ #───┘ Elasticsearch configuration └───────────────────────────── diff --git a/CHANGELOG.md b/CHANGELOG.md index 28be3faff9..03cf179a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ ### Server - イベント用Redisを別サーバーに分離できるように +- ジョブキュー用Redisを別サーバーに分離できるように - サーバーの全体的なパフォーマンスを向上 - ノート作成時のパフォーマンスを向上 - アンテナのタイムライン取得時のパフォーマンスを向上 diff --git a/chart/files/default.yml b/chart/files/default.yml index afaf8a162d..1d8e5b490a 100644 --- a/chart/files/default.yml +++ b/chart/files/default.yml @@ -91,6 +91,14 @@ redis: # #prefix: example-prefix # #db: 1 +#redisForJobQueue: +# host: localhost +# port: 6379 +# #family: 0 # 0=Both, 4=IPv4, 6=IPv6 +# #pass: example-pass +# #prefix: example-prefix +# #db: 1 + # ┌─────────────────────────────┐ #───┘ Elasticsearch configuration └───────────────────────────── diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index e8554e5c84..fd2b83cf2a 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -41,6 +41,14 @@ export type Source = { db?: number; prefix?: string; }; + redisForJobQueue?: { + host: string; + port: number; + family?: number; + pass: string; + db?: number; + prefix?: string; + }; elasticsearch: { host: string; port: number; @@ -99,6 +107,8 @@ export type Mixin = { mediaProxy: string; externalMediaProxyEnabled: boolean; videoThumbnailGenerator: string | null; + redisForPubsub: NonNullable; + redisForJobQueue: NonNullable; }; export type Config = Source & Mixin; @@ -160,6 +170,7 @@ export function loadConfig() { if (!config.redis.prefix) config.redis.prefix = mixin.host; if (config.redisForPubsub == null) config.redisForPubsub = config.redis; + if (config.redisForJobQueue == null) config.redisForJobQueue = config.redis; return Object.assign(config, mixin); } diff --git a/packages/backend/src/core/QueueModule.ts b/packages/backend/src/core/QueueModule.ts index edd843977b..8733a7d7eb 100644 --- a/packages/backend/src/core/QueueModule.ts +++ b/packages/backend/src/core/QueueModule.ts @@ -8,13 +8,13 @@ import type { DeliverJobData, InboxJobData, DbJobData, ObjectStorageJobData, End function q(config: Config, name: string, limitPerSec = -1) { return new Bull(name, { redis: { - port: config.redis.port, - host: config.redis.host, - family: config.redis.family == null ? 0 : config.redis.family, - password: config.redis.pass, - db: config.redis.db ?? 0, + port: config.redisForJobQueue.port, + host: config.redisForJobQueue.host, + family: config.redisForJobQueue.family == null ? 0 : config.redisForJobQueue.family, + password: config.redisForJobQueue.pass, + db: config.redisForJobQueue.db ?? 0, }, - prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : 'queue', + prefix: config.redisForJobQueue.prefix ? `${config.redisForJobQueue.prefix}:queue` : 'queue', limiter: limitPerSec > 0 ? { max: limitPerSec, duration: 1000,