Skip to content

perf(doctor): probe channels concurrently instead of sequentially - #579

Open
An-idd wants to merge 1 commit into
Panniantong:mainfrom
An-idd:perf/doctor-concurrent-probes
Open

perf(doctor): probe channels concurrently instead of sequentially#579
An-idd wants to merge 1 commit into
Panniantong:mainfrom
An-idd:perf/doctor-concurrent-probes

Conversation

@An-idd

@An-idd An-idd commented Aug 6, 2026

Copy link
Copy Markdown

Reimplementation of #406 on latest main, addressing each close reason:

Close reasons → fixes

  1. 丢失 main 的 URL 凭据清洗scrub_url_credentials is kept as the final output boundary in _check_one — both the success path and the exception path go through it (existing scrub tests still pass unchanged).
  2. 全局 channel 单例在并发 Doctor 调用中的 active_backend 竞态 → a module-level lock serializes overlapping check_all() runs, so concurrent doctor callers can't cross-contaminate the singletons' active_backend. Channels within one run still probe in parallel, so the perf win is unaffected. New test spawns two concurrent doctor runs against one singleton and asserts each gets its own backend.
  3. 墙钟测试不稳定 → no timing assertions at all. The concurrency test uses a threading.Barrier(8): it only passes if all 8 probes run simultaneously; sequential execution deterministically fails via barrier timeout. Registry ordering is also asserted (format_report relies on it; ThreadPoolExecutor.map preserves input order).

Why

Each check() does real subprocess/network probing with multi-second timeouts (rdt status waits up to 10s), so sequential wall time = Σ(probe times); concurrent ≈ max(probe times). Measured 2.2×–3.6× on real installed states — full benchmark methodology and raw trials in #406.

Tests

pytest tests/ -v: 588 passed, 16 subtests passed.

🤖 Generated with Claude Code

Reimplements Panniantong#406 on latest main, addressing all three close reasons:

- Keeps main's scrub_url_credentials boundary — every result message
  (success and error paths) is scrubbed in _check_one.
- Serializes overlapping doctor runs with a module-level lock so
  concurrent check_all callers can't cross-contaminate the registry
  singletons' active_backend; channels within one run still probe in
  parallel.
- No wall-clock assertions: the concurrency test uses a threading
  Barrier that only all-at-once execution can pass, plus a two-run
  test proving active_backend isolation.

Wall time drops from sum(probe times) to ~max(probe times) — measured
2.2×–3.6× on real installed states in Panniantong#406.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants