connection.go | 11 +++++++++++ global.go | 4 ++++ diff --git a/connection.go b/connection.go index 20fec26f4a3516db04be0e2df1ad23869b499e14..45c2c20a387259d3349490d36f542cbb5647377f 100644 --- a/connection.go +++ b/connection.go @@ -346,12 +346,15 @@ connectionWriterWrite = expvar.NewInt("connectionWriterWrite") ) 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 @@ return } } } + 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, @@ -380,6 +388,9 @@ }) { return } } + } + if sentRequests { + fillBufferSentRequests.Add(1) } } diff --git a/global.go b/global.go index 0d2411283568081ead4d4e04ecba14f83691c696..a89659aeb2b720a9c9b36d9f5f3739dfeaaf696d 100644 --- a/global.go +++ b/global.go @@ -93,4 +93,8 @@ // Track the effectiveness of Torrent.connPieceInclinationPool. pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused") pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew") pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut") + + fillBufferSentCancels = expvar.NewInt("fillBufferSentCancels") + fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests") + numFillBuffers = expvar.NewInt("numFillBuffers") )