Skip to content

Reduce idle startup allocations in embedded race UT - #29067

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/ut-single-runner-efficiency
Sep 17, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/ut-single-runner-efficiency

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #28419. This addresses unnecessary allocation in the existing single-runner race UT workload; it does not claim to resolve every timeout covered by that issue.

What this PR does / why we need it:

Remove unused startup allocations instead of adding runners or weakening tests. A real single-CN race-test profile retained 532 MiB of Go heap, including roughly 204 MiB of eagerly allocated WAL records, 92 MiB of disabled transaction-trace queues, and 101 MiB from FIFO cache construction.

Changes

  1. Allocate WAL payloads on first append. Keep eager backend connections, pool size, factory retries, write tokens, record headers, exact payload lengths and subsequent growth/return behavior. Idle/read-only clients do not need a payload record. This also applies outside tests.
  2. Size embedded testing trace queues explicitly. An unset CN trace buffer becomes 1024 entries in WithTesting mode, before scenario callbacks. Explicit overrides, added CNs and non-testing defaults retain their intended behavior. Tracing remains enabled-capable with blocking backpressure, not dropped events.
  3. Grow FIFO indexes with occupancy. Keep non-nil shard maps but remove the fixed 1024-entry hint in each of 256 shards. Locks, callbacks, logical capacity, eviction and ghost/pending accounting are unchanged. This also applies outside tests.

No changes to runner count, scheduling/concurrency, admission, CN topology, package selection, timeouts, race instrumentation or coverage collection. No tests or assertions removed.

Local measurements

macOS/arm64, Go 1.26.4, base e66c9da813ccbb8b9d1eedbdc40b619b7ee5dff3; prebuilt race executables separate execution from compilation.

Workload / metric Base Candidate
Single-CN SQL fixture: retained Go heap 532 MiB 148 MiB
Same fixture: cumulative allocation 921 MiB 481 MiB
Same fixture: service-start time 11.52 s 11.37 s
Same fixture: peak RSS 1.095 GB 1.060 GB
Complete pkg/tests/issues: wall time 407.19 s 283.45 s
Complete pkg/tests/issues: peak RSS 3.995 GB 2.539 GB
Empty FIFO constructor: allocated bytes 9,523,226 65,413

The full issues run executes the identical multiset of 549 test/subtest names. Candidate passes. The clean-base run fails TestAutoIDCachePublicLifecycle with peer-CN no such table at auto_id_cache_test.go:186; other tests continue. This unrelated baseline failure is not claimed fixed by these changes.

These are single local observations, not controlled repeated Linux CI trials; some auxiliary checks overlapped the measurements. The observed full-package wall/RSS reductions are about 30%/36%, but no equivalent full-CI speedup is promised. Startup wall time itself is essentially unchanged. Heap excludes native/race-runtime memory and is not RSS. Dense cache warm-up may pay map growth; fully used WAL pools can approach the old memory footprint.

Validation

  • Normal and race owning packages: fifocache, logservicedriver, txn/trace, fileservice, objectio.
  • Full embedded package normal/race, including real SQL and dynamic CN expansion; full issues package race.
  • WAL regression: unused checkout/return, zero/small/large append, exact backend header/payload, error then reuse, oversized return and on-the-fly read client.
  • FIFO regression: 1025 colliding keys; empty/small/dense/colliding constructor benchmarks and existing steady-state Set/Get controls.
  • Trace regression: ordered CSV persistence beyond capacity; deterministic full-queue barrier with a real buffer-bearing producer, unblock/progress, release-marker ordering, quiescent close and fresh service generation. Exact new trace tests each checked 100 times under race using the bounded test-duration budget.
  • Changed-owner go vet, incremental golangci-lint, and git diff --check.

Design and limitations: UT_STARTUP_ALLOCATION.md. Independent GPT-6 medium design/review performed; complete local evidence retained in the task record. CI is not awaited or represented as passed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review(head 862652d)

结论:未发现本次变更引入的可证实 P0/P1/P2 阻断问题。由于这是作者自有 PR,本次提交 COMMENT,不提交 APPROVE。

已检查全部 9 个 changed files 及实现、测试、benchmark 和设计文档:

  • idle WAL 不再创建 payload;首次 append 的精确长度、独占 checkout、提交后归还及关闭后归还路径保持正确。
  • embedded testing CN 的零值默认限制在 testing 场景,显式配置、回调覆盖和动态新增 CN 路径未受影响。
  • trace 背压测试先解除阻塞并等待 producer,再关闭 service;CSV 顺序和 release-marker 顺序仍有断言。
  • FIFO 仅移除 map 预分配 hint,锁、淘汰回调、ghost 和 pending accounting 保持不变。
  • 未发现本次变更新增的泄漏、double cleanup、race、死锁或测试选择削弱。

验证:指定 head 的 Linux race UT、UT coverage、BVT、SCA 和 CI Required 已通过。PR 中的 100 次 focused race 与性能数据属于作者报告;本次未独立重跑,且其整包性能基线不是严格的当前 base/head 受控对比,因此不把 RSS/耗时降幅作为独立证明。

资源优化的容量边界也保持明确:testing trace 队列从默认 1,000,000 降为 1024,但高负载下仍可增长,并非新的硬上限。

CI:https://github.com/matrixorigin/matrixone/actions/runs/35216076463

@XuPeng-SH
XuPeng-SH merged commit 89d28d5 into matrixorigin:main Sep 17, 2026
17 of 19 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/ut-single-runner-efficiency branch September 17, 2026 13:48

This branch was previously deployed

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

Labels

kind/enhancement kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants