]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Allow stealing from slower connections within priority classes
authorMatt Joiner <anacrolix@gmail.com>
Thu, 23 Dec 2021 07:44:07 +0000 (18:44 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 23 Dec 2021 21:56:10 +0000 (08:56 +1100)
requesting.go

index f97f82b524ee7190b8a49a173c0d61082651f52f..f1642181411cb3755cd1502e22437c83c82db358 100644 (file)
@@ -92,6 +92,17 @@ func (p *peerRequests) Less(i, j int) bool {
                        !p.peer.peerAllowedFast.Contains(rightPieceIndex),
                )
        }
+       leftPiece := t.piece(int(leftPieceIndex))
+       rightPiece := t.piece(int(rightPieceIndex))
+       // Putting this first means we can steal requests from lesser-performing peers for our first few
+       // new requests.
+       ml = ml.Int(
+               // Technically we would be happy with the cached priority here, except we don't actually
+               // cache it anymore, and Torrent.piecePriority just does another lookup of *Piece to resolve
+               // the priority through Piece.purePriority, which is probably slower.
+               -int(leftPiece.purePriority()),
+               -int(rightPiece.purePriority()),
+       )
        leftPeer := t.pendingRequests[leftRequest]
        rightPeer := t.pendingRequests[rightRequest]
        ml = ml.Bool(rightPeer == p.peer, leftPeer == p.peer)
@@ -116,15 +127,6 @@ func (p *peerRequests) Less(i, j int) bool {
                // it will be served and therefore is the best candidate to cancel.
                ml = ml.CmpInt64(rightLast.Sub(leftLast).Nanoseconds())
        }
-       leftPiece := t.piece(int(leftPieceIndex))
-       rightPiece := t.piece(int(rightPieceIndex))
-       ml = ml.Int(
-               // Technically we would be happy with the cached priority here, except we don't actually
-               // cache it anymore, and Torrent.piecePriority just does another lookup of *Piece to resolve
-               // the priority through Piece.purePriority, which is probably slower.
-               -int(leftPiece.purePriority()),
-               -int(rightPiece.purePriority()),
-       )
        ml = ml.Int(
                int(leftPiece.relativeAvailability),
                int(rightPiece.relativeAvailability))