From: Matt Joiner Date: Tue, 30 Aug 2016 04:21:50 +0000 (+1000) Subject: Add a benchmark for an observed slow case with Torrent.updatePiecePriorities X-Git-Tag: v1.0.0~607 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=792ab183e42cd42dbfe16a1c11aaa9c7c26244f0;p=btrtrc.git Add a benchmark for an observed slow case with Torrent.updatePiecePriorities --- diff --git a/torrent_test.go b/torrent_test.go index 6ffc8605..60951663 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -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() + } +}