Skip to content

perf: rsa sign on slacc - #17322

Merged
syuilo merged 16 commits into
developfrom
perf/rsa-sign-on-slacc
May 12, 2026
Merged

syuilo merged 16 commits into
developfrom
perf/rsa-sign-on-slacc

Conversation

@acid-chicken

@acid-chicken acid-chicken commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

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)

  • slacc の変更点については: misskey-dev/slacc@0d9e043...master
  • 運用者向け: threadPoolSize については基本的に 1 で良いです。特に、同一環境上に PostgreSQL などが同居していたりする状況でみだりにスレッドプール数を上げすぎてしまうと、スパイク時に頻繁なコンテキストスイッチで OOM などを引き起こして問題を発生させるリスクがあります。大規模なサーバで clusterLimit を CPU のコア数より減らして運用している場合などで初めて threadPoolSize の調整が効いてくるようになるかと思います。

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@acid-chicken acid-chicken self-assigned this Apr 17, 2026
Copilot AI review requested due to automatic review settings April 17, 2026 18:33
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 17, 2026
@github-actions github-actions Bot added the packages/backend Server side specific issue/PR label Apr 17, 2026
@codecov

codecov Bot commented Apr 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.00000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.88%. Comparing base (408d056) to head (221b55c).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
packages/backend/src/boot/common.ts 16.66% 3 Missing and 2 partials ⚠️
...s/backend/src/core/activitypub/ApRequestService.ts 77.77% 2 Missing ⚠️
...ages/backend/src/core/activitypub/JsonLdService.ts 0.00% 2 Missing ⚠️
packages/backend/src/boot/master.ts 0.00% 1 Missing ⚠️
packages/backend/src/boot/worker.ts 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Backend memory usage comparison

Before GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 304.44 MB 327.59 MB +23.15 MB +7.60%
VmHWM 304.44 MB 327.59 MB +23.15 MB +7.60%
VmSize 23081.89 MB 23173.52 MB +91.63 MB +0.39%
VmData 1348.50 MB 1374.08 MB +25.58 MB +1.89%

After GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 304.48 MB 327.60 MB +23.11 MB +7.59%
VmHWM 304.48 MB 327.60 MB +23.11 MB +7.59%
VmSize 23082.06 MB 23173.61 MB +91.55 MB +0.39%
VmData 1348.67 MB 1374.17 MB +25.50 MB +1.89%

After Request

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 305.06 MB 327.93 MB +22.86 MB +7.49%
VmHWM 305.06 MB 327.93 MB +22.86 MB +7.49%
VmSize 23082.31 MB 23173.61 MB +91.30 MB +0.39%
VmData 1348.92 MB 1374.17 MB +25.25 MB +1.87%

⚠️ Warning: Memory usage has increased by more than 5%. Please verify this is not an unintended change.

See workflow logs for details

@github-actions

github-actions Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) to 0.1.5 and adjust pnpm supply-chain delay exclusions.
  • Replace RSA signing in ActivityPub/JSON-LD signing paths to use slacc’s RSA implementation.
  • Add threadPoolSize config (default 1) 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

Comment thread packages/backend/src/config.ts Resolved
acid-chicken and others added 3 commits April 18, 2026 03:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 threadPoolSize configuration (default 1) 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

Comment thread packages/backend/src/boot/master.ts Resolved
Comment thread CHANGELOG.md Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@acid-chicken acid-chicken added 🐢Performance Efficiency related issue/PR 🔒Security Security related issue/PR labels Apr 17, 2026
@kakkokari-gtyih
kakkokari-gtyih force-pushed the perf/rsa-sign-on-slacc branch from fded18f to cd95e1e Compare April 20, 2026 06:15
@kakkokari-gtyih
kakkokari-gtyih requested a review from syuilo April 21, 2026 15:27
@kakkokari-gtyih
kakkokari-gtyih requested review from syuilo and removed request for syuilo April 27, 2026 11:30
@syuilo

syuilo commented May 7, 2026

Copy link
Copy Markdown
Member

/preview

@syuilo
syuilo merged commit b950f90 into develop May 12, 2026
39 checks passed
@syuilo
syuilo deleted the perf/rsa-sign-on-slacc branch May 12, 2026 08:36
@syuilo

syuilo commented May 12, 2026

Copy link
Copy Markdown
Member

👍

@github-project-automation github-project-automation Bot moved this from Todo to Done in [実験中] 管理用 May 12, 2026
anatawa12 added a commit to anatawa12/misskey that referenced this pull request May 18, 2026
* [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>
m10i1986 pushed a commit to foundation0-link/misskey-studio-version that referenced this pull request May 24, 2026
* 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>
m10i1986 pushed a commit to foundation0-link/misskey-studio-version that referenced this pull request May 24, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/backend:test packages/backend Server side specific issue/PR 🐢Performance Efficiency related issue/PR 🔒Security Security related issue/PR size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

4 participants