feat: concurrent.Pool 新增静默模式可选项 WithPoolSilent,在该模式下当缓冲区大小不足时,将不再输出警告日志
This commit is contained in:
parent
2d9ffad2ab
commit
3ad1330cd9
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue