SchedInst.cpp 3.0 KB
Newer Older
1 2 3 4 5 6 7
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/

#include "SchedInst.h"
W
wxyu 已提交
8 9
#include "server/ServerConfig.h"
#include "ResourceFactory.h"
W
wxyu 已提交
10
#include "knowhere/index/vector_index/gpu_ivf.h"
11 12 13 14 15 16 17 18 19 20 21

namespace zilliz {
namespace milvus {
namespace engine {

ResourceMgrPtr ResMgrInst::instance = nullptr;
std::mutex ResMgrInst::mutex_;

SchedulerPtr SchedInst::instance = nullptr;
std::mutex SchedInst::mutex_;

W
wxyu 已提交
22
void
S
starlord 已提交
23
StartSchedulerService() {
W
wxyu 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    server::ConfigNode &config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_RESOURCE);
    auto resources = config.GetChild(server::CONFIG_RESOURCES).GetChildren();
    for (auto &resource : resources) {
        auto &resname = resource.first;
        auto &resconf = resource.second;
        auto type = resconf.GetValue(server::CONFIG_RESOURCE_TYPE);
//        auto memory = resconf.GetInt64Value(server::CONFIG_RESOURCE_MEMORY);
        auto device_id = resconf.GetInt64Value(server::CONFIG_RESOURCE_DEVICE_ID);
        auto enable_loader = resconf.GetBoolValue(server::CONFIG_RESOURCE_ENABLE_LOADER);
        auto enable_executor = resconf.GetBoolValue(server::CONFIG_RESOURCE_ENABLE_EXECUTOR);

        ResMgrInst::GetInstance()->Add(ResourceFactory::Create(resname,
                                                               type,
                                                               device_id,
                                                               enable_loader,
                                                               enable_executor));
W
wxyu 已提交
40 41

        knowhere::FaissGpuResourceMgr::GetInstance().InitDevice(device_id);
W
wxyu 已提交
42 43
    }

W
wxyu 已提交
44 45
    knowhere::FaissGpuResourceMgr::GetInstance().InitResource();

46 47
//    auto default_connection = Connection("default_connection", 500.0);
    auto connections = config.GetChild(server::CONFIG_RESOURCE_CONNECTIONS).GetChildren();
W
wxyu 已提交
48
    for (auto &conn : connections) {
49 50 51 52 53
        auto &connect_name = conn.first;
        auto &connect_conf = conn.second;
        auto connect_speed = connect_conf.GetInt64Value(server::CONFIG_SPEED_CONNECTIONS);
        auto connect_endpoint = connect_conf.GetValue(server::CONFIG_ENDPOINT_CONNECTIONS);

W
wxyu 已提交
54
        std::string delimiter = "===";
55 56 57
        std::string left = connect_endpoint.substr(0, connect_endpoint.find(delimiter));
        std::string right = connect_endpoint.substr(connect_endpoint.find(delimiter) + 3,
            connect_endpoint.length());
W
wxyu 已提交
58

59 60
        auto connection = Connection(connect_name, connect_speed);
        ResMgrInst::GetInstance()->Connect(left, right, connection);
W
wxyu 已提交
61 62 63 64 65 66
    }

    ResMgrInst::GetInstance()->Start();
    SchedInst::GetInstance()->Start();
}

S
starlord 已提交
67 68 69 70 71
void
StopSchedulerService() {
    ResMgrInst::GetInstance()->Stop();
    SchedInst::GetInstance()->Stop();
}
72 73 74
}
}
}