From 750992cfe41130b6e82104eb9b336a89e90d0741 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 19 May 2023 17:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=BC=93=E5=86=B2=E6=B1=A0?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E7=AD=96=E7=95=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/synchronization/pool.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/synchronization/pool.go b/utils/synchronization/pool.go index 4d4256b..8749f6b 100644 --- a/utils/synchronization/pool.go +++ b/utils/synchronization/pool.go @@ -28,6 +28,7 @@ type Pool[T any] struct { bufferSize int generator func() T releaser func(data T) + warn int } func (slf *Pool[T]) Get() T { @@ -39,7 +40,11 @@ func (slf *Pool[T]) Get() T { return data } slf.mutex.Unlock() - log.Warn("Pool", zap.String("Get", "the number of buffer members is insufficient, consider whether it is due to unreleased or inappropriate buffer size")) + slf.warn++ + if slf.warn >= 100 { + log.Warn("Pool", zap.String("Get", "the number of buffer members is insufficient, consider whether it is due to unreleased or inappropriate buffer size")) + slf.warn = 0 + } return slf.generator() } @@ -54,6 +59,7 @@ func (slf *Pool[T]) Close() { slf.bufferSize = 0 slf.generator = nil slf.releaser = nil + slf.warn = 0 slf.mutex.Unlock() }