Config.h 10.4 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18 19
#pragma once

S
starlord 已提交
20
#include <yaml-cpp/yaml.h>
Y
yudong.cai 已提交
21
#include <mutex>
S
starlord 已提交
22
#include <string>
Y
yudong.cai 已提交
23
#include <unordered_map>
S
starlord 已提交
24
#include <vector>
S
starlord 已提交
25

G
groot 已提交
26
#include "config/ConfigNode.h"
S
starlord 已提交
27
#include "utils/Status.h"
G
groot 已提交
28

J
jinhai 已提交
29
namespace milvus {
G
groot 已提交
30 31
namespace server {

32
/* server config */
S
starlord 已提交
33 34 35 36 37 38 39 40 41
static const char* CONFIG_SERVER = "server_config";
static const char* CONFIG_SERVER_ADDRESS = "address";
static const char* CONFIG_SERVER_ADDRESS_DEFAULT = "127.0.0.1";
static const char* CONFIG_SERVER_PORT = "port";
static const char* CONFIG_SERVER_PORT_DEFAULT = "19530";
static const char* CONFIG_SERVER_DEPLOY_MODE = "deploy_mode";
static const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT = "single";
static const char* CONFIG_SERVER_TIME_ZONE = "time_zone";
static const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8";
G
groot 已提交
42

43
/* db config */
S
starlord 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
static const char* CONFIG_DB = "db_config";
static const char* CONFIG_DB_PRIMARY_PATH = "primary_path";
static const char* CONFIG_DB_PRIMARY_PATH_DEFAULT = "/tmp/milvus";
static const char* CONFIG_DB_SECONDARY_PATH = "secondary_path";
static const char* CONFIG_DB_SECONDARY_PATH_DEFAULT = "";
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";
static const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD = "archive_days_threshold";
static const char* CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT = "0";
static const char* CONFIG_DB_INSERT_BUFFER_SIZE = "insert_buffer_size";
static const char* CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT = "4";
static const char* CONFIG_DB_BUILD_INDEX_GPU = "build_index_gpu";
static const char* CONFIG_DB_BUILD_INDEX_GPU_DEFAULT = "0";
S
starlord 已提交
59
static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table";
G
groot 已提交
60

61
/* cache config */
S
starlord 已提交
62 63 64 65 66 67 68 69 70 71 72
static const char* CONFIG_CACHE = "cache_config";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "16";
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY = "gpu_cache_capacity";
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT = "0";
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_mem_threshold";
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD = "gpu_mem_threshold";
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false";
73 74

/* metric config */
S
starlord 已提交
75 76 77 78 79 80 81 82
static const char* CONFIG_METRIC = "metric_config";
static const char* CONFIG_METRIC_ENABLE_MONITOR = "enable_monitor";
static const char* CONFIG_METRIC_ENABLE_MONITOR_DEFAULT = "false";
static const char* CONFIG_METRIC_COLLECTOR = "collector";
static const char* CONFIG_METRIC_COLLECTOR_DEFAULT = "prometheus";
static const char* CONFIG_METRIC_PROMETHEUS = "prometheus_config";
static const char* CONFIG_METRIC_PROMETHEUS_PORT = "port";
static const char* CONFIG_METRIC_PROMETHEUS_PORT_DEFAULT = "8080";
Y
yu yunfeng 已提交
83

84
/* engine config */
S
starlord 已提交
85 86 87 88 89
static const char* CONFIG_ENGINE = "engine_config";
static const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD = "use_blas_threshold";
static const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT = "20";
static const char* CONFIG_ENGINE_OMP_THREAD_NUM = "omp_thread_num";
static const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0";
Y
yu yunfeng 已提交
90

91
/* resource config */
S
starlord 已提交
92 93 94 95
static const char* CONFIG_RESOURCE = "resource_config";
static const char* CONFIG_RESOURCE_MODE = "mode";
static const char* CONFIG_RESOURCE_MODE_DEFAULT = "simple";
static const char* CONFIG_RESOURCE_POOL = "resource_pool";
W
wxyu 已提交
96

97
class Config {
G
groot 已提交
98
 public:
S
starlord 已提交
99 100 101 102 103 104 105 106 107 108
    static Config&
    GetInstance();
    Status
    LoadConfigFile(const std::string& filename);
    Status
    ValidateConfig();
    Status
    ResetDefaultConfig();
    void
    PrintAll();
G
groot 已提交
109

Y
yudong.cai 已提交
110
 private:
S
starlord 已提交
111 112
    ConfigNode&
    GetConfigNode(const std::string& name);
Z
zhiru 已提交
113

S
starlord 已提交
114 115
    Status
    GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value);
Y
yudong.cai 已提交
116

S
starlord 已提交
117 118
    void
    SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value);
Y
yudong.cai 已提交
119

S
starlord 已提交
120 121
    void
    PrintConfigSection(const std::string& config_node_name);
Y
yudong.cai 已提交
122 123 124

