Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
do not format expensive debug messages in non-debug levels in doDropRPC
  • Loading branch information
algorandskiy committed Sep 24, 2024
commit a8b7b3d679be254b10a9bf5892d5f0352a1a8121
6 changes: 5 additions & 1 deletion gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/record"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"

"go.uber.org/zap/zapcore"
)

const (
Expand Down Expand Up @@ -1334,7 +1336,9 @@ func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC, urgent bool) {
}

func (gs *GossipSubRouter) doDropRPC(rpc *RPC, p peer.ID, reason string) {
log.Debugf("dropping message to peer %s: %s", p, reason)
if log.Level() <= zapcore.DebugLevel {
log.Debugf("dropping message to peer %s: %s", p, reason)
}
gs.tracer.DropRPC(rpc, p)
// push control messages that need to be retried
ctl := rpc.GetControl()
Expand Down
8 changes: 8 additions & 0 deletions gossipsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3175,3 +3175,11 @@ func TestGossipsubIdontwantClear(t *testing.T) {

<-ctx.Done()
}

func BenchmarkAllocDoDropRPC(b *testing.B) {
gs := GossipSubRouter{tracer: &pubsubTracer{}}

for i := 0; i < b.N; i++ {
gs.doDropRPC(&RPC{}, "peerID", "reason")
}
}
Loading