From 361cdc0e085377b7a8911cf40770830ba5bff7f0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 1 Sep 2017 10:53:59 +1000 Subject: [PATCH] Track buffered but not posted messages, and unify the expvar names for those counters --- connection.go | 6 ++++-- global.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/connection.go b/connection.go index 05c5f5ea..da1d97b7 100644 --- a/connection.go +++ b/connection.go @@ -234,7 +234,7 @@ func (cn *connection) PeerHasPiece(piece int) bool { } func (cn *connection) Post(msg pp.Message) { - postedMessageTypes.Add(strconv.FormatInt(int64(msg.Type), 10), 1) + messageTypesPosted.Add(strconv.FormatInt(int64(msg.Type), 10), 1) cn.postedBuffer.Write(msg.MustMarshalBinary()) cn.writerCond.Broadcast() } @@ -408,6 +408,7 @@ func (cn *connection) writer(keepAliveTimeout time.Duration) { cn.postedBuffer.Reset() if buf.Len() == 0 { cn.fillWriteBuffer(func(msg pp.Message) bool { + cn.wroteMsg(&msg) buf.Write(msg.MustMarshalBinary()) return buf.Len() < 1<<16 }) @@ -662,6 +663,7 @@ func (c *connection) requestPendingMetadata() { } func (cn *connection) wroteMsg(msg *pp.Message) { + messageTypesSent.Add(strconv.FormatInt(int64(msg.Type), 10), 1) cn.stats.wroteMsg(msg) cn.t.stats.wroteMsg(msg) } @@ -742,7 +744,7 @@ func (c *connection) mainReadLoop() error { receivedKeepalives.Add(1) continue } - receivedMessageTypes.Add(strconv.FormatInt(int64(msg.Type), 10), 1) + messageTypesReceived.Add(strconv.FormatInt(int64(msg.Type), 10), 1) switch msg.Type { case pp.Choke: c.PeerChoked = true diff --git a/global.go b/global.go index 9e357c56..fe1901cb 100644 --- a/global.go +++ b/global.go @@ -80,14 +80,16 @@ var ( connsToSelf = expvar.NewInt("connsToSelf") // Number of completed connections to a client we're already connected with. duplicateClientConns = expvar.NewInt("duplicateClientConns") - receivedMessageTypes = expvar.NewMap("receivedMessageTypes") receivedKeepalives = expvar.NewInt("receivedKeepalives") supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages") - postedMessageTypes = expvar.NewMap("postedMessageTypes") postedKeepalives = expvar.NewInt("postedKeepalives") // Requests received for pieces we don't have. requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces") + messageTypesReceived = expvar.NewMap("messageTypesReceived") + messageTypesSent = expvar.NewMap("messageTypesSent") + messageTypesPosted = expvar.NewMap("messageTypesPosted") + // Track the effectiveness of Torrent.connPieceInclinationPool. pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused") pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew") -- 2.48.1