From 368af1afe64e409c17e89fb627d140b4672cc8b1 Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Mon, 23 Dec 2019 19:41:12 +0800 Subject: [PATCH] nsqd: reduce ReadyCount update frequency --- nsqd/client_v2.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nsqd/client_v2.go b/nsqd/client_v2.go index 41002b5bd..877d6b234 100644 --- a/nsqd/client_v2.go +++ b/nsqd/client_v2.go @@ -327,8 +327,11 @@ func (c *clientV2) IsReadyForMessages() bool { } func (c *clientV2) SetReadyCount(count int64) { - atomic.StoreInt64(&c.ReadyCount, count) - c.tryUpdateReadyState() + oldCount := atomic.SwapInt64(&c.ReadyCount, count) + + if oldCount != count { + c.tryUpdateReadyState() + } } func (c *clientV2) tryUpdateReadyState() {