Skip to content

perf(backend): add cache for sign post w/ LRU#17215

Open
nyanrus wants to merge 2 commits intomisskey-dev:developfrom
nyanrus:feat-cache-webcrypto
Open

perf(backend): add cache for sign post w/ LRU#17215
nyanrus wants to merge 2 commits intomisskey-dev:developfrom
nyanrus:feat-cache-webcrypto

Conversation

@nyanrus
Copy link
Copy Markdown

@nyanrus nyanrus commented Mar 5, 2026

What

WebCryptoに移行後、LRUでキャッシュしています。
fix #17214

Why

deliveryのスループット改善です。

Additional info (optional)

キーを扱うPRなので、セキュリティをもう一度確認をお願いします。

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

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 5, 2026
@github-actions github-actions bot added packages/backend Server side specific issue/PR packages/backend:test labels Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

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

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 35.29412% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.51%. Comparing base (78435dc) to head (7938c1d).
⚠️ Report is 221 commits behind head on develop.

Files with missing lines Patch % Lines
...s/backend/src/core/activitypub/ApRequestService.ts 35.29% 22 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #17215       +/-   ##
============================================
+ Coverage    13.97%   63.51%   +49.54%     
============================================
  Files          237     1161      +924     
  Lines        11273   116332   +105059     
  Branches      3728     8353     +4625     
============================================
+ Hits          1575    73889    +72314     
- Misses        7578    40257    +32679     
- Partials      2120     2186       +66     

☔ 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
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Backend memory usage comparison

Before GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 320.52 MB 314.80 MB -5.71 MB -1.78%
VmHWM 321.14 MB 314.80 MB -6.34 MB -1.97%
VmSize 23113.84 MB 23109.28 MB -4.56 MB -0.01%
VmData 1384.45 MB 1380.11 MB -4.33 MB -0.31%

After GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 320.53 MB 314.81 MB -5.72 MB -1.78%
VmHWM 321.14 MB 314.81 MB -6.33 MB -1.97%
VmSize 23114.25 MB 23109.28 MB -4.97 MB -0.02%
VmData 1384.87 MB 1380.11 MB -4.75 MB -0.34%

After Request

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 321.09 MB 315.14 MB -5.94 MB -1.85%
VmHWM 321.42 MB 315.14 MB -6.27 MB -1.95%
VmSize 23114.50 MB 23109.28 MB -5.22 MB -0.02%
VmData 1385.12 MB 1380.11 MB -5.00 MB -0.36%

See workflow logs for details

@kakkokari-gtyih kakkokari-gtyih changed the title fix(backend): add cache for sign post w/ LRU perf(backend): add cache for sign post w/ LRU Mar 5, 2026
@nyanrus nyanrus force-pushed the feat-cache-webcrypto branch from 3db9cd1 to 7938c1d Compare March 24, 2026 07:45
@nyanrus
Copy link
Copy Markdown
Author

nyanrus commented Mar 24, 2026

@kakkokari-gtyih 適切なメンション先がわからないので、失礼します。
https://gist.github.com/nyanrus/913bc34f725aab4e3247a6b98e5e1ad3
こちらって正常ですか?
package/backend > pnpm jestはAll passedとしては表示されるのですが、TypeErrorなので大丈夫なのかなと思っています。

あと、pnpm testはpassedになるので、上記の- [] Test working in a local environmentはチェックしたらいいですかね?

@kakkokari-gtyih
Copy link
Copy Markdown
Contributor

CIで通過しているため問題ないと思います
(私はバックエンドを見る人間ではないので詳細はわかりかねます)

@syuilo
Copy link
Copy Markdown
Member

syuilo commented Apr 15, 2026

どのくらいメモリ負荷が増えるか・スループット改善がそれに見合うかどうかが検証の必要ありそうですね

肌感覚ですがサーバーの規模が大きくなるほど(様々なアカウントが投稿するため)キャッシュヒット率が低下するのでメリットよりデメリットの方が目立ってきそうです。
となると小規模サーバー向け機能ということになりそうな気はします

(もしくは大規模でも、メモリ負荷よりもCPUなどの負荷低減の方を最優先したいサーバーでも活用はできそうですが)

@nyanrus
Copy link
Copy Markdown
Author

nyanrus commented Apr 15, 2026

大規模でも同じアカウントが複数連続投稿する場合をよく見るので、頻度数も込めてキャッシュを最適化すれば、使えるかもしれません。 :3
LRUで制限しているので、RAMもあまり増えないと思います。
ベンチマークはIssueにあるものを、月末に引っ張ってきます!

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 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

use LRU cache for sign posts

3 participants