提交 0d0d08c2 编写于 作者: Y yudong.cai

MS-574 let all config APIs return Status


Former-commit-id: 7a843fa57779637761a80def4705a37f9805ceaf
上级 b0fe84cd
...@@ -30,10 +30,21 @@ namespace { ...@@ -30,10 +30,21 @@ namespace {
CpuCacheMgr::CpuCacheMgr() { CpuCacheMgr::CpuCacheMgr() {
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
int64_t cap = config.GetCacheConfigCpuMemCapacity() * unit; Status s;
int32_t cpu_mem_cap;
s = config.GetCacheConfigCpuMemCapacity(cpu_mem_cap);
if (!s.ok()) {
SERVER_LOG_ERROR << s.message();
}
int64_t cap = cpu_mem_cap * unit;
cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL<<32); cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL<<32);
float cpu_mem_threshold = config.GetCacheConfigCpuMemThreshold(); float cpu_mem_threshold;
s = config.GetCacheConfigCpuMemThreshold(cpu_mem_threshold);
if (!s.ok()) {
SERVER_LOG_ERROR << s.message();
}
if (cpu_mem_threshold > 0.0 && cpu_mem_threshold <= 1.0) { if (cpu_mem_threshold > 0.0 && cpu_mem_threshold <= 1.0) {
cache_->set_freemem_percent(cpu_mem_threshold); cache_->set_freemem_percent(cpu_mem_threshold);
} else { } else {
......
...@@ -34,11 +34,21 @@ namespace { ...@@ -34,11 +34,21 @@ namespace {
GpuCacheMgr::GpuCacheMgr() { GpuCacheMgr::GpuCacheMgr() {
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
Status s;
int32_t cap = config.GetCacheConfigGpuMemCapacity() * G_BYTE; int32_t gpu_mem_cap;
s = config.GetCacheConfigGpuMemCapacity(gpu_mem_cap);
if (!s.ok()) {
SERVER_LOG_ERROR << s.message();
}
int32_t cap = gpu_mem_cap * G_BYTE;
cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL<<32); cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL<<32);
float gpu_mem_threshold = config.GetCacheConfigGpuMemThreshold(); float gpu_mem_threshold;
s = config.GetCacheConfigGpuMemThreshold(gpu_mem_threshold);
if (!s.ok()) {
SERVER_LOG_ERROR << s.message();
}
if (gpu_mem_threshold > 0.0 && gpu_mem_threshold <= 1.0) { if (gpu_mem_threshold > 0.0 && gpu_mem_threshold <= 1.0) {
cache_->set_freemem_percent(gpu_mem_threshold); cache_->set_freemem_percent(gpu_mem_threshold);
} else { } else {
......
...@@ -336,7 +336,8 @@ Status ExecutionEngineImpl::GpuCache(uint64_t gpu_id) { ...@@ -336,7 +336,8 @@ Status ExecutionEngineImpl::GpuCache(uint64_t gpu_id) {
Status ExecutionEngineImpl::Init() { Status ExecutionEngineImpl::Init() {
using namespace zilliz::milvus::server; using namespace zilliz::milvus::server;
server::Config &config = server::Config::GetInstance(); server::Config &config = server::Config::GetInstance();
gpu_num_ = config.GetDBConfigBuildIndexGPU(); Status s = config.GetDBConfigBuildIndexGPU(gpu_num_);
if (!s.ok()) return s;
return Status::OK(); return Status::OK();
} }
......
...@@ -101,7 +101,7 @@ protected: ...@@ -101,7 +101,7 @@ protected:
std::string location_; std::string location_;
int32_t nlist_ = 0; int32_t nlist_ = 0;
int64_t gpu_num_ = 0; int32_t gpu_num_ = 0;
}; };
......
...@@ -33,7 +33,9 @@ Metrics::GetInstance() { ...@@ -33,7 +33,9 @@ Metrics::GetInstance() {
MetricsBase & MetricsBase &
Metrics::CreateMetricsCollector() { Metrics::CreateMetricsCollector() {
Config &config = Config::GetInstance(); Config &config = Config::GetInstance();
std::string collector_type_str = config.GetMetricConfigCollector(); std::string collector_type_str;
config.GetMetricConfigCollector(collector_type_str);
if (collector_type_str == "prometheus") { if (collector_type_str == "prometheus") {
return PrometheusMetrics::GetInstance(); return PrometheusMetrics::GetInstance();
......
...@@ -31,11 +31,14 @@ ErrorCode ...@@ -31,11 +31,14 @@ ErrorCode
PrometheusMetrics::Init() { PrometheusMetrics::Init() {
try { try {
Config &config = Config::GetInstance(); Config &config = Config::GetInstance();
startup_ = config.GetMetricConfigAutoBootup(); Status s = config.GetMetricConfigAutoBootup(startup_);
if (!s.ok()) return s.code();
if (!startup_) return SERVER_SUCCESS; if (!startup_) return SERVER_SUCCESS;
// Following should be read from config file. // Following should be read from config file.
const std::string bind_address = config.GetMetricConfigPrometheusPort(); std::string bind_address;
s = config.GetMetricConfigPrometheusPort(bind_address);
if (!s.ok()) return s.code();
const std::string uri = std::string("/tmp/metrics"); const std::string uri = std::string("/tmp/metrics");
const std::size_t num_threads = 2; const std::size_t num_threads = 2;
......
...@@ -39,8 +39,11 @@ std::mutex JobMgrInst::mutex_; ...@@ -39,8 +39,11 @@ std::mutex JobMgrInst::mutex_;
void void
load_simple_config() { load_simple_config() {
server::Config &config = server::Config::GetInstance(); server::Config &config = server::Config::GetInstance();
auto mode = config.GetResourceConfigMode(); std::string mode;
auto pool = config.GetResourceConfigPool(); config.GetResourceConfigMode(mode);
std::vector<std::string> pool;
config.GetResourceConfigPool(pool);
bool cpu = false; bool cpu = false;
std::set<uint64_t> gpu_ids; std::set<uint64_t> gpu_ids;
for (auto &resource : pool) { for (auto &resource : pool) {
......
此差异已折叠。
...@@ -102,8 +102,7 @@ class Config { ...@@ -102,8 +102,7 @@ class Config {
void PrintAll() const; void PrintAll() const;
private: private:
ConfigNode GetConfig(const std::string& name) const; ConfigNode& GetConfigNode(const std::string& name);
ConfigNode& GetConfig(const std::string& name);
Status CheckServerConfig(); Status CheckServerConfig();
Status CheckDBConfig(); Status CheckDBConfig();
...@@ -116,40 +115,80 @@ class Config { ...@@ -116,40 +115,80 @@ class Config {
const std::string& child_key, const std::string& child_key,
std::string& value); std::string& value);
void SetConfigValueInMem(const std::string& parent_key, Status SetConfigValueInMem(const std::string& parent_key,
const std::string& child_key, const std::string& child_key,
std::string& value); std::string& value);
private:
/* server config */
Status GetServerConfigStrAddress(std::string& value);
Status GetServerConfigStrPort(std::string& value);
Status GetServerConfigStrMode(std::string& value);
Status GetServerConfigStrTimeZone(std::string& value);
/* db config */
Status GetDBConfigStrPath(std::string& value);
Status GetDBConfigStrSlavePath(std::string& value);
Status GetDBConfigStrBackendUrl(std::string& value);
Status GetDBConfigStrArchiveDiskThreshold(std::string& value);
Status GetDBConfigStrArchiveDaysThreshold(std::string& value);
Status GetDBConfigStrBufferSize(std::string& value);
Status GetDBConfigStrBuildIndexGPU(std::string& value);
/* metric config */
Status GetMetricConfigStrAutoBootup(std::string& value);
Status GetMetricConfigStrCollector(std::string& value);
Status GetMetricConfigStrPrometheusPort(std::string& value);
/* cache config */
Status GetCacheConfigStrCpuMemCapacity(std::string& value);
Status GetCacheConfigStrCpuMemThreshold(std::string& value);
Status GetCacheConfigStrGpuMemCapacity(std::string& value);
Status GetCacheConfigStrGpuMemThreshold(std::string& value);
Status GetCacheConfigStrCacheInsertData(std::string& value);
/* engine config */
Status GetEngineConfigStrBlasThreshold(std::string& value);
Status GetEngineConfigStrOmpThreadNum(std::string& value);
/* resource config */
Status GetResourceConfigStrMode(std::string& value);
public: public:
std::string GetServerConfigAddress(); /* server config */
std::string GetServerConfigPort(); Status GetServerConfigAddress(std::string& value);
std::string GetServerConfigMode(); Status GetServerConfigPort(std::string& value);
std::string GetServerConfigTimeZone(); Status GetServerConfigMode(std::string& value);
Status GetServerConfigTimeZone(std::string& value);
std::string GetDBConfigPath();
std::string GetDBConfigSlavePath(); /* db config */
std::string GetDBConfigBackendUrl(); Status GetDBConfigPath(std::string& value);
int32_t GetDBConfigArchiveDiskThreshold(); Status GetDBConfigSlavePath(std::string& value);
int32_t GetDBConfigArchiveDaysThreshold(); Status GetDBConfigBackendUrl(std::string& value);
int32_t GetDBConfigBufferSize(); Status GetDBConfigArchiveDiskThreshold(int32_t& value);
int32_t GetDBConfigBuildIndexGPU(); Status GetDBConfigArchiveDaysThreshold(int32_t& value);
Status GetDBConfigBufferSize(int32_t& value);
bool GetMetricConfigAutoBootup(); Status GetDBConfigBuildIndexGPU(int32_t& value);
std::string GetMetricConfigCollector();
std::string GetMetricConfigPrometheusPort(); /* metric config */
Status GetMetricConfigAutoBootup(bool& value);
int32_t GetCacheConfigCpuMemCapacity(); Status GetMetricConfigCollector(std::string& value);
float GetCacheConfigCpuMemThreshold(); Status GetMetricConfigPrometheusPort(std::string& value);
int32_t GetCacheConfigGpuMemCapacity();
float GetCacheConfigGpuMemThreshold(); /* cache config */
bool GetCacheConfigCacheInsertData(); Status GetCacheConfigCpuMemCapacity(int32_t& value);
Status GetCacheConfigCpuMemThreshold(float& value);
int32_t GetEngineConfigBlasThreshold(); Status GetCacheConfigGpuMemCapacity(int32_t& value);
int32_t GetEngineConfigOmpThreadNum(); Status GetCacheConfigGpuMemThreshold(float& value);
Status GetCacheConfigCacheInsertData(bool& value);
std::string GetResourceConfigMode();
std::vector<std::string> /* engine config */
GetResourceConfigPool(); Status GetEngineConfigBlasThreshold(int32_t& value);
Status GetEngineConfigOmpThreadNum(int32_t& value);
/* resource config */
Status GetResourceConfigMode(std::string& value);
Status GetResourceConfigPool(std::vector<std::string>& value);
private: private:
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_; std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
......
...@@ -36,19 +36,33 @@ DBWrapper::DBWrapper() { ...@@ -36,19 +36,33 @@ DBWrapper::DBWrapper() {
Status DBWrapper::StartService() { Status DBWrapper::StartService() {
Config& config = Config::GetInstance(); Config& config = Config::GetInstance();
Status s;
//db config //db config
engine::DBOptions opt; engine::DBOptions opt;
opt.meta.backend_uri = config.GetDBConfigBackendUrl();
opt.meta.path = config.GetDBConfigPath() + "/db";
std::string db_slave_path = config.GetDBConfigSlavePath(); s = config.GetDBConfigBackendUrl(opt.meta.backend_uri);
if (!s.ok()) return s;
std::string path;
s = config.GetDBConfigPath(path);
if (!s.ok()) return s;
opt.meta.path = path + "/db";
std::string db_slave_path;
s = config.GetDBConfigSlavePath(db_slave_path);
if (!s.ok()) return s;
StringHelpFunctions::SplitStringByDelimeter(db_slave_path, ";", opt.meta.slave_paths); StringHelpFunctions::SplitStringByDelimeter(db_slave_path, ";", opt.meta.slave_paths);
// cache config // cache config
opt.insert_cache_immediately_ = config.GetCacheConfigCacheInsertData(); s = config.GetCacheConfigCacheInsertData(opt.insert_cache_immediately_);
if (!s.ok()) return s;
std::string mode;
s = config.GetServerConfigMode(mode);
if (!s.ok()) return s;
std::string mode = config.GetServerConfigMode();
if (mode == "single") { if (mode == "single") {
opt.mode = engine::DBOptions::MODE::SINGLE; opt.mode = engine::DBOptions::MODE::SINGLE;
} }
...@@ -64,8 +78,10 @@ Status DBWrapper::StartService() { ...@@ -64,8 +78,10 @@ Status DBWrapper::StartService() {
} }
// engine config // engine config
int32_t omp_thread = config.GetEngineConfigOmpThreadNum(); int32_t omp_thread;
if(omp_thread > 0) { s = config.GetEngineConfigOmpThreadNum(omp_thread);
if (!s.ok()) return s;
if (omp_thread > 0) {
omp_set_num_threads(omp_thread); omp_set_num_threads(omp_thread);
SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread; SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread;
} else { } else {
...@@ -77,15 +93,22 @@ Status DBWrapper::StartService() { ...@@ -77,15 +93,22 @@ Status DBWrapper::StartService() {
} }
//init faiss global variable //init faiss global variable
faiss::distance_compute_blas_threshold = config.GetEngineConfigBlasThreshold(); int32_t blas_threshold;
s = config.GetEngineConfigBlasThreshold(blas_threshold);
if (!s.ok()) return s;
faiss::distance_compute_blas_threshold = blas_threshold;
//set archive config //set archive config
engine::ArchiveConf::CriteriaT criterial; engine::ArchiveConf::CriteriaT criterial;
int32_t disk = config.GetDBConfigArchiveDiskThreshold(); int32_t disk, days;
int32_t days = config.GetDBConfigArchiveDaysThreshold(); s = config.GetDBConfigArchiveDiskThreshold(disk);
if (!s.ok()) return s;
if (disk > 0) { if (disk > 0) {
criterial[engine::ARCHIVE_CONF_DISK] = disk; criterial[engine::ARCHIVE_CONF_DISK] = disk;
} }
s = config.GetDBConfigArchiveDaysThreshold(days);
if (!s.ok()) return s;
if (days > 0) { if (days > 0) {
criterial[engine::ARCHIVE_CONF_DAYS] = days; criterial[engine::ARCHIVE_CONF_DAYS] = days;
} }
......
...@@ -161,7 +161,13 @@ Server::Start() { ...@@ -161,7 +161,13 @@ Server::Start() {
/* log path is defined in Config file, so InitLog must be called after LoadConfig */ /* log path is defined in Config file, so InitLog must be called after LoadConfig */
Config &config = Config::GetInstance(); Config &config = Config::GetInstance();
std::string time_zone = config.GetServerConfigTimeZone(); std::string time_zone;
Status s = config.GetServerConfigTimeZone(time_zone);
if (!s.ok()) {
std::cerr << "Fail to get server config timezone" << std::endl;
return;
}
if (time_zone.length() == 3) { if (time_zone.length() == 3) {
time_zone = "CUT"; time_zone = "CUT";
} else { } else {
......
...@@ -74,8 +74,17 @@ GrpcServer::Stop() { ...@@ -74,8 +74,17 @@ GrpcServer::Stop() {
Status Status
GrpcServer::StartService() { GrpcServer::StartService() {
Config &config = Config::GetInstance(); Config &config = Config::GetInstance();
std::string address = config.GetServerConfigAddress(); std::string address, port;
std::string port = config.GetServerConfigPort(); Status s;
s = config.GetServerConfigAddress(address);
if (!s.ok()) {
return s;
}
s = config.GetServerConfigPort(port);
if (!s.ok()) {
return s;
}
std::string server_address(address + ":" + port); std::string server_address(address + ":" + port);
......
...@@ -36,15 +36,22 @@ ErrorCode KnowhereResource::Initialize() { ...@@ -36,15 +36,22 @@ ErrorCode KnowhereResource::Initialize() {
}; };
using GpuResourcesArray = std::map<int64_t , GpuResourceSetting>; using GpuResourcesArray = std::map<int64_t , GpuResourceSetting>;
GpuResourcesArray gpu_resources; GpuResourcesArray gpu_resources;
Status s;
//get build index gpu resource //get build index gpu resource
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
int32_t build_index_gpu = config.GetDBConfigBuildIndexGPU(); int32_t build_index_gpu;
s = config.GetDBConfigBuildIndexGPU(build_index_gpu);
if (!s.ok()) return s.code();
gpu_resources.insert(std::make_pair(build_index_gpu, GpuResourceSetting())); gpu_resources.insert(std::make_pair(build_index_gpu, GpuResourceSetting()));
//get search gpu resource //get search gpu resource
auto pool = config.GetResourceConfigPool(); std::vector<std::string> pool;
s = config.GetResourceConfigPool(pool);
if (!s.ok()) return s.code();
std::set<uint64_t> gpu_ids; std::set<uint64_t> gpu_ids;
for (auto &resource : pool) { for (auto &resource : pool) {
if (resource.length() < 4 || resource.substr(0, 3) != "gpu") { if (resource.length() < 4 || resource.substr(0, 3) != "gpu") {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册