Skip to content

Commit

Permalink
move update piece requests after pending pieces is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed May 27, 2024
1 parent 3453a59 commit 3e31912
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 14 additions & 7 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ func (t *Torrent) onSetInfo() {
if !t.initialPieceCheckDisabled && !p.storageCompletionOk {
// t.logger.Printf("piece %s completion unknown, queueing check", p)
t.queuePieceCheck(i)
} else {
// if piece check is not called the piece priority still needs to be set
t.updatePiecePriority(i, "Torrent.OnSetInfo")
}
}
t.logger.Levelf(log.Debug, "%s: set info: peices=%d rolen=%d", t.Name(), len(t.pieces), t.getPieceRequestOrder().Len())
Expand Down Expand Up @@ -1256,19 +1259,23 @@ func (t *Torrent) onPiecePendingTriggers(piece pieceIndex, reason string) {
}

func (t *Torrent) updatePiecePriorityNoTriggers(piece pieceIndex) (pendingChanged bool) {
if !t.closed.IsSet() {
// It would be possible to filter on pure-priority changes here to avoid churning the piece
// request order.
t.updatePieceRequestOrderPiece(piece)
}
p := &t.pieces[piece]
newPrio := p.uncachedPriority()
// t.logger.Printf("torrent %p: piece %d: uncached priority: %v", t, piece, newPrio)
if newPrio == PiecePriorityNone {
return t._pendingPieces.CheckedRemove(uint32(piece))
pendingChanged = t._pendingPieces.CheckedRemove(uint32(piece))
} else {
return t._pendingPieces.CheckedAdd(uint32(piece))
pendingChanged = t._pendingPieces.CheckedAdd(uint32(piece))
}
// this needs to happen after t._pendingPieces is set otherwise the
// updated pending state is ignored
if pendingChanged && !t.closed.IsSet() {
// It would be possible to filter on pure-priority changes here to avoid churning the piece
// request order.
t.updatePieceRequestOrderPiece(piece)
}

return pendingChanged
}

func (t *Torrent) updatePiecePriority(piece pieceIndex, reason string) {
Expand Down
8 changes: 5 additions & 3 deletions webseed-peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ func (ws *webseedPeer) requester(i int) {
desiredRequests := len(ws.peer.getDesiredRequestState().Requests.requestIndexes)
pendingRequests := int(ws.peer.requestState.Requests.GetCardinality())

ws.peer.logger.Levelf(log.Debug, "%d: requests %d (p=%d,d=%d,n=%d) active(c=%d,m=%d,w=%d) complete(%d/%d) restart(%v)",
ws.peer.logger.Levelf(log.Debug, "%d: requests %d (p=%d,d=%d,n=%d) active(c=%d,m=%d,w=%d) hashing(q=%d,a=%d) complete(%d/%d) restart(%v)",
i, ws.processedRequests, pendingRequests, desiredRequests, ws.nominalMaxRequests(),
len(ws.activeRequests), ws.maxActiveRequests, ws.waiting, ws.peer.t.numPiecesCompleted(), ws.peer.t.NumPieces(), restart)
len(ws.activeRequests), ws.maxActiveRequests, ws.waiting,
ws.peer.t.piecesQueuedForHash.Len(), ws.peer.t.activePieceHashes,
ws.peer.t.numPiecesCompleted(), ws.peer.t.NumPieces(), restart)

if pendingRequests > ws.maxRequesters {
if pendingRequests > ws.peer.PeerMaxRequests {
Expand Down Expand Up @@ -300,7 +302,7 @@ func requestUpdate(ws *webseedPeer) {
peerInfo = append(peerInfo, fmt.Sprintf("%s%s:p=%d,d=%d: %f", this, flags, pieces, desired, rate))
})

ws.peer.logger.Levelf(log.Debug, "unchoke %d/%d/%d maxRequesters=%d, waiting=%d, (%s): peers(%d): %v", ws.processedRequests, numCompleted, numPieces, ws.maxRequesters, ws.waiting, ws.peer.lastUsefulChunkReceived, len(peerInfo), peerInfo)
ws.peer.logger.Levelf(log.Debug, "unchoke processed=%d, complete(%d/%d) maxRequesters=%d, waiting=%d, (%s): peers(%d): %v", ws.processedRequests, numCompleted, numPieces, ws.maxRequesters, ws.waiting, ws.peer.lastUsefulChunkReceived, len(peerInfo), peerInfo)

ws.peer.updateRequests("unchoked")

Expand Down

0 comments on commit 3e31912

Please sign in to comment.