fix: adaptive engine crash + erratic H1 performance#43
Merged
FumingPower3925 merged 4 commits intomainfrom Mar 9, 2026
Merged
Conversation
- 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
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.
Summary
Fixes three root causes behind Issue #42 (adaptive engine crash + erratic H1 benchmark performance):
NumCPUworkers each, exhausting io_uring ring resources on 2-vCPU CI machines. AddedsplitResources()to halve shared resources (workers, ring size, buffer pool, max events, max conns) per sub-engine. LoweredMinWorkersfrom 2 to 1.PauseAccept→ zero traffic → zero RPS, so the switch condition0 > activeScore * 1.15was 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.Files changed
adaptive/engine.gosplitResources()+New()uses halved configsadaptive/controller.goevaluate()rewrite,historicalScore()adaptive/engine_test.goengine/iouring/worker.goengine/epoll/loop.goresource/preset.goMinWorkers2→1resource/preset_test.goresource/config_test.goTest plan
go build ./...(macOS, linux/amd64, linux/arm64)go test -race -count=1 ./resource/...— passgo 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)go test -v -race ./adaptive/...(linux only)go test -v -race ./test/integration/...(linux only)Closes #42