    ///////////////////////////////////////////////////////////////////////////
    /* server config */
S
starlord 已提交
125 126 127 128 129 130 131 132
    Status
    CheckServerConfigAddress(const std::string& value);
    Status
    CheckServerConfigPort(const std::string& value);
    Status
    CheckServerConfigDeployMode(const std::string& value);
    Status
    CheckServerConfigTimeZone(const std::string& value);
Y
yudong.cai 已提交
133 134

    /* db config */
S
starlord 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148
    Status
    CheckDBConfigPrimaryPath(const std::string& value);
    Status
    CheckDBConfigSecondaryPath(const std::string& value);
    Status
    CheckDBConfigBackendUrl(const std::string& value);
    Status
    CheckDBConfigArchiveDiskThreshold(const std::string& value);
    Status
    CheckDBConfigArchiveDaysThreshold(const std::string& value);
    Status
    CheckDBConfigInsertBufferSize(const std::string& value);
    Status
    CheckDBConfigBuildIndexGPU(const std::string& value);
Y
yudong.cai 已提交
149 150

    /* metric config */
S
starlord 已提交
151 152 153 154 155 156
    Status
    CheckMetricConfigEnableMonitor(const std::string& value);
    Status
    CheckMetricConfigCollector(const std::string& value);
    Status
    CheckMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
157 158

    /* cache config */
S
starlord 已提交
159 160 161 162 163 164 165 166 167 168
    Status
    CheckCacheConfigCpuCacheCapacity(const std::string& value);
    Status
    CheckCacheConfigCpuCacheThreshold(const std::string& value);
    Status
    CheckCacheConfigGpuCacheCapacity(const std::string& value);
    Status
    CheckCacheConfigGpuCacheThreshold(const std::string& value);
    Status
    CheckCacheConfigCacheInsertData(const std::string& value);
Y
yudong.cai 已提交
169 170

    /* engine config */
S
starlord 已提交
171 172 173 174
    Status
    CheckEngineConfigUseBlasThreshold(const std::string& value);
    Status
    CheckEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
175 176

    /* resource config */
S
starlord 已提交
177 178 179 180
    Status
    CheckResourceConfigMode(const std::string& value);
    Status
    CheckResourceConfigPool(const std::vector<std::string>& value);
Y
yudong.cai 已提交
181

S
starlord 已提交
182
    std::string
S
starlord 已提交
183
    GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = "");
184

Y
yudong.cai 已提交
185
 public:
186
    /* server config */
S
starlord 已提交
187 188 189 190 191 192 193 194
    Status
    GetServerConfigAddress(std::string& value);
    Status
    GetServerConfigPort(std::string& value);
    Status
    GetServerConfigDeployMode(std::string& value);
    Status
    GetServerConfigTimeZone(std::string& value);
195 196

    /* db config */
S
starlord 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210
    Status
    GetDBConfigPrimaryPath(std::string& value);
    Status
    GetDBConfigSecondaryPath(std::string& value);
    Status
    GetDBConfigBackendUrl(std::string& value);
    Status
    GetDBConfigArchiveDiskThreshold(int32_t& value);
    Status
    GetDBConfigArchiveDaysThreshold(int32_t& value);
    Status
    GetDBConfigInsertBufferSize(int32_t& value);
    Status
    GetDBConfigBuildIndexGPU(int32_t& value);
