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

Y
yudong.cai 已提交
20
#include <mutex>
S
starlord 已提交
21
#include <string>
Y
yudong.cai 已提交
22
#include <unordered_map>
S
starlord 已提交
23
#include <vector>
S
starlord 已提交
24

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

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

31
/* server config */
S
starlord 已提交
32 33 34 35 36 37 38 39 40
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 已提交
41

42
/* db config */
S
starlord 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55
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";
S
starlord 已提交
56
static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table";
G
groot 已提交
57

58
/* cache config */
S
starlord 已提交
59 60 61 62
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";
63
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT = "4";
S
starlord 已提交
64 65 66 67 68 69
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";
70 71

/* metric config */
S
starlord 已提交
72 73 74 75 76 77 78 79
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 已提交
80

81
/* engine config */
S
starlord 已提交
82 83 84 85 86
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 已提交
87

88
/* resource config */
S
starlord 已提交
89 90 91
static const char* CONFIG_RESOURCE = "resource_config";
static const char* CONFIG_RESOURCE_MODE = "mode";
static const char* CONFIG_RESOURCE_MODE_DEFAULT = "simple";
92 93 94
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES = "search_resources";
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE = "index_build_device";
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT = "gpu0";
W
wxyu 已提交
95

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

Y
yudong.cai 已提交
109
 private:
S
starlord 已提交
110 111 112 113 114 115 116 117
    ConfigNode&
    GetConfigNode(const std::string& name);
    Status
    GetConfigValueInMem(const std::string& parent_key, const std::string& child_key, std::string& value);
    void
    SetConfigValueInMem(const std::string& parent_key, const std::string& child_key, const std::string& value);
    void
    PrintConfigSection(const std::string& config_node_name);
Y
yudong.cai 已提交
118 119 120

    ///////////////////////////////////////////////////////////////////////////
    /* server config */
S
starlord 已提交
121 122 123 124 125 126 127 128
    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 已提交
129 130

    /* db config */
S
starlord 已提交
131 132 133 134 135 136 137 138 139 140 141 142
    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);
Y
yudong.cai 已提交
143 144

    /* metric config */
S
starlord 已提交
145 146 147 148 149 150
    Status
    CheckMetricConfigEnableMonitor(const std::string& value);
    Status
    CheckMetricConfigCollector(const std::string& value);
    Status
    CheckMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
151 152

    /* cache config */
S
starlord 已提交
153 154 155 156 157 158 159 160 161 162
    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 已提交
163 164

    /* engine config */
S
starlord 已提交
165 166 167 168
    Status
    CheckEngineConfigUseBlasThreshold(const std::string& value);
    Status
    CheckEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
169 170

    /* resource config */
S
starlord 已提交
171 172 173
    Status
    CheckResourceConfigMode(const std::string& value);
    Status
174 175 176
    CheckResourceConfigSearchResources(const std::vector<std::string>& value);
    Status
    CheckResourceConfigIndexBuildDevice(const std::string& value);
Y
yudong.cai 已提交
177

S
starlord 已提交
178
    std::string
S
starlord 已提交
179
    GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = "");
180

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

    /* db config */
S
starlord 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205
    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
S
starlord 已提交
206
    GetDBConfigPreloadTable(std::string& value);
207 208

    /* metric config */
S
starlord 已提交
209 210 211 212 213 214
    Status
    GetMetricConfigEnableMonitor(bool& value);
    Status
    GetMetricConfigCollector(std::string& value);
    Status
    GetMetricConfigPrometheusPort(std::string& value);
215 216

    /* cache config */
S
starlord 已提交
217
    Status
W
wxyu 已提交
218
    GetCacheConfigCpuCacheCapacity(int64_t& value);
S
starlord 已提交
219 220 221
    Status
    GetCacheConfigCpuCacheThreshold(float& value);
    Status
W
wxyu 已提交
222
    GetCacheConfigGpuCacheCapacity(int64_t& value);
S
starlord 已提交
223 224 225 226
    Status
    GetCacheConfigGpuCacheThreshold(float& value);
    Status
    GetCacheConfigCacheInsertData(bool& value);
227 228

    /* engine config */
S
starlord 已提交
229 230 231 232
    Status
    GetEngineConfigUseBlasThreshold(int32_t& value);
    Status
    GetEngineConfigOmpThreadNum(int32_t& value);
233 234

    /* resource config */
S
starlord 已提交
235 236 237
    Status
    GetResourceConfigMode(std::string& value);
    Status
238 239 240
    GetResourceConfigSearchResources(std::vector<std::string>& value);
    Status
    GetResourceConfigIndexBuildDevice(int32_t& value);
Y
yudong.cai 已提交
241

Y
yudong.cai 已提交
242 243
 public:
    /* server config */
S
starlord 已提交
244 245 246 247 248 249 250 251
    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 已提交
252 253

    /* db config */
S
starlord 已提交
254 255 256 257 258 259 260 261 262 263 264 265
    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);
Y
yudong.cai 已提交
266 267

    /* metric config */
S
starlord 已提交
268 269 270 271 272 273
    Status
    SetMetricConfigEnableMonitor(const std::string& value);
    Status
    SetMetricConfigCollector(const std::string& value);
    Status
    SetMetricConfigPrometheusPort(const std::string& value);
Y
yudong.cai 已提交
274 275

    /* cache config */
S
starlord 已提交
276 277 278 279 280 281 282 283 284 285
    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 已提交
286 287

    /* engine config */
S
starlord 已提交
288 289 290 291
    Status
    SetEngineConfigUseBlasThreshold(const std::string& value);
    Status
    SetEngineConfigOmpThreadNum(const std::string& value);
Y
yudong.cai 已提交
292 293

    /* resource config */
S
starlord 已提交
294 295
    Status
    SetResourceConfigMode(const std::string& value);
296 297
    Status
    SetResourceConfigIndexBuildDevice(const std::string& value);
Y
yudong.cai 已提交
298

Y
yudong.cai 已提交
299 300 301
 private:
    std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
    std::mutex mutex_;
G
groot 已提交
302 303
};

S
starlord 已提交
304 305
}  // namespace server
}  // namespace milvus