Repository navigation
perf(torrent): declare v1 interest only in peers with pieces we want - #566
Merged
Merged
Conversation
A v1 worker sent INTERESTED to every peer and never NOT_INTERESTED, even while seeding, so leechers' chokers gave us unchoke slots we never used. The scheduler now counts, per peer, the wanted pieces it has that we have not verified (bitfield, HAVE, verify, revoke and selection changes keep it current); a worker starts not interested and sends INTERESTED or NOT_INTERESTED as that count crosses zero, and claims pieces only while interested. A swarm that has every piece closes connections to peers that have every piece too, and never redials them.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
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.
Second of three stacked PRs for v1 torrent throughput, based on #565 (review item 17).
A v1 worker sent INTERESTED to every peer right after the handshake and never sent NOT_INTERESTED, even while seeding. Leechers' rate-based chokers then gave Ketch unchoke slots it never used, and two seeds stayed connected forever.
Download throughput is unchanged; measured once per row on this PR, every row is within the run-to-run range of the digests PR. The 16 KiB row varies most, because the old per-claim scan allocates on every attempt.
Tests
TorrentSwarmInterestTest.interestFollowsThePiecesThePeerHasAndWeStillWant: no INTERESTED to a peer with nothing we want; INTERESTED once it announces a wanted piece; NOT_INTERESTED once that piece is stored; INTERESTED again for the next one.TorrentSwarmInterestTest.seedIsNeverInterestedAndClosesOtherSeeds: a seeding swarm never declares interest, still serves a leecher, and hangs up on another seed.TorrentSwarmDhtPortTest,TorrentSwarmPexEndpointTest, the Fast seeder test).:library:torrent:jvmTestpasses (1,288 tests). An earlier version closed seeds once the selection was complete, and four selection tests caught it (TorrentDownloadSourceSelectionTest,KotlinTorrentSessionSelectionTest,KotlinRuntimePrivateTest).How this was measured
V1ThroughputTest(opt-in, added in the first PR of the stack): aKotlinTorrentEnginewith the default buffer limits (maxBufferedBytes32 MiB) downloads a v1 torrent from 4 in-processLoopbackSeeders, memory-backed seeds on plain threads that answer each request after an optional delay, which the engine sees as the round trip. Uploads, DHT, uTP, encryption, local discovery and port mapping are off; the seeders' threads are subtracted from CPU time and allocation; one warm-up download runs first. 256 MiB payload without a round trip, 64 MiB with 50 ms, 3 runs per row (median and range). CPU is process CPU, JIT and GC included.Apple M4 Pro (14 cores), 48 GiB, macOS 27, APFS SSD, OpenJDK 21.0.11 (Homebrew), otherwise idle.