Repository navigation
perf(report): 修复报表加载极慢/假死——默认刷新调至 30 秒、精简指标查询并补齐聚合索引 - #278
Open
YouYangDaShu wants to merge 1 commit into
Open
YouYangDaShu wants to merge 1 commit into
YouYangDaShu wants to merge 1 commit into
Conversation
1. 优化:停留在「报表」页时的默认自动刷新间隔由 1 秒调整为 30 秒(DEFAULT_REPORT_AUTO_REFRESH_SECONDS: 30),避免高频轮询打爆数据库读锁与 CPU 2. 优化:报表计算缓存命中率与 24 小时趋势时改用精简指标查询(CacheMetricEntry),仅投影 6 列必要字段,不再反序列化 attempt_details、sensitive_hits 等大文本 JSON 3. 优化:补齐 requests 聚合复合索引 idx_requests_summary (is_test, ts, row_id)(schema v15),消除报表时间范围扫描的文件排序与全表遍历 4. 构建:重建前端产物 ui.js,同步 report-page.tsx 改动
coulsontl
added a commit
to coulsontl/agent2api
that referenced
this pull request
Oct 18, 2026
来源:上游 PR aimod-cc#278(YouYangDaShu,perf(report))。 该 PR 的其余两部分在我们这边已被上游后续版本覆盖且方案更优: - 聚合索引 idx_requests_summary 已随 v15 schema 落地,且多一条 idx_requests_status - 四档缓存命中率改由 SQL 侧 sum_cache_windows 一次聚合(优于该 PR 的 Rust 侧遍历) 因此只取仍缺失的这一项:秒级轮询会把数据库读锁与 CPU 一起顶上去, 30 秒对「看报表」足够,用户仍可在设置页改回。
coulsontl
added a commit
to coulsontl/agent2api
that referenced
this pull request
Oct 18, 2026
…刷新间隔) - aimod-cc#305(406722575):商汤日日新预置 Base URL 改为 https://token.sensenova.cn/v1 - aimod-cc#310(coulsontl):AI 助手工具链对自定义提供商支持不完整 - aimod-cc#278(YouYangDaShu):报表页默认自动刷新由 1 秒改 30 秒 (该 PR 的聚合索引与缓存查询精简已被上游后续版本以更优方案覆盖)
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.
现象
当网关运行数天积累较多请求记录(数万条)后,停留在「报表」页时会出现页面加载极慢、接口超时,甚至导致程序 CPU 满载、系统负载极高、其他接口响应受阻。
成因
经排查,由以下三点叠加引发雪崩效应:
DEFAULT_REPORT_AUTO_REFRESH_SECONDS与前端DEFAULT_AUTO_REFRESH_MS默认为 1 秒。用户停留在报表页时,前端每隔 1 秒即发起一次/api/stats/summary。在
usage_summary内部计算缓存命中率(cache_rates)与 24 小时整点趋势(cache_trend_24h)时,硬编码调用了sql::select_between(conn, now - SUMMARY_WINDOW_MS, now, true),将过去 7 天内的全部明细整行全量捞出(包含attempt_details、sensitive_hits等每条记录几 KB 至十几 KB 的重试大 JSON 文本),单次反序列化数万条大记录耗时 1~2 秒并大量占用内存与持有读锁。由于单次后端查询耗时(1~2 秒)超过了前端的轮询周期(1 秒),新请求在上一轮尚未结束时密集到达,在 SQLite 上串行持锁排队堆叠,引发 CPU 满载与假死。
现有索引仅有
idx_requests_ts,对于WHERE ts >= ? AND ts <= ? AND is_test = 0范围查询,无法利用索引过滤测试数据,仍需逐行回表检查。修法
DEFAULT_REPORT_AUTO_REFRESH_SECONDS与前端DEFAULT_AUTO_REFRESH_MS默认值由 1 秒调整为合理的 30 秒,从源头杜绝高频请求堆叠。CacheMetricEntry,在sql::select_cache_metrics_between中只投影ts, prompt_tokens, total_tokens, cache_read_tokens, model, upstream_model6 列标量字段;attempt_details、sensitive_hits、route、error等大文本字段的反序列化,内存分配减少 90% 以上,查询速度提升数十倍。idx_requests_summary (is_test, ts, row_id)复合索引;ui/islands/ui.js,确保前端产物与源码严格同源,满足frontend-artifactsCI 门禁。验证
tsc --noEmit && vite build重新编译,无类型错误;