From: Matt Joiner Date: Fri, 1 Sep 2017 00:36:43 +0000 (+1000) Subject: Add some variables to track fillBuffer effectiveness X-Git-Tag: v1.0.0~416 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d934ec7e30fe1ba2ad8fe0ab45ad0adfc3796796;p=btrtrc.git Add some variables to track fillBuffer effectiveness --- diff --git a/connection.go b/connection.go index 20fec26f..45c2c20a 100644 --- a/connection.go +++ b/connection.go @@ -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. diff --git a/global.go b/global.go index 0d241128..a89659ae 100644 --- a/global.go +++ b/global.go @@ -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") )