From 989b9da33d282369b5771621b0eb7d6fe03dd6c0 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 6 Sep 2023 16:53:33 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20concurrent.Pool=20?= =?UTF-8?q?=E6=B1=A0=E5=AF=B9=E8=B1=A1=E4=B8=8D=E5=A4=9F=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0=E4=B8=BA=201=20=E7=A7=92?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E9=A2=91?= =?UTF-8?q?=E7=B9=81=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/concurrent/pool.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils/concurrent/pool.go b/utils/concurrent/pool.go index 79184c7..35cb425 100644 --- a/utils/concurrent/pool.go +++ b/utils/concurrent/pool.go @@ -4,6 +4,7 @@ import ( "github.com/kercylan98/minotaur/utils/log" "go.uber.org/zap" "sync" + "time" ) func NewPool[T any](bufferSize int, generator func() T, releaser func(data T)) *Pool[T] { @@ -52,12 +53,13 @@ func (slf *Pool[T]) Get() T { slf.mutex.Unlock() return data } - slf.warn++ - slf.mutex.Unlock() - if slf.warn >= 256 { + now := time.Now().Unix() + if now-slf.warn >= 1 { log.Warn("Pool", log.String("Get", "the number of buffer members is insufficient, consider whether it is due to unreleased or inappropriate buffer size"), zap.Stack("stack")) - slf.warn = 0 + slf.warn = now } + slf.mutex.Unlock() + return slf.generator() }