]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add a benchmark for an observed slow case with Torrent.updatePiecePriorities
authorMatt Joiner <anacrolix@gmail.com>
Tue, 30 Aug 2016 04:21:50 +0000 (14:21 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 30 Aug 2016 04:21:50 +0000 (14:21 +1000)
torrent_test.go

index 6ffc860549fbc357658770582dd7e224e9be7831..6095166386cf676523593af90282baf57cdc9d82 100644 (file)
@@ -3,6 +3,10 @@ package torrent
 import (
        "testing"
 
+       "github.com/bradfitz/iter"
+       "github.com/stretchr/testify/assert"
+
+       "github.com/anacrolix/torrent/metainfo"
        "github.com/anacrolix/torrent/peer_protocol"
 )
 
@@ -58,3 +62,30 @@ func TestTorrentString(t *testing.T) {
                t.FailNow()
        }
 }
+
+// This benchmark is from the observation that a lot of overlapping Readers on
+// a large torrent with small pieces had a lot of overhead in recalculating
+// piece priorities everytime a reader (possibly in another Torrent) changed.
+func BenchmarkUpdatePiecePriorities(b *testing.B) {
+       cl := &Client{}
+       t := cl.newTorrent(metainfo.Hash{})
+       t.info = &metainfo.Info{
+               Pieces:      make([]byte, 20*13410),
+               PieceLength: 256 << 10,
+       }
+       t.makePieces()
+       assert.EqualValues(b, 13410, t.numPieces())
+       for range iter.N(7) {
+               r := t.NewReader()
+               r.SetReadahead(32 << 20)
+               r.Seek(3500000, 0)
+       }
+       assert.Len(b, t.readers, 7)
+       t.pendPieceRange(0, t.numPieces())
+       for i := 0; i < t.numPieces(); i += 3 {
+               t.completedPieces.Set(i, true)
+       }
+       for range iter.N(b.N) {
+               t.updatePiecePriorities()
+       }
+}