Skip to content

Commit

Permalink
create pubsubpeer-queue-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Feb 22, 2024
1 parent e6be3c0 commit 43b2a8e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions libp2p/protocols/pubsub/pubsubpeer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ when defined(libp2p_expensive_metrics):
declareCounter(libp2p_pubsub_skipped_received_messages, "number of received skipped messages", labels = ["id"])
declareCounter(libp2p_pubsub_skipped_sent_messages, "number of sent skipped messages", labels = ["id"])

when defined(pubsubpeer-queue-metrics):
declareGauge(libp2p_gossipsub_priority_queue_size, "the number of messages in the priority queue", labels = ["id"])
declareGauge(libp2p_gossipsub_non_priority_queue_size, "the number of messages in the non-priority queue", labels = ["id"])

Expand Down Expand Up @@ -161,7 +162,7 @@ proc stopSendNonPriorityTask*(p: PubSubPeer) =
f.cancel()
p.rpcmessagequeue.sendPriorityQueue.clear()
p.rpcmessagequeue.nonPriorityQueue.clear()
when defined(libp2p_expensive_metrics):
when defined(pubsubpeer-queue-metrics):
libp2p_gossipsub_priority_queue_size.set(labelValues = [$p.peerId], value = 0)
libp2p_gossipsub_non_priority_queue_size.set(labelValues = [$p.peerId], value = 0)

Expand Down Expand Up @@ -274,7 +275,7 @@ proc clearSendPriorityQueue(p: PubSubPeer) =
discard p.rpcmessagequeue.sendPriorityQueue.popLast()
else:
break
when defined(libp2p_expensive_metrics):
when defined(pubsubpeer-queue-metrics):
libp2p_gossipsub_priority_queue_size.dec(labelValues = [$p.peerId])

proc sendMsg(p: PubSubPeer, msg: seq[byte]) {.async.} =
Expand Down Expand Up @@ -326,11 +327,11 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte], isHighPriority: bool) {.async.}
let f = p.sendMsg(msg)
if not f.finished:
p.rpcmessagequeue.sendPriorityQueue.addLast(f)
when defined(libp2p_expensive_metrics):
when defined(pubsubpeer-queue-metrics):
libp2p_gossipsub_priority_queue_size.inc(labelValues = [$p.peerId])
else:
await p.rpcmessagequeue.nonPriorityQueue.addLast(msg)
when defined(libp2p_expensive_metrics):
when defined(pubsubpeer-queue-metrics):
libp2p_gossipsub_non_priority_queue_size.inc(labelValues = [$p.peerId])
trace "message queued", p, msg = shortLog(msg)

Expand Down Expand Up @@ -422,7 +423,7 @@ proc sendNonPriorityTask(p: PubSubPeer) {.async.} =
# to be finished already (since sends are processed in order).
if p.rpcmessagequeue.sendPriorityQueue.len > 0:
await p.rpcmessagequeue.sendPriorityQueue[^1]
when defined(libp2p_expensive_metrics):
when defined(pubsubpeer-queue-metrics):
libp2p_gossipsub_non_priority_queue_size.dec(labelValues = [$p.peerId])
await p.sendMsg(msg)

Expand Down

0 comments on commit 43b2a8e

Please sign in to comment.