milvus/internal/datanode/io/io_pool.go
XuanYang-cn 4dd0c54ca0
fix: Fix l0 compactor may cause DN from OOM (#33554)
See also: #33547

---------

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2024-06-06 14:33:52 +08:00

61 lines
1.4 KiB
Go

package io
import (
"sync"
"github.com/milvus-io/milvus/pkg/util/conc"
"github.com/milvus-io/milvus/pkg/util/hardware"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)
var (
ioPool *conc.Pool[any]
ioPoolInitOnce sync.Once
)
var (
statsPool *conc.Pool[any]
statsPoolInitOnce sync.Once
)
func initIOPool() {
capacity := paramtable.Get().DataNodeCfg.IOConcurrency.GetAsInt()
if capacity > 32 {
capacity = 32
}
// error only happens with negative expiry duration or with negative pre-alloc size.
ioPool = conc.NewPool[any](capacity)
}
func GetOrCreateIOPool() *conc.Pool[any] {
ioPoolInitOnce.Do(initIOPool)
return ioPool
}
func initStatsPool() {
poolSize := paramtable.Get().DataNodeCfg.ChannelWorkPoolSize.GetAsInt()
if poolSize <= 0 {
poolSize = hardware.GetCPUNum()
}
statsPool = conc.NewPool[any](poolSize, conc.WithPreAlloc(false), conc.WithNonBlocking(false))
}
func GetOrCreateStatsPool() *conc.Pool[any] {
statsPoolInitOnce.Do(initStatsPool)
return statsPool
}
func initMultiReadPool() {
capacity := paramtable.Get().DataNodeCfg.FileReadConcurrency.GetAsInt()
if capacity > hardware.GetCPUNum() {
capacity = hardware.GetCPUNum()
}
// error only happens with negative expiry duration or with negative pre-alloc size.
ioPool = conc.NewPool[any](capacity)
}
func getMultiReadPool() *conc.Pool[any] {
ioPoolInitOnce.Do(initMultiReadPool)
return ioPool
}