Raise the nominal max requests for connections that download lots of useful chunks
Massive speed increases for some connections.
This commit is contained in:
parent
f4c03ee6ac
commit
05da46ddbb
@ -314,13 +314,32 @@ func (cn *connection) requestedMetadataPiece(index int) bool {
|
|||||||
return index < len(cn.metadataRequests) && cn.metadataRequests[index]
|
return index < len(cn.metadataRequests) && cn.metadataRequests[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clamp(min, value, max int64) int64 {
|
||||||
|
if min > max {
|
||||||
|
panic("harumph")
|
||||||
|
}
|
||||||
|
if value < min {
|
||||||
|
value = min
|
||||||
|
}
|
||||||
|
if value > max {
|
||||||
|
value = max
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func max(as ...int64) int64 {
|
||||||
|
ret := as[0]
|
||||||
|
for _, a := range as[1:] {
|
||||||
|
if a > ret {
|
||||||
|
ret = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// The actual value to use as the maximum outbound requests.
|
// The actual value to use as the maximum outbound requests.
|
||||||
func (cn *connection) nominalMaxRequests() (ret int) {
|
func (cn *connection) nominalMaxRequests() (ret int) {
|
||||||
ret = cn.PeerMaxRequests
|
return int(clamp(1, int64(cn.PeerMaxRequests), max(64, cn.stats.ChunksReadUseful-(cn.stats.ChunksRead-cn.stats.ChunksReadUseful))))
|
||||||
if ret > 64 {
|
|
||||||
ret = 64
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *connection) onPeerSentCancel(r request) {
|
func (cn *connection) onPeerSentCancel(r request) {
|
||||||
@ -567,13 +586,16 @@ func nextRequestState(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(currentRequests)+len(newRequests) >= requestsHighWater {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if _, ok := currentRequests[r]; !ok {
|
if _, ok := currentRequests[r]; !ok {
|
||||||
if newRequests == nil {
|
if newRequests == nil {
|
||||||
newRequests = make([]request, 0, requestsHighWater-len(currentRequests))
|
newRequests = make([]request, 0, requestsHighWater-len(currentRequests))
|
||||||
}
|
}
|
||||||
newRequests = append(newRequests, r)
|
newRequests = append(newRequests, r)
|
||||||
}
|
}
|
||||||
return len(currentRequests)+len(newRequests) < requestsHighWater
|
return true
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user