From 787b0d922f0d996b1e9baea41e0af1eed247f967 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Tue, 1 Aug 2023 20:28:37 -0700 Subject: [PATCH] Do not hold onto no interest subjects from a client in the unlocked cache. If sending lots of different subjects all with no interest performance could be affected. Signed-off-by: Derek Collison --- server/client.go | 18 ++++++++++-------- server/sublist.go | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/client.go b/server/client.go index 4886a18e..b6f73442 100644 --- a/server/client.go +++ b/server/client.go @@ -3670,14 +3670,16 @@ func (c *client) processInboundClientMsg(msg []byte) (bool, bool) { // Go back to the sublist data structure. if !ok { r = acc.sl.Match(string(c.pa.subject)) - c.in.results[string(c.pa.subject)] = r - // Prune the results cache. Keeps us from unbounded growth. Random delete. - if len(c.in.results) > maxResultCacheSize { - n := 0 - for subject := range c.in.results { - delete(c.in.results, subject) - if n++; n > pruneSize { - break + if len(r.psubs)+len(r.qsubs) > 0 { + c.in.results[string(c.pa.subject)] = r + // Prune the results cache. Keeps us from unbounded growth. Random delete. + if len(c.in.results) > maxResultCacheSize { + n := 0 + for subject := range c.in.results { + delete(c.in.results, subject) + if n++; n > pruneSize { + break + } } } } diff --git a/server/sublist.go b/server/sublist.go index 48375b6b..d7ffac0c 100644 --- a/server/sublist.go +++ b/server/sublist.go @@ -48,7 +48,7 @@ const ( // cacheMax is used to bound limit the frontend cache slCacheMax = 1024 // If we run a sweeper we will drain to this count. - slCacheSweep = 512 + slCacheSweep = 256 // plistMin is our lower bounds to create a fast plist for Match. plistMin = 256 )