This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new c4d05be47f2 branch-4.0: [fix](ann index) fix omp threads limit can not
be assigned manually #58427 (#58493)
c4d05be47f2 is described below
commit c4d05be47f2b77aa07fc8c7fe785b5ce89cc2221
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Nov 28 20:34:41 2025 +0800
branch-4.0: [fix](ann index) fix omp threads limit can not be assigned
manually #58427 (#58493)
Cherry-picked from #58427
Co-authored-by: zhiqiang <[email protected]>
---
be/src/common/config.cpp | 11 ++++----
be/test/common/config_validator_test.cpp | 46 ++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 6b2175f1a2e..8f615cd47d7 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1597,14 +1597,15 @@ DEFINE_mInt64(max_csv_line_reader_output_buffer_size,
"4294967296");
// -1 means auto: use 80% of the available CPU cores.
DEFINE_Int32(omp_threads_limit, "-1");
DEFINE_Validator(omp_threads_limit, [](const int config) -> bool {
+ if (config > 0) {
+ omp_threads_limit = config;
+ return true;
+ }
CpuInfo::init();
int core_cap = config::num_cores > 0 ? config::num_cores :
CpuInfo::num_cores();
core_cap = std::max(1, core_cap);
- int limit = config;
- if (limit < 0) {
- limit = std::max(1, core_cap * 4 / 5);
- }
- omp_threads_limit = std::max(1, std::min(limit, core_cap));
+ // Use at most 80% of the available CPU cores.
+ omp_threads_limit = std::max(1, core_cap * 4 / 5);
return true;
});
// The capacity of segment partial column cache, used to cache column readers
for each segment.
diff --git a/be/test/common/config_validator_test.cpp
b/be/test/common/config_validator_test.cpp
index 56708648a63..ac105655c20 100644
--- a/be/test/common/config_validator_test.cpp
+++ b/be/test/common/config_validator_test.cpp
@@ -17,8 +17,11 @@
#include <gtest/gtest.h>
+#include <algorithm>
+
#include "common/config.h"
#include "common/status.h"
+#include "util/cpu_info.h"
namespace doris {
using namespace config;
@@ -46,4 +49,47 @@ TEST(ConfigValidatorTest, Validator) {
EXPECT_TRUE(s.ok());
EXPECT_EQ(cfg_validator_2, 8);
}
+
+// When a positive value is specified, validator should use it directly.
+TEST(ConfigValidatorTest, OmpThreadsLimitExplicitValue) {
+ int32_t original_limit = config::omp_threads_limit;
+
+ Status st = config::set_config("omp_threads_limit", "7", false, true);
+ ASSERT_TRUE(st.ok());
+ EXPECT_EQ(7, config::omp_threads_limit);
+
+ config::omp_threads_limit = original_limit;
+}
+
+// When value is -1 and config::num_cores is set,
+// validator should pick 80% of that core count.
+TEST(ConfigValidatorTest, OmpThreadsLimitAutoUsesConfiguredNumCores) {
+ int32_t original_limit = config::omp_threads_limit;
+ int32_t original_num_cores = config::num_cores;
+
+ config::num_cores = 20;
+ Status st = config::set_config("omp_threads_limit", "-1", false, true);
+ ASSERT_TRUE(st.ok());
+ EXPECT_EQ(16, config::omp_threads_limit);
+
+ config::num_cores = original_num_cores;
+ config::omp_threads_limit = original_limit;
+}
+
+// When value is -1 and config::num_cores is 0,
+// validator should fall back to CpuInfo::num_cores().
+TEST(ConfigValidatorTest, OmpThreadsLimitAutoFallsBackToCpuInfo) {
+ int32_t original_limit = config::omp_threads_limit;
+ int32_t original_num_cores = config::num_cores;
+
+ config::num_cores = 0;
+ Status st = config::set_config("omp_threads_limit", "-1", false, true);
+ ASSERT_TRUE(st.ok());
+ CpuInfo::init();
+ int expected = std::max(1, CpuInfo::num_cores() * 4 / 5);
+ EXPECT_EQ(expected, config::omp_threads_limit);
+
+ config::num_cores = original_num_cores;
+ config::omp_threads_limit = original_limit;
+}
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]