mirror of https://github.com/milvus-io/milvus.git
Merge branch 'branch-0.4.0' into 'branch-0.4.0'
MS-384 Add global instance of ResourceMgr and Scheduler See merge request megasearch/milvus!391 Former-commit-id: 1030c47545d1d972c64ab967188f0e6ccf7b287epull/191/head
commit
3b31d63b53
|
@ -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
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*******************************************************************************
|
||||
* 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)
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* 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_;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*******************************************************************************
|
||||
* 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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue