Limit max thread num for pool (#28018) (#28115)

Signed-off-by: yah01 <yah2er0ne@outlook.com>
pull/28177/head
yah01 2023-11-06 10:50:17 +08:00 committed by GitHub
parent 5c06f293f5
commit 5c444218a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -39,6 +39,13 @@ class ThreadPool {
current_threads_size_ = 0;
min_threads_size_ = CPU_NUM;
max_threads_size_ = CPU_NUM * thread_core_coefficient;
// only IO pool will set large limit, but the CPU helps nothing to IO operations,
// we need to limit the max thread num, each thread will download 16 MiB data,
// it should be not greater than 256 (4GiB data) to avoid OOM and send too many requests to object storage
if (max_threads_size_ > 256) {
max_threads_size_ = 256;
}
LOG_SEGCORE_INFO_ << "Init thread pool:" << name_
<< " with min worker num:" << min_threads_size_
<< " and max worker num:" << max_threads_size_;

View File

@ -367,6 +367,9 @@ func (loader *segmentLoader) requestResource(ctx context.Context, infos ...*quer
diskCap := paramtable.Get().QueryNodeCfg.DiskCapacityLimit.GetAsUint64()
poolCap := runtime.NumCPU() * paramtable.Get().CommonCfg.HighPriorityThreadCoreCoefficient.GetAsInt()
if poolCap > 256 {
poolCap = 256
}
if loader.committedResource.WorkNum >= poolCap {
return resource, 0, merr.WrapErrServiceRequestLimitExceeded(int32(poolCap))
} else if loader.committedResource.MemorySize+memoryUsage >= totalMemory {