From: Matt Joiner Date: Wed, 16 Jul 2014 07:11:45 +0000 (+1000) Subject: Use low-water mark to populate connection requests X-Git-Tag: v1.0.0~1663 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e092ba2c5f9d625a1d05772837fdbedfda0df9ee;p=btrtrc.git 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. --- 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) {