Include rate limiting and stats in BenchmarkConnectionMainReadLoop
This commit is contained in:
parent
add2fceaba
commit
ab48d4731c
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
3
misc.go
3
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)
|
||||
|
|
Loading…
Reference in New Issue