summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2021-08-20 21:59:03 +0900
committerGitHub <noreply@github.com>2021-08-20 21:59:03 +0900
commitbb2db1cf76a94af9133017897db5e4952b0d1532 (patch)
treed81835924f4ae3b49b7590a41be2b6148a8a3354
parentdoc: add features/word-mute (#7672) (diff)
downloadsharkey-bb2db1cf76a94af9133017897db5e4952b0d1532.tar.gz
sharkey-bb2db1cf76a94af9133017897db5e4952b0d1532.tar.bz2
sharkey-bb2db1cf76a94af9133017897db5e4952b0d1532.zip
perf: Tune AP job queue timings (#7635)
* perf: Tune AP job queue timings * CHANGELOG * chore: add reference Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/queue/index.ts6
-rw-r--r--src/queue/initialize.ts21
3 files changed, 21 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88dc308f0e..47372dda56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
### Improvements
- 依存関係の更新
- localStorageのaccountsはindexedDBで保持するように
+- ActivityPub: ジョブキューの試行タイミングを調整 (#7635)
### Bugfixes
- チャンネルを作成しているとアカウントを削除できないのを修正
diff --git a/src/queue/index.ts b/src/queue/index.ts
index 2facd9c8e1..ff96c0fb15 100644
--- a/src/queue/index.ts
+++ b/src/queue/index.ts
@@ -73,8 +73,7 @@ export function deliver(user: ThinUser, content: unknown, to: string | null) {
attempts: config.deliverJobMaxAttempts || 12,
timeout: 1 * 60 * 1000, // 1min
backoff: {
- type: 'exponential',
- delay: 60 * 1000
+ type: 'apBackoff'
},
removeOnComplete: true,
removeOnFail: true
@@ -91,8 +90,7 @@ export function inbox(activity: IActivity, signature: httpSignature.IParsedSigna
attempts: config.inboxJobMaxAttempts || 8,
timeout: 5 * 60 * 1000, // 5min
backoff: {
- type: 'exponential',
- delay: 60 * 1000
+ type: 'apBackoff'
},
removeOnComplete: true,
removeOnFail: true
diff --git a/src/queue/initialize.ts b/src/queue/initialize.ts
index 5fe5a9f6f3..31102a3ed2 100644
--- a/src/queue/initialize.ts
+++ b/src/queue/initialize.ts
@@ -11,8 +11,23 @@ export function initialize<T>(name: string, limitPerSec = -1) {
},
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : 'queue',
limiter: limitPerSec > 0 ? {
- max: limitPerSec * 5,
- duration: 5000
- } : undefined
+ max: limitPerSec,
+ duration: 1000
+ } : undefined,
+ settings: {
+ backoffStrategies: {
+ apBackoff
+ }
+ }
});
}
+
+// ref. https://github.com/misskey-dev/misskey/pull/7635#issue-971097019
+function apBackoff(attemptsMade: number, err: Error) {
+ const baseDelay = 60 * 1000; // 1min
+ const maxBackoff = 8 * 60 * 60 * 1000; // 8hours
+ let backoff = (Math.pow(2, attemptsMade) - 1) * baseDelay;
+ backoff = Math.min(backoff, maxBackoff);
+ backoff += Math.round(backoff * Math.random() * 0.2);
+ return backoff;
+}