Repository navigation
perf: rsa sign on slacc - #17322
perf: rsa sign on slacc#17322
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #17322 +/- ##
===========================================
+ Coverage 15.22% 24.88% +9.66%
===========================================
Files 247 1153 +906
Lines 12322 39279 +26957
Branches 4170 10935 +6765
===========================================
+ Hits 1876 9775 +7899
- Misses 8183 23640 +15457
- Partials 2263 5864 +3601 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Backend memory usage comparisonBefore GC
After GC
After Request
|
|
このPRによるapi.jsonの差分 |
There was a problem hiding this comment.
Pull request overview
This PR migrates RSA signing in the backend to slacc@0.1.5 and introduces a configurable “extra” thread pool to offload CPU-bound signing work away from the Node.js event loop / libuv thread pool.
Changes:
- Upgrade
slacc(and platform-specific packages) to0.1.5and adjust pnpm supply-chain delay exclusions. - Replace RSA signing in ActivityPub/JSON-LD signing paths to use
slacc’s RSA implementation. - Add
threadPoolSizeconfig (default1) and initialize the extra thread pool during backend boot.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm-workspace.yaml |
Excludes slacc packages (and related) from minimum release age delay. |
pnpm-lock.yaml |
Locks slacc upgrade to 0.1.5 across platforms. |
packages/backend/package.json |
Bumps slacc and platform-specific optional deps to 0.1.5. |
packages/backend/src/core/activitypub/JsonLdService.ts |
Switches RSA signing to slacc (RsaKeyPair.sign). |
packages/backend/src/core/activitypub/ApRequestService.ts |
Switches HTTP signature signing to slacc (but introduces an async/signature mismatch to fix). |
packages/backend/src/config.ts |
Adds threadPoolSize config with defaulting in loadConfig(). |
packages/backend/src/boot/common.ts |
Introduces initExtraThreadPool() that calls slacc.init(threadPoolSize). |
packages/backend/src/boot/worker.ts |
Initializes extra thread pool on worker startup. |
packages/backend/src/boot/master.ts |
Initializes extra thread pool on master startup. |
chart/files/default.yml |
Documents new threadPoolSize config option. |
.devcontainer/devcontainer.yml |
Documents new threadPoolSize config option. |
.config/example.yml |
Documents new threadPoolSize config option. |
.config/docker_example.yml |
Documents new threadPoolSize config option. |
.config/cypress-devcontainer.yml |
Documents new threadPoolSize config option. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates RSA signing in the backend from node:crypto synchronous APIs to slacc@0.1.5, offloading CPU-bound signing work onto a managed thread pool, and introduces a new threadPoolSize config option to control that pool size.
Changes:
- Replace RSA signing implementation in ActivityPub request signing and JSON-LD signatures to use
slacc(async/offloaded). - Add and initialize
threadPoolSizeconfiguration (default1) and wire thread-pool initialization into boot + unit test runtime. - Update dependency manifests/lockfile and document the new config option in examples + changelog.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm-workspace.yaml |
Excludes slacc packages (and related) from minimum release age delay. |
pnpm-lock.yaml |
Updates slacc and platform packages to 0.1.5 with new engine constraints. |
packages/backend/package.json |
Bumps slacc and platform-specific optional deps to 0.1.5. |
packages/backend/src/core/activitypub/ApRequestService.ts |
Makes request signing async and routes RSA signing through slacc (RsaKeyPair.sign). |
packages/backend/src/core/activitypub/JsonLdService.ts |
Routes RsaSignature2017 signing through slacc while keeping verification via node:crypto. |
packages/backend/src/config.ts |
Adds threadPoolSize to config types and loads it with a default of 1. |
packages/backend/src/boot/common.ts |
Adds initExtraThreadPool() wrapper around slacc.init() with a one-time guard. |
packages/backend/src/boot/worker.ts |
Initializes the extra thread pool early in worker startup. |
packages/backend/src/boot/master.ts |
Initializes the extra thread pool in master startup as well. |
packages/backend/jest.config.unit.cjs |
Uses a custom Jest test environment for unit tests. |
packages/backend/test/jest.environment.unit.cjs |
Initializes slacc thread pool for unit tests (init(1)). |
packages/backend/test/unit/ap-request.ts |
Updates unit tests to await the now-async signing helpers. |
chart/files/default.yml |
Documents threadPoolSize in the chart default config. |
.devcontainer/devcontainer.yml |
Documents threadPoolSize in devcontainer config. |
.config/example.yml |
Documents threadPoolSize in the example config. |
.config/docker_example.yml |
Documents threadPoolSize in the docker example config. |
.config/cypress-devcontainer.yml |
Documents threadPoolSize in the cypress devcontainer config. |
CHANGELOG.md |
Notes the new threadPoolSize option and mentions RSA signing offload. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
fded18f to
cd95e1e
Compare
|
/preview |
|
👍 |
* [skip ci] Update CHANGELOG.md (prepend template) * enhance(frontend): テーマの適用管理を改善 (misskey-dev#17376) * wip * add test * use themeManager.currentCompiledTheme for obtaining theme variables / reduce getComputedStyle usage * fix * fix: better error handling on theme installation * Update Changelog * chore: remove frontend-shared builds as it is currently working as a stub package * fix: broken lockfile * fix * fix lint * fix * Update CHANGELOG.md * enhance(frontend): MkInputでthrottleできるように & delay設定できるように * fix(frontend): ドライブのファイル更新が即座に反映されない問題の修正 (misskey-dev#17383) * enhance: 絵文字データの参照を自前ライブラリに変更 (misskey-dev#17381) * wip * enhance: 絵文字データの参照を自前ライブラリに変更 * fix * update to v17.0.2 * fix assets handling * fix * update mfm-js * update emoji library * Update COPYING [ci skip] * Update Changelog * Update Changelog * fix: 端末の絵文字にフォールバックできるように * Fix: リスト編集画面におけるユーザー追加時のユーザー選択ダイアログにおいて、自身のアカウントが検索結果の一覧に表示されない問題を修正 (misskey-dev#17386) * fix(frontend): cannot add self to list by selectUser dialog * docs(changelog): update changelog * fix(frontend): デッキのカラムから開いたアンテナ・リストの編集ウィンドウを、"ポップアウト"、"新しいタブで表示"、"リンクをコピー"した場合に誤ったリンクが与えられる問題を修正 (misskey-dev#17384) * fix(frontend): incorrect page link for deck pageWindow * docs(changelog): update changelog * fix(frontend): missing はい/いいえ in base-role 「チャンネルの作成」 header (misskey-dev#17380) * Initial plan * fix(frontend): show base-role value text for channel creation policy Agent-Logs-Url: https://github.com/misskey-dev/misskey/sessions/c4fcb1b7-eb6e-444b-bbdf-9b367bc13544 Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> * Update changelog [ci skip] * fix --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> * perf: rsa sign on slacc (misskey-dev#17322) * perf: rsa sign on slacc * fix: missing async/await * fix: threadPoolSize is always number Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * test(backend): init slacc in unit setup and await ap-request signing * test(backend): move slacc init to unit testEnvironment * test(backend): delete unused file * docs: update CHANGELOG * docs: fix indent Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * chore: migrate to vitest * fix * fix: fix changelog * chore: regenerate lockfile * docs: changelog --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> * docs: AI コーディングエージェント共通設定を追加 (misskey-dev#17396) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> * Bump version to 2026.5.2-alpha.0 * feat: 投稿通知設定したユーザーをリストで見ることができるように (misskey-dev#17385) * feat: 投稿通知を設定したユーザーをリストで見ることができるように * test(e2e): 投稿通知のテスト追加 * chore: 不必要なコードの削除 * Update CHANGELOG.md * Bump version to 2026.5.2-beta.0 * deps: update dependencies (misskey-dev#17400) * deps: Update Dependencies * run pnpm dedupe * update some major packages * update to pnpm v11 * update systeminformation * fix indent * fix: rollback sharp to 0.33 * update re2 * fix(deps): update dependency sanitize-html to v2.17.4 [security] [ci skip] (misskey-dev#17402) * fix(deps): update dependency sanitize-html to v2.17.4 [security] * fix minimumReleaseAgeExclude --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> * fix(deps): broken lockfile (misskey-dev#17404) * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Update CHANGELOG.md * fix: move `users/notify/list` to `following/list` (misskey-dev#17416) * fix: move `users/notify/list` to `following/list` * fix * fix lint * fix test * fix test * fix test title * Bump version to 2026.5.2-beta.1 * fix: add-i18n-keyの記述が間違っていたので修正 (misskey-dev#17418) * Release: 2026.5.2 * [skip ci] Update CHANGELOG.md (prepend template) * Update about-misskey.vue * fix(docker): runnerでのpnpmの依存関係チェックを無効化 (misskey-dev#17425) * fix(docker): runnerでのpnpmの依存関係チェックを無効化 * Update Changelog * update changelog * Bump version to 2026.5.3-alpha.0 * Release: 2026.5.3 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: 4ster1sk <146138447+4ster1sk@users.noreply.github.com> Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Acid Chicken <root@acid-chicken.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* perf: rsa sign on slacc * fix: missing async/await * fix: threadPoolSize is always number Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * test(backend): init slacc in unit setup and await ap-request signing * test(backend): move slacc init to unit testEnvironment * test(backend): delete unused file * docs: update CHANGELOG * docs: fix indent Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * chore: migrate to vitest * fix * fix: fix changelog * chore: regenerate lockfile * docs: changelog --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
* perf: rsa sign on slacc * fix: missing async/await * fix: threadPoolSize is always number Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * test(backend): init slacc in unit setup and await ap-request signing * test(backend): move slacc init to unit testEnvironment * test(backend): delete unused file * docs: update CHANGELOG * docs: fix indent Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * chore: migrate to vitest * fix * fix: fix changelog * chore: regenerate lockfile * docs: changelog --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
RSA 署名処理に slacc@0.1.5 を使用する
What
slacc に rayon ベースのスレッドプールを用意し、aws_lc_rs を使用して RSA 署名処理をそちらに退避させる。また、このスレッドプールのスレッド数の設定を config に
threadPoolSizeとして追加。この設定値はデフォルトで 1 で、ワーカーごとに指定した数のスレッドプールが作られる。Why
従前の RSA 署名処理は
node:cryptoを使用していて、これは同期処理なのでイベントループをブロックする。Web Crypto API に移行して非同期処理にしても、内部的には libuv のスレッドでブロッキングされ、他の libuv のスレッドに待避する処理が詰まる。そもそもこの libuv のスレッド数はデフォルトで 4 であり、何も考えずにこちらに退避させると最悪の場合 clusterLimit * 4 スレッドで CPU バウンドな署名処理が走り、スパイクを重篤化させる可能性がある(皮肉にも同期処理のおかげで回避されてきたともいえる)。
slacc に managed なスレッドプールを作り、こちらにこの CPU バウンドな処理を積むことで、libuv のスレッドで I/O バウンドな処理が詰まることなく、イベントスレッドがブロックされないようにできる。
Additional info (optional)
threadPoolSizeについては基本的に1で良いです。特に、同一環境上に PostgreSQL などが同居していたりする状況でみだりにスレッドプール数を上げすぎてしまうと、スパイク時に頻繁なコンテキストスイッチで OOM などを引き起こして問題を発生させるリスクがあります。大規模なサーバでclusterLimitを CPU のコア数より減らして運用している場合などで初めてthreadPoolSizeの調整が効いてくるようになるかと思います。Checklist