]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add some variables to track fillBuffer effectiveness
authorMatt Joiner <anacrolix@gmail.com>
Fri, 1 Sep 2017 00:36:43 +0000 (10:36 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 1 Sep 2017 00:36:43 +0000 (10:36 +1000)
connection.go
global.go

index 20fec26f4a3516db04be0e2df1ad23869b499e14..45c2c20a387259d3349490d36f542cbb5647377f 100644 (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.
index 0d2411283568081ead4d4e04ecba14f83691c696..a89659aeb2b720a9c9b36d9f5f3739dfeaaf696d 100644 (file)
--- 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")
 )