Skip to content

Commit

Permalink
Limit statsz updates to once every 5 seconds per client
Browse files Browse the repository at this point in the history
  • Loading branch information
wjordan committed May 23, 2024
1 parent 7672774 commit 725bbb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ type client struct {
tags jwt.TagList
nameTag string

tlsTo *time.Timer
tlsTo *time.Timer
lastStatsz time.Time
}

type rrTracking struct {
Expand Down Expand Up @@ -3398,6 +3399,15 @@ func (c *client) deliverMsg(prodIsMQTT bool, sub *subscription, acc *Account, su

client.mu.Lock()

// Limit statsz updates to once every 5 seconds per client.
if string(sub.subject) == "$SYS.SERVER.*.STATSZ" {
if time.Since(client.lastStatsz) < 5*time.Second {
client.mu.Unlock()
return false
}
client.lastStatsz = time.Now()
}

// Check if we have a subscribe deny clause. This will trigger us to check the subject
// for a match against the denied subjects.
if client.mperms != nil && client.checkDenySub(string(subject)) {
Expand Down
13 changes: 13 additions & 0 deletions server/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3055,3 +3055,16 @@ func TestInProcessAllowedConnectionType(t *testing.T) {
})
}
}

func TestClusterSetupMsgs(t *testing.T) {
numServers := 10
c := createClusterEx(t, true, 5*time.Millisecond, true, "cluster", numServers)
var totalOut int
for _, server := range c.servers {
totalOut += int(server.outMsgs)
}
totalExpected := numServers * numServers
if totalOut >= totalExpected {
t.Fatalf("Total outMsgs is %d, expected < %d\n", totalOut, totalExpected)
}
}

0 comments on commit 725bbb0

Please sign in to comment.