Repository navigation
feat(engine): give an idle connection the slowest chunk's tail - #6
Conversation
troke12
left a comment
There was a problem hiding this comment.
Nice idea, and coverage stays intact since only the victim choice changes. Two issues:
- A stalled connection is never picked as slow:
notePaceonly runs when bytes arrive, so a hung socket keeps its last good pace forever (or stays at pace 0 and is skipped). That's the case that matters most. Please decay pace bynow - paceAtwhen computing ETA. paceAtisn't reset on pause/resume or between retries, so the first window after a resume divides by the paused time. Zero it at the start of eachfetch.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
An idle worker still takes half of one unfinished chunk. When two chunks have a measured pace and the slower one will take at least twice as long, that chunk gives up its tail. Until a pace is known, the largest remainder is used.
Review changes on top of the previous commit: - currentPace caps a chunk's pace by the bytes since its last update over the time since, so it falls toward 0 while the socket is quiet: notePace only runs when bytes arrive, and a hung socket kept its last good pace forever. A response without its first byte for paceStall (1 s) counts as pace 0 instead of unknown. Split judges paces at a given time (splitAt), and a pace of 0 is the slowest. - startPace forgets the pace of an earlier response at the start of each fetch, so the first window after a pause or retry does not divide by the time in between. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
10d7a5e to
8e49fc1
Compare
|
Rebased onto current |
Summary
When a connection finishes early it takes the tail of another chunk. Before, the chunk was always the one with the largest remainder. Now it is the chunk that will take longest to finish, when that is at least twice as long as the fastest one. A slow connection's tail goes to a faster one. Until paces are known, the largest remainder is still used.
Pace
notePace).currentPacedecays while no bytes arrive (bytes since the last update ÷ time since), so a hung socket falls to 0 instead of keeping its last good pace. A response with no first byte after 1 s counts as 0. A pace of 0 is the slowest, so a stalled connection's chunk is the one split.startPaceresets the measurement at each fetch, so the first window after a pause or retry does not divide by the paused time.midformula is the same.Commits
14d4b58(Ryan Bagas): the original change, rebased onto currentmain.8e49fc1: review changes. Pace decay, first-byte stall,startPaceper fetch.Test plan
go test ./...andgo test -race ./internal/engineTestSplitPicksAStalledChunk: a chunk that was fast but has had no byte for 10 s is split, not the busy larger one. Fails without decay.TestSplitPicksAChunkWithNoBytesYet: no first byte afterpaceStall→ split. Before that, it is still unknown. Fails without the first-byte rule.TestStartPaceForgetsTheEarlierResponsenotePacewindow.✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)