Skip to content

fix: adaptive engine crash + erratic H1 performance#43

Merged
FumingPower3925 merged 4 commits intomainfrom
fix/sustained-load-death-spiral
Mar 9, 2026
Merged

fix: adaptive engine crash + erratic H1 performance#43
FumingPower3925 merged 4 commits intomainfrom
fix/sustained-load-death-spiral

Conversation

@FumingPower3925
Copy link
Contributor

Summary

Fixes three root causes behind Issue #42 (adaptive engine crash + erratic H1 benchmark performance):

  • Crash on Auto mode: Both sub-engines created NumCPU workers each, exhausting io_uring ring resources on 2-vCPU CI machines. Added splitResources() to halve shared resources (workers, ring size, buffer pool, max events, max conns) per sub-engine. Lowered MinWorkers from 2 to 1.
  • Dead telemetry / no-op controller: Standby engine always scored 0 because PauseAccept → zero traffic → zero RPS, so the switch condition 0 > activeScore * 1.15 was always false. Replaced live standby sampling with historical scoring — stores the last active score per engine type with 1%/sec decay. New standby engines are seeded at 80% of active's score.
  • CPU contention from standby busy-polling: Idle standby workers (paused accept, no draining connections) now use longer poll timeouts (io_uring: 100ms→1s, epoll: 1ms→500ms), reducing standby CPU from ~50% to <1%.

Files changed

File Change
adaptive/engine.go splitResources() + New() uses halved configs
adaptive/controller.go Historical scoring maps, evaluate() rewrite, historicalScore()
adaptive/engine_test.go 5 existing tests updated + 4 new tests
engine/iouring/worker.go Standby timeout backoff
engine/epoll/loop.go Standby timeout backoff
resource/preset.go MinWorkers 2→1
resource/preset_test.go Updated Minimal preset expectations
resource/config_test.go Updated validation boundary test

Test plan

  • go build ./... (macOS, linux/amd64, linux/arm64)
  • go test -race -count=1 ./resource/... — pass
  • go test -race -count=1 ./overload/... — pass (no regressions)
  • go test -race -count=1 ./... — all pass (4 pre-existing h2spec failures unrelated)
  • golangci-lint run ./... — 0 issues (macOS + linux/amd64)
  • CI: go test -v -race ./adaptive/... (linux only)
  • CI: go test -v -race ./test/integration/... (linux only)

Closes #42

- Replace MSG_PEEK-based protocol detection with inline detection in
  handleRecv, fixing 20x slowdown on arm64 where MSG_PEEK behaves
  differently. Detection now happens on first received data, matching
  epoll's approach.

- Remove dead code: prepRecvPeek, udPeek, msgPeek, handlePeek.

- Eliminate per-DATA-frame map allocation in FlushWindowUpdates by
  writing WINDOW_UPDATE frames directly while iterating pending updates.

- Lower windowUpdateThreshold from 16384 to 1024 so small bodies (4KB)
  get timely flow control credits on multiplexed connections.

- Clean up pendingStreamUpdates in DeleteStream to prevent unbounded
  map growth over long-lived connections.
Three root causes addressed:

1. Crash on hybrid (Auto) mode: both sub-engines created NumCPU workers
   each, exhausting io_uring ring resources on low-CPU machines. Added
   splitResources() to halve shared resources per sub-engine while
   keeping per-connection settings unchanged. Lowered MinWorkers to 1.

2. Dead telemetry: standby engine always scored 0 (PauseAccept → zero
   traffic → zero RPS), making the controller a permanent no-op.
   Replaced live standby sampling with historical scoring — stores last
   active score per engine type with 1%/sec decay. Standby seeded at
   80% of active when no history exists.

3. CPU contention: standby workers busy-polled even when idle, wasting
   ~50% CPU. Added timeout backoff for idle standby workers (1s for
   io_uring, 500ms for epoll) when accept is paused and no connections
   are draining.

Closes #42
@FumingPower3925 FumingPower3925 self-assigned this Mar 9, 2026
@FumingPower3925 FumingPower3925 merged commit 1c0fda2 into main Mar 9, 2026
8 checks passed
@FumingPower3925 FumingPower3925 deleted the fix/sustained-load-death-spiral branch March 9, 2026 17:04
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.

fix: adaptive engine crash on hybrid mode and erratic H1 performance

1 participant