perf: 历史图表的查询走独立的只读连接,不再挡住 agent 上报 - #85
Merged
Merged
Conversation
- 打开数据库时另开一条只读连接,`/api/nodes/{id}/metrics` 的资源、延迟、探测名称三个查询都走它。WAL 下它读的同时写连接照常提交,agent 上报和面板请求不再排在历史扫描后面
- 每次查询包在一个读事务里,水位线和它两侧的行来自同一个快照
- 只读连接先于写连接关闭,hub 正常停机后库仍是单个文件,不留 -wal
- `:memory:` 开不了第二条连接,测试库仍走写连接
- 历史闸门仍是 4 个,扫描改在只读连接上排队,闸门决定的是图表最长等多久
- 只读连接被接连的图表请求占着快照时,自动 checkpoint 重置不了 WAL。取读连接时若 WAL 超过 4 MiB,先在写连接上做一次 TRUNCATE checkpoint,不等待其他读者,导出备份时不会占住写连接 - 导出备份改用同一个只读连接的打开方式
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 free
to 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.
历史图表的查询改走一条只读连接,扫描再长也不会让 agent 上报和面板请求排队。
/api/nodes/{id}/metrics的资源、延迟、探测名称三个查询都走它。WAL 下它读的同时写连接照常提交:memory:开不了第二条连接,测试库仍走写连接测试
cargo fmt --check、cargo clippy --all-targets -- -D warnings、cargo test(132 个)通过;scripts/e2e.sh配 agent 1.1.0 通过/api/me,中位 1120 ms → 1.8 ms,最慢 1893 ms → 9.2 ms