From e092ba2c5f9d625a1d05772837fdbedfda0df9ee Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 16 Jul 2014 17:11:45 +1000 Subject: [PATCH] Use low-water mark to populate connection requests I can't believe I didn't think of this before. It should address massive performance problems I've had here. --- download_strategies.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/download_strategies.go b/download_strategies.go index c6d0e1e1..43bd1d2d 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -20,7 +20,7 @@ func (s *DefaultDownloadStrategy) FillRequests(t *torrent, c *connection) { if c.PeerChoked { return } - if len(c.Requests) >= c.PeerMaxRequests { + if len(c.Requests) >= (c.PeerMaxRequests+1)/2 { return } } @@ -51,13 +51,13 @@ func (s *DefaultDownloadStrategy) FillRequests(t *torrent, c *connection) { } } // Then finish off incomplete pieces in order of bytes remaining. - for _, heatThreshold := range []int{0, 4, 60} { + for _, heatThreshold := range []int{1, 4, 15, 60} { for e := t.PiecesByBytesLeft.Front(); e != nil; e = e.Next() { pieceIndex := pp.Integer(e.Value.(int)) - // for _, chunkSpec := range t.Pieces[pieceIndex].shuffledPendingChunkSpecs() { - for chunkSpec := range t.Pieces[pieceIndex].PendingChunkSpecs { + for _, chunkSpec := range t.Pieces[pieceIndex].shuffledPendingChunkSpecs() { + // for chunkSpec := range t.Pieces[pieceIndex].PendingChunkSpecs { r := request{pieceIndex, chunkSpec} - if th[r] > heatThreshold { + if th[r] >= heatThreshold { continue } if !addRequest(r) { -- 2.48.1