diff --git a/cpp/conf/server_config.template b/cpp/conf/server_config.template index a96d2d81cfc25316a9a7d8fcbaf1809a65e43073..6364698100e43de7dda50b3a5da74565e1656e02 100644 --- a/cpp/conf/server_config.template +++ b/cpp/conf/server_config.template @@ -5,13 +5,13 @@ server_config: time_zone: UTC+8 db_config: - db_path: @MILVUS_DB_PATH@ # milvus database path - db_slave_path: # secondary database path, split by semicolon + path: @MILVUS_DB_PATH@ # milvus database path + slave_path: # secondary database path, split by semicolon # URI format: dialect://username:password@host:port/database # All parts except dialect are optional, but you MUST include the delimiters # Currently dialect supports mysql or sqlite - db_backend_url: sqlite://:@:/ + backend_url: sqlite://:@:/ archive_disk_threshold: 0 # GB, file will be archived when disk usage exceed, 0 for no limit archive_days_threshold: 0 # DAYS, older files will be archived, 0 for no limit @@ -27,7 +27,7 @@ metric_config: cache_config: cpu_mem_capacity: 16 # GB, CPU memory size used for cache cpu_mem_threshold: 0.85 # percent of data kept when cache cleanup triggered - insert_immediately: false # whether load data into cache when insert + cache_insert_data: false # whether load data into cache when insert engine_config: blas_threshold: 20 diff --git a/cpp/src/cache/CpuCacheMgr.cpp b/cpp/src/cache/CpuCacheMgr.cpp index ee30494192685429a1d3ca1c297cca59a691d3ce..7141394fa1f5b459f5be494e4253ad21c4ebb8bf 100644 --- a/cpp/src/cache/CpuCacheMgr.cpp +++ b/cpp/src/cache/CpuCacheMgr.cpp @@ -29,19 +29,16 @@ namespace { } CpuCacheMgr::CpuCacheMgr() { - server::ConfigNode& config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_CACHE); - int64_t cap = - config.GetInt64Value(server::CONFIG_CACHE_CPU_MEM_CAPACITY, std::stoi(server::CONFIG_CACHE_CPU_MEM_CAPACITY_DEFAULT)); - cap *= unit; + server::ServerConfig& config = server::ServerConfig::GetInstance(); + int64_t cap = config.GetCacheConfigCpuMemCapacity() * unit; cache_ = std::make_shared>(cap, 1UL<<32); - double free_percent = - config.GetDoubleValue(server::CONFIG_CACHE_CPU_MEM_THRESHOLD, std::stof(server::CONFIG_CACHE_CPU_MEM_THRESHOLD_DEFAULT)); - if(free_percent > 0.0 && free_percent <= 1.0) { - cache_->set_freemem_percent(free_percent); + float cpu_mem_threshold = config.GetCacheConfigCpuMemThreshold(); + if (cpu_mem_threshold > 0.0 && cpu_mem_threshold <= 1.0) { + cache_->set_freemem_percent(cpu_mem_threshold); } else { - SERVER_LOG_ERROR << "Invalid cache_free_percent: " << free_percent << - ", defaultly set to " << cache_->freemem_percent(); + SERVER_LOG_ERROR << "Invalid cpu_mem_threshold: " << cpu_mem_threshold + << ", by default set to " << cache_->freemem_percent(); } } diff --git a/cpp/src/cache/GpuCacheMgr.cpp b/cpp/src/cache/GpuCacheMgr.cpp index 58c7db3fd636c0fd83a69eceb556157234238828..ba5665f5f2b43e6fce22c28165eb4630f2a5dbad 100644 --- a/cpp/src/cache/GpuCacheMgr.cpp +++ b/cpp/src/cache/GpuCacheMgr.cpp @@ -33,20 +33,17 @@ namespace { } GpuCacheMgr::GpuCacheMgr() { - server::ConfigNode& config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_CACHE); + server::ServerConfig& config = server::ServerConfig::GetInstance(); - int64_t cap = - config.GetInt64Value(server::CONFIG_CACHE_GPU_MEM_CAPACITY, std::stoi(server::CONFIG_CACHE_GPU_MEM_CAPACITY_DEFAULT)); - cap *= G_BYTE; + int32_t cap = config.GetCacheConfigGpuMemCapacity() * G_BYTE; cache_ = std::make_shared>(cap, 1UL<<32); - double free_percent = - config.GetDoubleValue(server::CONFIG_CACHE_GPU_MEM_THRESHOLD, std::stof(server::CONFIG_CACHE_GPU_MEM_THRESHOLD_DEFAULT)); - if (free_percent > 0.0 && free_percent <= 1.0) { - cache_->set_freemem_percent(free_percent); + float gpu_mem_threshold = config.GetCacheConfigGpuMemThreshold(); + if (gpu_mem_threshold > 0.0 && gpu_mem_threshold <= 1.0) { + cache_->set_freemem_percent(gpu_mem_threshold); } else { - SERVER_LOG_ERROR << "Invalid gpu_cache_free_percent: " << free_percent << - ", defaultly set to " << cache_->freemem_percent(); + SERVER_LOG_ERROR << "Invalid gpu_mem_threshold: " << gpu_mem_threshold + << ", by default set to " << cache_->freemem_percent(); } } diff --git a/cpp/src/db/engine/ExecutionEngineImpl.cpp b/cpp/src/db/engine/ExecutionEngineImpl.cpp index 65483690d6a175c26014aa1e0552d95fe7e11f29..960f3baa89fee523673deb85339eb0a1f49ff352 100644 --- a/cpp/src/db/engine/ExecutionEngineImpl.cpp +++ b/cpp/src/db/engine/ExecutionEngineImpl.cpp @@ -335,8 +335,7 @@ Status ExecutionEngineImpl::GpuCache(uint64_t gpu_id) { Status ExecutionEngineImpl::Init() { using namespace zilliz::milvus::server; ServerConfig &config = ServerConfig::GetInstance(); - ConfigNode server_config = config.GetConfig(CONFIG_DB); - gpu_num_ = server_config.GetInt32Value(CONFIG_DB_BUILD_INDEX_GPU, std::stoi(CONFIG_DB_BUILD_INDEX_GPU_DEFAULT)); + gpu_num_ = config.GetDBConfigBuildIndexGPU(); return Status::OK(); } diff --git a/cpp/src/metrics/Metrics.cpp b/cpp/src/metrics/Metrics.cpp index ba51d7fd94c283eece16fe792152e045ce6464b6..59eaea63556030d81289acfd8fa4204f95ff5fc4 100644 --- a/cpp/src/metrics/Metrics.cpp +++ b/cpp/src/metrics/Metrics.cpp @@ -16,6 +16,7 @@ // under the License. #include "Metrics.h" +#include "server/ServerConfig.h" #include "PrometheusMetrics.h" @@ -31,9 +32,8 @@ Metrics::GetInstance() { MetricsBase & Metrics::CreateMetricsCollector() { - ConfigNode &config = ServerConfig::GetInstance().GetConfig(CONFIG_METRIC); - std::string collector_type_str = - config.GetValue(CONFIG_METRIC_COLLECTOR, CONFIG_METRIC_COLLECTOR_DEFAULT); + ServerConfig &config = ServerConfig::GetInstance(); + std::string collector_type_str = config.GetMetricConfigCollector(); if (collector_type_str == "prometheus") { return PrometheusMetrics::GetInstance(); diff --git a/cpp/src/metrics/PrometheusMetrics.cpp b/cpp/src/metrics/PrometheusMetrics.cpp index cc8aca204fb33af181b64a8431d1b56ad0044a68..b07e91ea32daa87b0161d203d1efb1688edd1c50 100644 --- a/cpp/src/metrics/PrometheusMetrics.cpp +++ b/cpp/src/metrics/PrometheusMetrics.cpp @@ -29,15 +29,12 @@ namespace server { ErrorCode PrometheusMetrics::Init() { try { - ConfigNode &metric_config = ServerConfig::GetInstance().GetConfig(CONFIG_METRIC); - startup_ = - metric_config.GetBoolValue(CONFIG_METRIC_AUTO_BOOTUP, std::stoi(CONFIG_METRIC_AUTO_BOOTUP_DEFAULT)); + ServerConfig &config = ServerConfig::GetInstance(); + startup_ = config.GetMetricConfigAutoBootup(); if (!startup_) return SERVER_SUCCESS; // Following should be read from config file. - ConfigNode &prometheus_config = metric_config.GetChild(CONFIG_METRIC_PROMETHEUS); - const std::string bind_address = - prometheus_config.GetValue(CONFIG_METRIC_PROMETHEUS_PORT, CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT); + const std::string bind_address = config.GetMetricConfigPrometheusPort(); const std::string uri = std::string("/tmp/metrics"); const std::size_t num_threads = 2; diff --git a/cpp/src/scheduler/SchedInst.cpp b/cpp/src/scheduler/SchedInst.cpp index 0b1e7cd3025d4919453b33d411eaef9a41616658..54b870100ab2ba40eec4b404bec954c88e081b61 100644 --- a/cpp/src/scheduler/SchedInst.cpp +++ b/cpp/src/scheduler/SchedInst.cpp @@ -38,10 +38,9 @@ std::mutex JobMgrInst::mutex_; void load_simple_config() { - server::ConfigNode &config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_RESOURCE); - auto mode = config.GetValue(server::CONFIG_RESOURCE_MODE, server::CONFIG_RESOURCE_MODE_DEFAULT); - - auto pool = config.GetSequence(server::CONFIG_RESOURCE_POOL); + server::ServerConfig &config = server::ServerConfig::GetInstance(); + auto mode = config.GetResourceConfigMode(); + auto pool = config.GetResourceConfigPool(); bool cpu = false; std::set gpu_ids; for (auto &resource : pool) { diff --git a/cpp/src/server/DBWrapper.cpp b/cpp/src/server/DBWrapper.cpp index 756438dfb347838afb0627a001c07fcb85ac8657..3d958b15a4dc0748b793efa4d51e70bf37eeb036 100644 --- a/cpp/src/server/DBWrapper.cpp +++ b/cpp/src/server/DBWrapper.cpp @@ -35,23 +35,20 @@ DBWrapper::DBWrapper() { } Status DBWrapper::StartService() { + ServerConfig& config = ServerConfig::GetInstance(); + //db config engine::DBOptions opt; - ConfigNode& db_config = ServerConfig::GetInstance().GetConfig(CONFIG_DB); - opt.meta.backend_uri = db_config.GetValue(CONFIG_DB_BACKEND_URL); - std::string db_path = db_config.GetValue(CONFIG_DB_PATH); - opt.meta.path = db_path + "/db"; + opt.meta.backend_uri = config.GetDBConfigBackendUrl(); + opt.meta.path = config.GetDBConfigPath() + "/db"; - std::string db_slave_path = db_config.GetValue(CONFIG_DB_SLAVE_PATH); + std::string db_slave_path = config.GetDBConfigSlavePath(); StringHelpFunctions::SplitStringByDelimeter(db_slave_path, ";", opt.meta.slave_paths); // cache config - ConfigNode& cache_config = ServerConfig::GetInstance().GetConfig(CONFIG_CACHE); - opt.insert_cache_immediately_ = - cache_config.GetBoolValue(CONFIG_CACHE_INSERT_IMMEDIATELY, std::stoi(CONFIG_CACHE_INSERT_IMMEDIATELY_DEFAULT)); + opt.insert_cache_immediately_ = config.GetCacheConfigCacheInsertData(); - ConfigNode& serverConfig = ServerConfig::GetInstance().GetConfig(CONFIG_SERVER); - std::string mode = serverConfig.GetValue(CONFIG_SERVER_MODE, CONFIG_SERVER_MODE_DEFAULT); + std::string mode = config.GetServerConfigMode(); if (mode == "single") { opt.mode = engine::DBOptions::MODE::SINGLE; } @@ -67,9 +64,7 @@ Status DBWrapper::StartService() { } // engine config - ConfigNode& engine_config = ServerConfig::GetInstance().GetConfig(CONFIG_ENGINE); - int32_t omp_thread = - engine_config.GetInt32Value(CONFIG_ENGINE_OMP_THREAD_NUM, std::stoi(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT)); + int32_t omp_thread = config.GetEngineConfigOmpThreadNum(); if(omp_thread > 0) { omp_set_num_threads(omp_thread); SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread; @@ -82,19 +77,16 @@ Status DBWrapper::StartService() { } //init faiss global variable - faiss::distance_compute_blas_threshold = - engine_config.GetInt32Value(CONFIG_ENGINE_BLAS_THRESHOLD, std::stoi(CONFIG_ENGINE_BLAS_THRESHOLD_DEFAULT)); + faiss::distance_compute_blas_threshold = config.GetEngineConfigBlasThreshold(); //set archive config engine::ArchiveConf::CriteriaT criterial; - int64_t disk = - db_config.GetInt64Value(CONFIG_DB_ARCHIVE_DISK_THRESHOLD, std::stoi(CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT)); - int64_t days = - db_config.GetInt64Value(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, std::stoi(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT)); - if(disk > 0) { + int32_t disk = config.GetDBConfigArchiveDiskThreshold(); + int32_t days = config.GetDBConfigArchiveDaysThreshold(); + if (disk > 0) { criterial[engine::ARCHIVE_CONF_DISK] = disk; } - if(days > 0) { + if (days > 0) { criterial[engine::ARCHIVE_CONF_DAYS] = days; } opt.meta.archive_conf.SetCriterias(criterial); diff --git a/cpp/src/server/Server.cpp b/cpp/src/server/Server.cpp index 7f85ed6509540dd942a2ae588473a7c3e28fb9e8..d8924e9d7dabc077a9de514cc9d10c16d446a994 100644 --- a/cpp/src/server/Server.cpp +++ b/cpp/src/server/Server.cpp @@ -162,9 +162,7 @@ Server::Start() { /* log path is defined in Config file, so InitLog must be called after LoadConfig */ ServerConfig &config = ServerConfig::GetInstance(); - ConfigNode server_config = config.GetConfig(CONFIG_SERVER); - - std::string time_zone = server_config.GetValue(CONFIG_SERVER_TIME_ZONE, CONFIG_SERVER_TIME_ZONE_DEFAULT); + std::string time_zone = config.GetServerConfigTimeZone(); if (time_zone.length() == 3) { time_zone = "CUT"; } else { @@ -232,8 +230,9 @@ Server::Stop() { ErrorCode Server::LoadConfig() { - ServerConfig::GetInstance().LoadConfigFile(config_filename_); - auto status = ServerConfig::GetInstance().ValidateConfig(); + ServerConfig& server_config = ServerConfig::GetInstance(); + server_config.LoadConfigFile(config_filename_); + auto status = server_config.ValidateConfig(); if (!status.ok()) { std::cerr << "Failed to load config file: " << config_filename_ << std::endl; exit(0); diff --git a/cpp/src/server/ServerConfig.cpp b/cpp/src/server/ServerConfig.cpp index 0f51ecf6e2a7f20c3240d9fa17cedff1ee2d9fa2..35012192e888cd37fa80edbf99ee3c3f6528a59c 100644 --- a/cpp/src/server/ServerConfig.cpp +++ b/cpp/src/server/ServerConfig.cpp @@ -42,30 +42,29 @@ ServerConfig::GetInstance() { } Status -ServerConfig::LoadConfigFile(const std::string &config_filename) { - std::string filename = config_filename; +ServerConfig::LoadConfigFile(const std::string &filename) { if (filename.empty()) { - std::cerr << "ERROR: a config file is required" << std::endl; - exit(1);//directly exit program if config file not specified + std::cerr << "ERROR: need specify config file" << std::endl; + exit(1); } - struct stat directoryStat; - int statOK = stat(filename.c_str(), &directoryStat); + struct stat dirStat; + int statOK = stat(filename.c_str(), &dirStat); if (statOK != 0) { - std::cerr << "ERROR: " << filename << " not found!" << std::endl; - exit(1);//directly exit program if config file not found + std::cerr << "ERROR: Config file not exist: " << filename << std::endl; + exit(1); } try { ConfigMgr *mgr = const_cast(ConfigMgr::GetInstance()); ErrorCode err = mgr->LoadConfigFile(filename); if (err != 0) { - std::cerr << "Server failed to load config file" << std::endl; - exit(1);//directly exit program if the config file is illegal + std::cerr << "Server failed to load config file: " << filename << std::endl; + exit(1); } } catch (YAML::Exception &e) { - std::cerr << "Server failed to load config file: " << std::endl; - exit(1);//directly exit program if the config file is illegal + std::cerr << "Server failed to load config file: " << filename << std::endl; + exit(1); } return Status::OK(); @@ -73,27 +72,25 @@ ServerConfig::LoadConfigFile(const std::string &config_filename) { Status ServerConfig::ValidateConfig() { - - bool okay = true; if (!CheckServerConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "Server config validation check fail"); } if (!CheckDBConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "DB config validation check fail"); } if (!CheckMetricConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "Metric config validation check fail"); } if (!CheckCacheConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "Cache config validation check fail"); } if (!CheckEngineConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "Engine config validation check fail"); } if (!CheckResourceConfig().ok()) { - okay = false; + return Status(SERVER_INVALID_ARGUMENT, "Resource config validation check fail"); } - return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Config validation not pass")); + return Status::OK(); } Status @@ -201,18 +198,18 @@ ServerConfig::CheckDBConfig() { okay = false; } - std::string insert_buffer_size_str = db_config.GetValue(CONFIG_DB_BUFFER_SIZE, CONFIG_DB_BUFFER_SIZE_DEFAULT); - if (!ValidationUtil::ValidateStringIsNumber(insert_buffer_size_str).ok()) { - std::cerr << "ERROR: insert_buffer_size " << insert_buffer_size_str << " is not a number" << std::endl; + std::string buffer_size_str = db_config.GetValue(CONFIG_DB_BUFFER_SIZE, CONFIG_DB_BUFFER_SIZE_DEFAULT); + if (!ValidationUtil::ValidateStringIsNumber(buffer_size_str).ok()) { + std::cerr << "ERROR: buffer_size " << buffer_size_str << " is not a number" << std::endl; okay = false; } else { - uint64_t insert_buffer_size = (uint64_t) std::stol(insert_buffer_size_str); - insert_buffer_size *= GB; + uint64_t buffer_size = (uint64_t) std::stol(buffer_size_str); + buffer_size *= GB; unsigned long total_mem = 0, free_mem = 0; CommonUtil::GetSystemMemInfo(total_mem, free_mem); - if (insert_buffer_size >= total_mem) { - std::cerr << "ERROR: insert_buffer_size exceed system memory" << std::endl; + if (buffer_size >= total_mem) { + std::cerr << "ERROR: buffer_size exceed system memory" << std::endl; okay = false; } } @@ -317,7 +314,7 @@ ServerConfig::CheckCacheConfig() { } std::string insert_cache_immediately_str = - cache_config.GetValue(CONFIG_CACHE_INSERT_IMMEDIATELY, CONFIG_CACHE_INSERT_IMMEDIATELY_DEFAULT); + cache_config.GetValue(CONFIG_CACHE_CACHE_INSERT_DATA, CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT); if (!ValidationUtil::ValidateStringIsBool(insert_cache_immediately_str).ok()) { std::cerr << "ERROR: invalid insert_cache_immediately config: " << insert_cache_immediately_str << std::endl; okay = false; @@ -629,6 +626,171 @@ ServerConfig::GetConfig(const std::string &name) { return root_node.GetChild(name); } +/* server config */ +std::string +ServerConfig::GetServerConfigAddress() { + ConfigNode server_config = GetConfig(CONFIG_SERVER); + return server_config.GetValue(CONFIG_SERVER_ADDRESS, + CONFIG_SERVER_ADDRESS_DEFAULT); +} + +std::string +ServerConfig::GetServerConfigPort() { + ConfigNode server_config = GetConfig(CONFIG_SERVER); + return server_config.GetValue(CONFIG_SERVER_PORT, + CONFIG_SERVER_PORT_DEFAULT); +} + +std::string +ServerConfig::GetServerConfigMode() { + ConfigNode server_config = GetConfig(CONFIG_SERVER); + return server_config.GetValue(CONFIG_SERVER_MODE, + CONFIG_SERVER_MODE_DEFAULT); +} + +std::string +ServerConfig::GetServerConfigTimeZone() { + ConfigNode server_config = GetConfig(CONFIG_SERVER); + return server_config.GetValue(CONFIG_SERVER_TIME_ZONE, + CONFIG_SERVER_TIME_ZONE_DEFAULT); +} + +/* db config */ +std::string +ServerConfig::GetDBConfigPath() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetValue(CONFIG_DB_PATH, + CONFIG_DB_PATH_DEFAULT); +} + +std::string +ServerConfig::GetDBConfigSlavePath() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetValue(CONFIG_DB_SLAVE_PATH, + CONFIG_DB_SLAVE_PATH_DEFAULT); +} + +std::string +ServerConfig::GetDBConfigBackendUrl() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetValue(CONFIG_DB_BACKEND_URL, + CONFIG_DB_BACKEND_URL_DEFAULT); +} + +int32_t +ServerConfig::GetDBConfigArchiveDiskThreshold() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetInt32Value(CONFIG_DB_ARCHIVE_DISK_THRESHOLD, + std::stoi(CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT)); +} + +int32_t +ServerConfig::GetDBConfigArchiveDaysThreshold() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetInt32Value(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, + std::stoi(CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT)); +} + +int32_t +ServerConfig::GetDBConfigBufferSize() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetInt32Value(CONFIG_DB_BUFFER_SIZE, + std::stoi(CONFIG_DB_BUFFER_SIZE_DEFAULT)); +} + +int32_t +ServerConfig::GetDBConfigBuildIndexGPU() { + ConfigNode db_config = GetConfig(CONFIG_DB); + return db_config.GetInt32Value(CONFIG_DB_BUILD_INDEX_GPU, + std::stoi(CONFIG_DB_BUILD_INDEX_GPU_DEFAULT)); +} + +/* metric config */ +bool +ServerConfig::GetMetricConfigAutoBootup() { + ConfigNode metric_config = GetConfig(CONFIG_METRIC); + return metric_config.GetBoolValue(CONFIG_METRIC_AUTO_BOOTUP, + std::stoi(CONFIG_METRIC_AUTO_BOOTUP_DEFAULT)); +} + +std::string +ServerConfig::GetMetricConfigCollector() { + ConfigNode metric_config = GetConfig(CONFIG_METRIC); + return metric_config.GetValue(CONFIG_METRIC_COLLECTOR, + CONFIG_METRIC_COLLECTOR_DEFAULT); +} + +std::string +ServerConfig::GetMetricConfigPrometheusPort() { + ConfigNode metric_config = GetConfig(CONFIG_METRIC); + return metric_config.GetValue(CONFIG_METRIC_PROMETHEUS_PORT, + CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT); +} + +/* cache config */ +int32_t +ServerConfig::GetCacheConfigCpuMemCapacity() { + ConfigNode cache_config = GetConfig(CONFIG_CACHE); + return cache_config.GetInt32Value(CONFIG_CACHE_CPU_MEM_CAPACITY, + std::stoi(CONFIG_CACHE_CPU_MEM_CAPACITY_DEFAULT)); +} + +float +ServerConfig::GetCacheConfigCpuMemThreshold() { + ConfigNode cache_config = GetConfig(CONFIG_CACHE); + return cache_config.GetFloatValue(CONFIG_CACHE_CPU_MEM_THRESHOLD, + std::stof(CONFIG_CACHE_CPU_MEM_THRESHOLD_DEFAULT)); +} + +int32_t +ServerConfig::GetCacheConfigGpuMemCapacity() { + ConfigNode cache_config = GetConfig(CONFIG_CACHE); + return cache_config.GetInt32Value(CONFIG_CACHE_GPU_MEM_CAPACITY, + std::stoi(CONFIG_CACHE_GPU_MEM_CAPACITY_DEFAULT)); +} + +float +ServerConfig::GetCacheConfigGpuMemThreshold() { + ConfigNode cache_config = GetConfig(CONFIG_CACHE); + return cache_config.GetFloatValue(CONFIG_CACHE_GPU_MEM_THRESHOLD, + std::stof(CONFIG_CACHE_GPU_MEM_THRESHOLD_DEFAULT)); +} + +bool +ServerConfig::GetCacheConfigCacheInsertData() { + ConfigNode cache_config = GetConfig(CONFIG_CACHE); + return cache_config.GetBoolValue(CONFIG_CACHE_CACHE_INSERT_DATA, + std::stoi(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT)); +} + +/* engine config */ +int32_t +ServerConfig::GetEngineConfigBlasThreshold() { + ConfigNode engine_config = GetConfig(CONFIG_ENGINE); + return engine_config.GetInt32Value(CONFIG_ENGINE_BLAS_THRESHOLD, + std::stoi(CONFIG_ENGINE_BLAS_THRESHOLD_DEFAULT)); +} + +int32_t +ServerConfig::GetEngineConfigOmpThreadNum() { + ConfigNode engine_config = GetConfig(CONFIG_ENGINE); + return engine_config.GetInt32Value(CONFIG_ENGINE_OMP_THREAD_NUM, + std::stoi(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT)); +} + +/* resource config */ +std::string +ServerConfig::GetResourceConfigMode() { + ConfigNode resource_config = GetConfig(CONFIG_RESOURCE); + return resource_config.GetValue(CONFIG_RESOURCE_MODE, + CONFIG_RESOURCE_MODE_DEFAULT); +} + +std::vector +ServerConfig::GetResourceConfigPool() { + ConfigNode resource_config = GetConfig(CONFIG_RESOURCE); + return resource_config.GetSequence(CONFIG_RESOURCE_POOL); +} } } diff --git a/cpp/src/server/ServerConfig.h b/cpp/src/server/ServerConfig.h index e515b74645e8efaea0630c1c606544f410e3d72e..1453adde49d5a4173f22de90f576f854240a72d2 100644 --- a/cpp/src/server/ServerConfig.h +++ b/cpp/src/server/ServerConfig.h @@ -39,11 +39,11 @@ static const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8"; /* db config */ static const char* CONFIG_DB = "db_config"; -static const char* CONFIG_DB_PATH = "db_path"; +static const char* CONFIG_DB_PATH = "path"; static const char* CONFIG_DB_PATH_DEFAULT = "/tmp/milvus"; -static const char* CONFIG_DB_SLAVE_PATH = "db_slave_path"; +static const char* CONFIG_DB_SLAVE_PATH = "slave_path"; static const char* CONFIG_DB_SLAVE_PATH_DEFAULT = ""; -static const char* CONFIG_DB_BACKEND_URL = "db_backend_url"; +static const char* CONFIG_DB_BACKEND_URL = "backend_url"; static const char* CONFIG_DB_BACKEND_URL_DEFAULT = "sqlite://:@:/"; static const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD = "archive_disk_threshold"; static const char* CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT = "0"; @@ -64,8 +64,8 @@ static const char* CONFIG_CACHE_CPU_MEM_THRESHOLD = "cpu_mem_threshold"; static const char* CONFIG_CACHE_CPU_MEM_THRESHOLD_DEFAULT = "0.85"; static const char* CONFIG_CACHE_GPU_MEM_THRESHOLD = "gpu_mem_threshold"; static const char* CONFIG_CACHE_GPU_MEM_THRESHOLD_DEFAULT = "0.85"; -static const char* CONFIG_CACHE_INSERT_IMMEDIATELY = "insert_immediately"; -static const char* CONFIG_CACHE_INSERT_IMMEDIATELY_DEFAULT = "0"; +static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data"; +static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "0"; /* metric config */ static const char* CONFIG_METRIC = "metric_config"; @@ -95,20 +95,51 @@ class ServerConfig { public: static ServerConfig &GetInstance(); - Status LoadConfigFile(const std::string& config_filename); + Status LoadConfigFile(const std::string& filename); Status ValidateConfig(); void PrintAll() const; + private: ConfigNode GetConfig(const std::string& name) const; ConfigNode& GetConfig(const std::string& name); - private: Status CheckServerConfig(); Status CheckDBConfig(); Status CheckMetricConfig(); Status CheckCacheConfig(); Status CheckEngineConfig(); Status CheckResourceConfig(); + + public: + std::string GetServerConfigAddress(); + std::string GetServerConfigPort(); + std::string GetServerConfigMode(); + std::string GetServerConfigTimeZone(); + + std::string GetDBConfigPath(); + std::string GetDBConfigSlavePath(); + std::string GetDBConfigBackendUrl(); + int32_t GetDBConfigArchiveDiskThreshold(); + int32_t GetDBConfigArchiveDaysThreshold(); + int32_t GetDBConfigBufferSize(); + int32_t GetDBConfigBuildIndexGPU(); + + bool GetMetricConfigAutoBootup(); + std::string GetMetricConfigCollector(); + std::string GetMetricConfigPrometheusPort(); + + int32_t GetCacheConfigCpuMemCapacity(); + float GetCacheConfigCpuMemThreshold(); + int32_t GetCacheConfigGpuMemCapacity(); + float GetCacheConfigGpuMemThreshold(); + bool GetCacheConfigCacheInsertData(); + + int32_t GetEngineConfigBlasThreshold(); + int32_t GetEngineConfigOmpThreadNum(); + + std::string GetResourceConfigMode(); + std::vector + GetResourceConfigPool(); }; } diff --git a/cpp/src/server/grpc_impl/GrpcServer.cpp b/cpp/src/server/grpc_impl/GrpcServer.cpp index 5160e0c8add6d9c92e5566a1704bf5c3f1e8bbed..e330f5483c9f0b9eed5a46e5b81e8c32bedbbce2 100644 --- a/cpp/src/server/grpc_impl/GrpcServer.cpp +++ b/cpp/src/server/grpc_impl/GrpcServer.cpp @@ -74,12 +74,10 @@ GrpcServer::Stop() { Status GrpcServer::StartService() { ServerConfig &config = ServerConfig::GetInstance(); - ConfigNode server_config = config.GetConfig(CONFIG_SERVER); - ConfigNode engine_config = config.GetConfig(CONFIG_ENGINE); - std::string address = server_config.GetValue(CONFIG_SERVER_ADDRESS, CONFIG_SERVER_ADDRESS_DEFAULT); - int32_t port = server_config.GetInt32Value(CONFIG_SERVER_PORT, std::stoi(CONFIG_SERVER_PORT_DEFAULT)); + std::string address = config.GetServerConfigAddress(); + std::string port = config.GetServerConfigPort(); - std::string server_address(address + ":" + std::to_string(port)); + std::string server_address(address + ":" + port); ::grpc::ServerBuilder builder; builder.SetOption(std::unique_ptr<::grpc::ServerBuilderOption>(new NoReusePortOption)); diff --git a/cpp/src/wrapper/KnowhereResource.cpp b/cpp/src/wrapper/KnowhereResource.cpp index e59b56b5742a28eb8779530d6425910bd197e872..dfd75df25376c49645d9fde1e6e06d4b17495fbf 100644 --- a/cpp/src/wrapper/KnowhereResource.cpp +++ b/cpp/src/wrapper/KnowhereResource.cpp @@ -38,16 +38,13 @@ ErrorCode KnowhereResource::Initialize() { GpuResourcesArray gpu_resources; //get build index gpu resource - server::ServerConfig& root_config = server::ServerConfig::GetInstance(); - server::ConfigNode& db_config = root_config.GetConfig(server::CONFIG_DB); + server::ServerConfig& config = server::ServerConfig::GetInstance(); - int32_t build_index_gpu = - db_config.GetInt32Value(server::CONFIG_DB_BUILD_INDEX_GPU, std::stoi(server::CONFIG_DB_BUILD_INDEX_GPU_DEFAULT)); + int32_t build_index_gpu = config.GetDBConfigBuildIndexGPU(); gpu_resources.insert(std::make_pair(build_index_gpu, GpuResourceSetting())); //get search gpu resource - server::ConfigNode& res_config = root_config.GetConfig(server::CONFIG_RESOURCE); - auto pool = res_config.GetSequence(server::CONFIG_RESOURCE_POOL); + auto pool = config.GetResourceConfigPool(); std::set gpu_ids; for (auto &resource : pool) { if (resource.length() < 4 || resource.substr(0, 3) != "gpu") {