]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use low-water mark to populate connection requests
authorMatt Joiner <anacrolix@gmail.com>
Wed, 16 Jul 2014 07:11:45 +0000 (17:11 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 16 Jul 2014 07:11:45 +0000 (17:11 +1000)
I can't believe I didn't think of this before. It should address massive
performance problems I've had here.

download_strategies.go

index c6d0e1e1afa629e691032ed0953528d22413a5e3..43bd1d2d864e97db9cc7344861c8bb39a3d4a860 100644 (file)
@@ -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) {