mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-08 01:58:34 +08:00
61 lines
1.4 KiB
Go
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
|
|
}
|