From: Matt Joiner Date: Sat, 10 Jan 2015 13:16:57 +0000 (+1100) Subject: Scale readahead with unchoked connections X-Git-Tag: v1.0.0~1371 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=78caa4533b46276da4c5770011f23c155fcf22a1;p=btrtrc.git Scale readahead with unchoked connections --- diff --git a/client.go b/client.go index 9809fd66..dadd87a0 100644 --- a/client.go +++ b/client.go @@ -287,7 +287,7 @@ func (cl *Client) readRaisePiecePriorities(t *torrent, off, _len int64) { return } cl.raisePiecePriority(t, index, piecePriorityNext) - for i := 0; i < 5; i++ { + for i := 0; i < t.numConnsUnchoked()-2; i++ { index++ if index >= t.NumPieces() { break diff --git a/torrent.go b/torrent.go index 21a3e413..b05ff34f 100644 --- a/torrent.go +++ b/torrent.go @@ -77,6 +77,15 @@ type torrent struct { GotMetainfo <-chan struct{} } +func (t *torrent) numConnsUnchoked() (num int) { + for _, c := range t.Conns { + if !c.PeerChoked { + num++ + } + } + return +} + func (t *torrent) addrActive(addr string) bool { if _, ok := t.HalfOpen[addr]; ok { return true