S
starlord 已提交
211 212
    Status
    GetDBConfigPreloadTable(std::string& value);
213 214

    /* metric config */
S
starlord 已提交
215 216 217 218 219 220
    Status
    GetMetricConfigEnableMonitor(bool& value);
    Status
    GetMetricConfigCollector(std::string& value);
    Status
    GetMetricConfigPrometheusPort(std::string& value);
221 222

    /* cache config */
S
starlord 已提交
223
    Status
W
wxyu 已提交
224
    GetCacheConfigCpuCacheCapacity(int64_t& value);
S
starlord 已提交
225 226 227
    Status
    GetCacheConfigCpuCacheThreshold(float& value);
    Status
W
wxyu 已提交
228
    GetCacheConfigGpuCacheCapacity(int64_t& value);
S
starlord 已提交
229 230 231 232
    Status
    GetCacheConfigGpuCacheThreshold(float& value);
    Status
    GetCacheConfigCacheInsertData(bool& value);
233 234

    /* engine config */
S
starlord 已提交
235 236 237 238
    Status
    GetEngineConfigUseBlasThreshold(int32_t& value);
    Status
    GetEngineConfigOmpThreadNum(int32_t& value);
239 240

    /* resource config */
S
starlord 已提交
241 242 243 244
    Status
    GetResourceConfigMode(std::string& value);
    Status
    GetResourceConfigPool(std::vector<std::string>& value);
Y
yudong.cai 已提交
245

Y
yudong.cai 已提交
246 247
 public:
    /* server config */
S
starlord 已提交
248 249 250 251 252 253 254 255
    Status
    SetServerConfigAddress(const std::string& value);
    Status
    SetServerConfigPort(const std::string& value);
    Status
    SetServerConfigDeployMode(const std::string& value);
    Status
    SetServerConfigTimeZone(const std::string& value);
Y
yudong.cai 已提交
256 257

    /* db config */
S
starlord 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271
    Status
    SetDBConfigPrimaryPath(const std::string& value);
    Status
    SetDBConfigSecondaryPath(const std::string& value);
    Status
    SetDBConfigBackendUrl(const std::string& value);
    Status
    SetDBConfigArchiveDiskThreshold(const std::string& value);
    Status
    SetDBConfigArchiveDaysThreshold(const std::string& value);
    Status
    SetDBConfigInsertBufferSize(const std::string& value);
    Status
    SetDBConfigBuildIndexGPU(const std::string& value);
Y
yudong.cai 已提交
272 273

    /* metric config */
S
starlord 已提交
274 275 276 277 278 279
    Status
    SetMetricConfigEnableMonitor(const std::string& value);
    Status
    SetMetricConfigCollector(const std::string& value);
    Status
    SetMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
280 281

    /* cache config */
S
starlord 已提交
282 283 284 285 286 287 288 289 290 291
    Status
    SetCacheConfigCpuCacheCapacity(const std::string& value);
    Status
    SetCacheConfigCpuCacheThreshold(const std::string& value);
    Status
    SetCacheConfigGpuCacheCapacity(const std::string& value);
    Status
    SetCacheConfigGpuCacheThreshold(const std::string& value);
    Status
    SetCacheConfigCacheInsertData(const std::string& value);
Y
yudong.cai 已提交
292 293

    /* engine config */
S
starlord 已提交
294 295 296 297
    Status
    SetEngineConfigUseBlasThreshold(const std::string& value);
    Status
    SetEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
298 299

    /* resource config */
S
starlord 已提交
300 301
    Status
    SetResourceConfigMode(const std::string& value);
Y
yudong.cai 已提交
302

Y
yudong.cai 已提交
303 304 305
 private:
    std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
    std::mutex mutex_;
G
groot 已提交
306 307
};

S
starlord 已提交
308 309
}  // namespace server
}  // namespace milvus