Skip to content

Commit

Permalink
Limit max thread num for pool (#28018) (#28115)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <[email protected]>
  • Loading branch information
yah01 authored Nov 6, 2023
1 parent 5c06f29 commit 5c44421
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/core/src/storage/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
3 changes: 3 additions & 0 deletions internal/querynodev2/segments/segment_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5c44421

Please sign in to comment.