Skip to content

[Performance] 数据库同步/异步与 ORM 性能基准和回归门禁 #95

Description

@Antruly

父任务:#88

目标

证明 ORM 没有把数据库访问拖慢,并且底层 db 模块的同步、异步路径在 1.12.0 没有回退。性能不达标就不发布 1.12.0。

基线

以现有 bench/bench_db.cpp 和 1.11.0 的数据库读数为基线;新增 ORM 基准必须在同一台机器、同一数据库版本、同一编译配置、同一连接数下对比。

至少记录:

  • uvcpp_db_client 同步查询:QPS、p50/p95/p99、CPU、分配次数
  • uvcpp_db_pool 异步查询:线程池路径与 PostgreSQL 真异步路径分开
  • 连接池 1 / 4 / 16 条连接;并发 1 / 16 / 64
  • 事务:提交、回滚、冲突、超时
  • ORM 端到端:SQL 生成 + 参数绑定 + 映射 + 数据库调用
  • ORM 纯开销:只生成 SQL、只映射结果,不连数据库
  • 大结果集(行数/列数)与 BLOB;小结果集高频查询
  • SQLite / MySQL / PostgreSQL;ODBC 到 SQLite 作为补充
  • Windows MSVC 至少跑一次 SQLite 基线,确认没有平台性退化

验收预算

  • ORM 相对等价手写 SQL 的端到端 p50/p99 额外开销:目标 ≤ 15%,不得 > 25%
  • ORM 纯映射/构造成本:目标 ≤ 10 µs/行(以基准机为准),不得随字段数超线性增长
  • db 模块相对 1.11.0 基线:吞吐回退不得 > 5%,p99 回退不得 > 10%
  • 连接池并发 16/64 时不得出现串行化、死锁或超时率上升
  • PostgreSQL 真异步不得退化到线程池路径;CPU/请求不得高于线程池路径
  • 结果集扩大 10 倍时内存增长必须可解释,不得出现整表重复拷贝

阈值是发布门禁;如果基准机噪声大,用同一轮交替 A/B、取中位数,并在报告中写明置信区间和原始数据。

交付物

  • bench/bench_orm.cpp(或扩展现有 bench_db.cpp)
  • 可重复的基准脚本,输出 JSON/CSV 原始数据
  • doc/benchmark.md 增加 ORM 与 db 同步/异步章节
  • CI:共享 runner 只做“能跑 + 无崩溃”;稳定基准在固定机器/夜间任务跑,回归 > 阈值时报警但不伪装成单元测试失败
  • 1.12.0 RC 的基准报告,含基线、命令、硬件、数据库版本、原始数据

明确不做

  • 用微基准替代真实数据库端到端测试
  • 用共享 CI 的抖动数字当发布结论
  • 为了数字漂亮而缓存查询结果或改变事务语义
  • 在 1.12.0 做查询计划优化器/预编译缓存

依赖

PR 要求

  • 分支:perf/orm-bench
  • 标题:perf(orm): add database and ORM benchmarks
  • PR 附原始 JSON/CSV、复现命令、硬件/DB 版本、A/B 对比
  • 至少一位维护者 review;性能未达标不得标记完成

Activity

  1. added this to the 1.12.0 milestone on Nov 27, 2026
  2. added
    enhancement
    on Nov 27, 2026
  3. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    PR #97 delivered the existing-db baseline driver and methodology only. ORM end-to-end/pure-overhead numbers, p95, MySQL/PostgreSQL and fixed-runner regression gates remain open; this issue should stay open until those are measured.

  4. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    PR #105 added the SQLite ORM A/B benchmark; on the optimized code the development-machine p50/p99 results are within 15% for pk/find_all/update/insert/remove. This is still not the release gate: no fixed performance runner, no p95, no MySQL/PostgreSQL/ODBC, no pool/concurrency/async latency. Keep open until those are measured.

  5. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    Current benchmark evidence is SQLite-only on a powersave development machine (3 rounds, 500 samples/arm). After #103/#104 all end-to-end p50/p99 cases are within 15% on that machine, but a fixed performance runner, p95, pool/concurrency/async latency, and MySQL/PostgreSQL performance are still not measured; release gate remains open.

  6. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    Dev-machine 3-round A/B remains target_met for all end-to-end cases (pk p50 +4.70% / p99 +8.59%, find_all +8.65% / +13.11%; writes ~0). Evidence: /tmp/orm-overhead-final2/orm-overhead-20261127T063811Z, summary.json sha256 e20d2ab9...c126a. Still not a release gate: powersave/unbound machine, no p95, no fixed runner, no 1.11.0 same-machine db baseline, no MySQL/PG perf numbers. Keep open.

  7. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    Additional local evidence: bench_db was built with MySQL/PostgreSQL/ODBC and run against real MySQL 8.0.46 and PostgreSQL 16.15 at 10,000 rows. MySQL: point select 5,526 calls/s, insert in txn 6,918 rows/s, fetch 10k rows 1,059,314 rows/s, sync loop gap 505,947 us vs async ~1,8xx us; PostgreSQL: point select 12,448 calls/s, insert in txn 7,824 rows/s, fetch 10k rows 1,539,075 rows/s, sync gap 505,325 us vs async ~1,8xx us. Logs: /tmp/bench-mysql.log and /tmp/bench-pg.log. This is db-layer data on a powersave dev machine; ORM A/B for MySQL/PostgreSQL, p95 and a fixed runner are still missing.

  8. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    Same-machine SQLite db baseline, 1.11.0 source vs current master: v1.11.0 point select(param) 6.7 us / 148,819 calls/s, insert-in-txn 190k–240k rows/s, fetch 10k 2.16–3.19M rows/s, pool(4) 239,146 calls/s; current 1.12 6.1 us / 163,337 calls/s, insert-in-txn 235k–265k rows/s, fetch 10k 2.48–2.97M rows/s, pool(4) 235,840 calls/s. Point select improved; pool -1.4%, within the 5% budget. Logs /tmp/bench-1110.log and /tmp/bench-120.log. Still no p95/fixed runner/ORM A/B on MySQL/PostgreSQL.

  9. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    1.11.0 same-machine SQLite baseline completed: v1.11.0 point select 6.7 us / 148,819 calls/s, insert-in-txn 190k–240k rows/s, fetch10k 2.16–3.19M rows/s, pool(4) 239,146 calls/s; current 1.12 6.1 us / 163,337, 235k–265k, 2.48–2.97M, 235,840 (-1.4%, within 5%). Logs /tmp/bench-1110.log and /tmp/bench-120.log. No p95/fixed runner or MySQL/PostgreSQL ORM A/B yet.

  10. Antruly commented on Nov 27, 2026

    @Antruly
    OwnerAuthor

    Closing for v1.12.0 with the release evidence: development-machine 3-round ORM A/B target_met; 1.11.0 same-machine SQLite db comparison within budget; MySQL/PostgreSQL db baselines measured; fixed-runner p95 and MySQL/PG ORM A/B are explicitly documented as not release claims. v1.12.0 is published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions