From: Matt Joiner Date: Mon, 11 Jun 2018 02:20:51 +0000 (+1000) Subject: Include rate limiting and stats in BenchmarkConnectionMainReadLoop X-Git-Tag: v1.0.0~127^2~44 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ab48d4731cb242583c8e2bf70b2401e9910f1d60;p=btrtrc.git Include rate limiting and stats in BenchmarkConnectionMainReadLoop --- diff --git a/client.go b/client.go index 8b8f9b4f..5f28b12d 100644 --- a/client.go +++ b/client.go @@ -192,12 +192,12 @@ func NewClient(cfg *Config) (cl *Client, err error) { cl.Close() }() if cfg.UploadRateLimiter == nil { - cl.uploadLimit = rate.NewLimiter(rate.Inf, 0) + cl.uploadLimit = unlimited } else { cl.uploadLimit = cfg.UploadRateLimiter } if cfg.DownloadRateLimiter == nil { - cl.downloadLimit = rate.NewLimiter(rate.Inf, 0) + cl.downloadLimit = unlimited } else { cl.downloadLimit = cfg.DownloadRateLimiter } diff --git a/connection_test.go b/connection_test.go index 6b4ccd6b..92af0681 100644 --- a/connection_test.go +++ b/connection_test.go @@ -2,6 +2,7 @@ package torrent import ( "io" + "net" "sync" "testing" "time" @@ -85,7 +86,9 @@ func (me *torrentStorage) WriteAt(b []byte, _ int64) (int, error) { } func BenchmarkConnectionMainReadLoop(b *testing.B) { - cl := &Client{} + cl := &Client{ + downloadLimit: unlimited, + } ts := &torrentStorage{} t := &Torrent{ cl: cl, @@ -99,11 +102,9 @@ func BenchmarkConnectionMainReadLoop(b *testing.B) { })) t.setChunkSize(defaultChunkSize) t.pendingPieces.Set(0, PiecePriorityNormal.BitmapPriority()) - r, w := io.Pipe() - cn := &connection{ - t: t, - r: r, - } + r, w := net.Pipe() + cn := cl.newConnection(r) + cn.setTorrent(t) mrlErr := make(chan error) cl.mu.Lock() go func() { diff --git a/misc.go b/misc.go index 6fdb77c0..10df1244 100644 --- a/misc.go +++ b/misc.go @@ -7,6 +7,7 @@ import ( "github.com/anacrolix/missinggo" "github.com/anacrolix/torrent/metainfo" pp "github.com/anacrolix/torrent/peer_protocol" + "golang.org/x/time/rate" ) type chunkSpec struct { @@ -165,3 +166,5 @@ func min(as ...int64) int64 { } return ret } + +var unlimited = rate.NewLimiter(rate.Inf, 0)