Skip to content

Commit

Permalink
make slowness a warning, with a user configurable threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jul 30, 2021
1 parent 257d133 commit 0c7092d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ type GossipSubParams struct {
// HeartbeatInterval controls the time between heartbeats.
HeartbeatInterval time.Duration

// SlowHeartbeatWarning is the duration threshold for heartbeat processing before emitting
// a warning; this would be indicative of an overloaded peer.
SlowHeartbeatWarning float64

// FanoutTTL controls how long we keep track of the fanout state. If it's been
// FanoutTTL since we've published to a topic that we're not subscribed to,
// we'll delete the fanout map for that topic.
Expand Down Expand Up @@ -251,6 +255,7 @@ func DefaultGossipSubParams() GossipSubParams {
MaxIHaveLength: GossipSubMaxIHaveLength,
MaxIHaveMessages: GossipSubMaxIHaveMessages,
IWantFollowupTime: GossipSubIWantFollowupTime,
SlowHeartbeatWarning: 0.1,
}
}

Expand Down Expand Up @@ -1298,8 +1303,11 @@ func (gs *GossipSubRouter) heartbeatTimer() {
func (gs *GossipSubRouter) heartbeat() {
start := time.Now()
defer func() {
if dt := time.Since(start); dt > time.Millisecond {
log.Infow("heartbeat done", "took", dt)
if gs.params.SlowHeartbeatWarning > 0 {
slowWarning := time.Duration(gs.params.SlowHeartbeatWarning * float64(gs.params.HeartbeatInterval))
if dt := time.Since(start); dt > slowWarning {
log.Warnw("slow heartbeat", "took", dt)
}
}
}()

Expand Down

0 comments on commit 0c7092d

Please sign in to comment.