From eee85889208018208a4d1008612db28b59d7c370 Mon Sep 17 00:00:00 2001 From: groot Date: Tue, 6 Aug 2019 17:31:43 +0800 Subject: [PATCH] MS-312 Set openmp thread number by config Former-commit-id: 4c5b32f30e68639d85f4ae1d3eb8115810d8af01 --- cpp/CHANGELOG.md | 1 + cpp/conf/server_config.template | 3 ++- cpp/src/server/DBWrapper.cpp | 14 ++++++++++++++ cpp/src/server/ServerConfig.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 6e5fcc2c..5c5d7ccb 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -40,6 +40,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-266 - Improve topk reduce time by using multi-threads - MS-275 - Avoid sqlite logic error excetion - MS-278 - add IndexStatsHelper +- MS-312 - Set openmp thread number by config ## New Feature - MS-180 - Add new mem manager diff --git a/cpp/conf/server_config.template b/cpp/conf/server_config.template index ff5cfc6c..ec88b28c 100644 --- a/cpp/conf/server_config.template +++ b/cpp/conf/server_config.template @@ -43,4 +43,5 @@ engine_config: nprobe: 10 nlist: 16384 use_blas_threshold: 20 - metric_type: L2 # compare vectors by euclidean distance(L2) or inner product(IP), optional: L2 or IP + metric_type: L2 # compare vectors by euclidean distance(L2) or inner product(IP), optional: L2 or IP + omp_thread_occupancy: 0.75 # how many compute threads be used, this is a percent value compare to system cpu core number(for instance: cpu core is 4, then 0.75 means use 3 compute threads) diff --git a/cpp/src/server/DBWrapper.cpp b/cpp/src/server/DBWrapper.cpp index e908f62d..b4c89ed8 100644 --- a/cpp/src/server/DBWrapper.cpp +++ b/cpp/src/server/DBWrapper.cpp @@ -10,11 +10,14 @@ #include "utils/Log.h" #include "utils/StringHelpFunctions.h" +#include + namespace zilliz { namespace milvus { namespace server { DBWrapper::DBWrapper() { + //db config zilliz::milvus::engine::Options opt; ConfigNode& db_config = ServerConfig::GetInstance().GetConfig(CONFIG_DB); opt.meta.backend_uri = db_config.GetValue(CONFIG_DB_URL); @@ -37,6 +40,7 @@ DBWrapper::DBWrapper() { kill(0, SIGUSR1); } + // cache config ConfigNode& cache_config = ServerConfig::GetInstance().GetConfig(CONFIG_CACHE); opt.insert_cache_immediately_ = cache_config.GetBoolValue(CONFIG_INSERT_CACHE_IMMEDIATELY, false); @@ -56,6 +60,16 @@ DBWrapper::DBWrapper() { kill(0, SIGUSR1); } + // engine config + ConfigNode& engine_config = ServerConfig::GetInstance().GetConfig(CONFIG_ENGINE); + float omp_thread_rate = engine_config.GetFloatValue(CONFIG_OMP_THREAD_RATE, 0.75); + uint32_t cpu_count = 1; + CommonUtil::GetSystemAvailableThreads(cpu_count); + float thread_count = omp_thread_rate*(float)cpu_count; + int32_t omp_thread = (int32_t)round(thread_count); + omp_set_num_threads(omp_thread); + SERVER_LOG_DEBUG << "Openmp thread number = " << omp_thread; + //set archive config engine::ArchiveConf::CriteriaT criterial; int64_t disk = db_config.GetInt64Value(CONFIG_DB_ARCHIVE_DISK, 0); diff --git a/cpp/src/server/ServerConfig.h b/cpp/src/server/ServerConfig.h index bb7d5d36..48e44fc4 100644 --- a/cpp/src/server/ServerConfig.h +++ b/cpp/src/server/ServerConfig.h @@ -53,6 +53,7 @@ static const std::string CONFIG_NPROBE = "nprobe"; static const std::string CONFIG_NLIST = "nlist"; static const std::string CONFIG_DCBT = "use_blas_threshold"; static const std::string CONFIG_METRICTYPE = "metric_type"; +static const std::string CONFIG_OMP_THREAD_RATE = "omp_thread_occupancy"; class ServerConfig { public: -- GitLab