diff --git a/utils/concurrent/pool.go b/utils/concurrent/pool.go index 35cb425..d50f8d3 100644 --- a/utils/concurrent/pool.go +++ b/utils/concurrent/pool.go @@ -30,6 +30,7 @@ type Pool[T any] struct { generator func() T releaser func(data T) warn int64 + silent bool } // EAC 动态调整缓冲区大小,适用于突发场景使用 @@ -53,10 +54,12 @@ func (slf *Pool[T]) Get() T { slf.mutex.Unlock() return data } - 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 = now + if !slf.silent { + 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 = now + } } slf.mutex.Unlock() diff --git a/utils/concurrent/pool_options.go b/utils/concurrent/pool_options.go new file mode 100644 index 0000000..1fc713f --- /dev/null +++ b/utils/concurrent/pool_options.go @@ -0,0 +1,12 @@ +package concurrent + +// PoolOption 线程安全的对象缓冲池选项 +type PoolOption[T any] func(pool *Pool[T]) + +// WithPoolSilent 静默模式 +// - 静默模式下,当缓冲区大小不足时,将不再输出警告日志 +func WithPoolSilent[T any]() PoolOption[T] { + return func(pool *Pool[T]) { + pool.silent = true + } +}