fix(perf): warm NFS sqlite with 64MB cache + transactions indexes + parallel trend (rant 2026-08-25T12:02:13) - #150
Merged
Conversation
…arallel trend (rant 2026-08-25T12:02:13)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the slow transactions page caused by the dev database living on NFS (Aliyun NAS). Browser-measured
/api/transactions1.7s, page refresh ~5s.Rant:
2026-08-25T12:02:13— 交易页慢(dev 库在 NFS):调大 SQLite 页缓存 + 建索引 + 前端并行拉 trendRoot cause (verified on dev)
cache_sizeis 2MB < DB 2.8MB;db.rs open()set no PRAGMAs → every query re-reads pages from the remote NFS volume (cold read ~0.93s/COUNT vs 26ms on local SSD).transactionshad zero indexes → summary/COUNT/list full-table scans + 3 LEFT JOINs (dev: 23079 rows).loadTransactionsawaited the list before fetching trend → one extra ~0.9s serial hop per page load.Verified fix on NAS (3 consecutive COUNTs): default cache 2.39s →
cache_size=64MB0.80s → 64MB+mmap 0.40s (fully hot after first read).Changes
src/db.rs:open()now setsPRAGMA cache_size=-65536(64MB) andPRAGMA mmap_size=67108864— whole DB resident in process memory, NFS read once.transactions:(user_id),(user_id, id DESC),(user_id, time),(user_id, type).transactions_perf_indexes_created_on_migrateasserts all 4 indexes exist.ui/js/app.js:loadTransactionsfetches list + trend withPromise.all— failures are independent (list failure → empty state + retry; trend failure →trend=null), behavior preserved.ui/index.html: cache-bust20260825-3→20260825-4.Constraints honored
Tests
cargo test— 148/148 pass (147 + 1 new)cargo fmt --checkcleannode --check ui/js/app.jsOK