Add some variables to track fillBuffer effectiveness

This commit is contained in:
Matt Joiner 2017-09-01 10:36:43 +10:00
parent 016b238cc5
commit d934ec7e30
2 changed files with 15 additions and 0 deletions

View File

@ -346,12 +346,15 @@ var (
)
func (cn *connection) fillWriteBuffer(msg func(pp.Message) bool) {
numFillBuffers.Add(1)
rs, i := cn.desiredRequestState()
if !cn.SetInterested(i, msg) {
return
}
sentCancels := false
for r := range cn.requests {
if _, ok := rs[r]; !ok {
sentCancels = true
delete(cn.requests, r)
// log.Printf("%p: cancelling request: %v", cn, r)
if !msg(pp.Message{
@ -364,12 +367,17 @@ func (cn *connection) fillWriteBuffer(msg func(pp.Message) bool) {
}
}
}
if sentCancels {
fillBufferSentCancels.Add(1)
}
sentRequests := false
for r := range rs {
if _, ok := cn.requests[r]; !ok {
if cn.requests == nil {
cn.requests = make(map[request]struct{}, cn.nominalMaxRequests())
}
cn.requests[r] = struct{}{}
sentRequests = true
// log.Printf("%p: requesting %v", cn, r)
if !msg(pp.Message{
Type: pp.Request,
@ -381,6 +389,9 @@ func (cn *connection) fillWriteBuffer(msg func(pp.Message) bool) {
}
}
}
if sentRequests {
fillBufferSentRequests.Add(1)
}
}
// Writes buffers to the socket from the write channel.

View File

@ -93,4 +93,8 @@ var (
pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
fillBufferSentCancels = expvar.NewInt("fillBufferSentCancels")
fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests")
numFillBuffers = expvar.NewInt("numFillBuffers")
)