提交 582c4210 编写于 作者: W wxyu

MS-384 Add global instance of ResourceMgr and Scheduler


Former-commit-id: 03372f8f7b48490f5438a21be2fea1f019d2104d
上级 7014a69d
......@@ -33,6 +33,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-379 - Add Dump implementation in Resource
- MS-380 - Update resource loader and executor, work util all finished
- MS-383 - Modify condition variable usage in scheduler
- MS-384 - Add global instance of ResourceMgr and Scheduler
## New Feature
- MS-343 - Implement ResourceMgr
......
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
......@@ -61,7 +60,7 @@ public:
Stop();
void
PostEvent(const EventPtr& event);
PostEvent(const EventPtr &event);
// TODO: add stats interface(low)
......
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "SchedInst.h"
namespace zilliz {
namespace milvus {
namespace engine {
ResourceMgrPtr ResMgrInst::instance = nullptr;
std::mutex ResMgrInst::mutex_;
SchedulerPtr SchedInst::instance = nullptr;
std::mutex SchedInst::mutex_;
}
}
}
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include "ResourceMgr.h"
#include "Scheduler.h"
#include <mutex>
#include <memory>
namespace zilliz {
namespace milvus {
namespace engine {
class ResMgrInst {
public:
static ResourceMgrPtr
GetInstance() {
if (instance == nullptr) {
std::lock_guard<std::mutex> lock(mutex_);
if (instance == nullptr) {
instance = std::make_shared<ResourceMgr>();
}
}
return instance;
}
private:
static ResourceMgrPtr instance;
static std::mutex mutex_;
};
class SchedInst {
public:
static SchedulerPtr
GetInstance() {
if (instance == nullptr) {
std::lock_guard<std::mutex> lock(mutex_);
if (instance == nullptr) {
instance = std::make_shared<Scheduler>(ResMgrInst::GetInstance());
}
}
return instance;
}
private:
static SchedulerPtr instance;
static std::mutex mutex_;
};
}
}
}
......@@ -2,6 +2,7 @@
#include "scheduler/ResourceMgr.h"
#include "scheduler/Scheduler.h"
#include "scheduler/task/TestTask.h"
#include "scheduler/SchedInst.h"
#include "utils/Log.h"
#include <gtest/gtest.h>
......@@ -10,7 +11,8 @@ using namespace zilliz::milvus::engine;
TEST(normal_test, test1) {
// ResourceMgr only compose resources, provide unified event
auto res_mgr = std::make_shared<ResourceMgr>();
// auto res_mgr = std::make_shared<ResourceMgr>();
auto res_mgr = ResMgrInst::GetInstance();
auto disk = res_mgr->Add(ResourceFactory::Create("disk", "ssd"));
auto cpu = res_mgr->Add(ResourceFactory::Create("cpu"));
auto gpu1 = res_mgr->Add(ResourceFactory::Create("gpu"));
......@@ -24,10 +26,11 @@ TEST(normal_test, test1) {
res_mgr->Start();
auto scheduler = new Scheduler(res_mgr);
// auto scheduler = new Scheduler(res_mgr);
auto scheduler = SchedInst::GetInstance();
scheduler->Start();
const uint64_t NUM_TASK = 10;
const uint64_t NUM_TASK = 100;
std::vector<std::shared_ptr<TestTask>> tasks;
for (uint64_t i = 0; i < NUM_TASK; ++i) {
if (auto observe = disk.lock()) {
......@@ -37,45 +40,8 @@ TEST(normal_test, test1) {
}
}
if (auto disk_r = disk.lock()) {
if (auto cpu_r = cpu.lock()) {
if (auto gpu1_r = gpu1.lock()) {
if (auto gpu2_r = gpu2.lock()) {
std::cout << "<<<<<<<<<<before<<<<<<<<<<" << std::endl;
std::cout << "disk:" << std::endl;
std::cout << disk_r->task_table().Dump() << std::endl;
std::cout << "cpu:" << std::endl;
std::cout << cpu_r->task_table().Dump() << std::endl;
std::cout << "gpu1:" << std::endl;
std::cout << gpu1_r->task_table().Dump() << std::endl;
std::cout << "gpu2:" << std::endl;
std::cout << gpu2_r->task_table().Dump() << std::endl;
std::cout << ">>>>>>>>>>before>>>>>>>>>>" << std::endl;
}
}
}
}
sleep(1);
if (auto disk_r = disk.lock()) {
if (auto cpu_r = cpu.lock()) {
if (auto gpu1_r = gpu1.lock()) {
if (auto gpu2_r = gpu2.lock()) {
std::cout << "<<<<<<<<<<after<<<<<<<<<<" << std::endl;
std::cout << "disk:" << std::endl;
std::cout << disk_r->task_table().Dump() << std::endl;
std::cout << "cpu:" << std::endl;
std::cout << cpu_r->task_table().Dump() << std::endl;
std::cout << "gpu1:" << std::endl;
std::cout << gpu1_r->task_table().Dump() << std::endl;
std::cout << "gpu2:" << std::endl;
std::cout << gpu2_r->task_table().Dump() << std::endl;
std::cout << ">>>>>>>>>>after>>>>>>>>>>" << std::endl;
}
}
}
}
scheduler->Stop();
res_mgr->Stop();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册