提交 7f9def46 编写于 作者: Y Yu Kun

merge upstream


Former-commit-id: 161080a5b239ecaab6bddca8dd7a539ae067c799
...@@ -45,6 +45,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -45,6 +45,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-404 - Release index after search task done avoid memory increment continues - MS-404 - Release index after search task done avoid memory increment continues
- MS-405 - Add delete task support - MS-405 - Add delete task support
- MS-407 - Reconstruct MetricsCollector - MS-407 - Reconstruct MetricsCollector
- MS-408 - Add device_id in resource construct function
## New Feature ## New Feature
- MS-343 - Implement ResourceMgr - MS-343 - Implement ResourceMgr
......
...@@ -13,15 +13,16 @@ namespace engine { ...@@ -13,15 +13,16 @@ namespace engine {
std::shared_ptr<Resource> std::shared_ptr<Resource>
ResourceFactory::Create(const std::string &name, ResourceFactory::Create(const std::string &name,
const std::string &alias, const std::string &type,
uint64_t device_id,
bool enable_loader, bool enable_loader,
bool enable_executor) { bool enable_executor) {
if (name == "disk") { if (type == "DISK") {
return std::make_shared<DiskResource>(alias, enable_loader, enable_executor); return std::make_shared<DiskResource>(name, device_id, enable_loader, enable_executor);
} else if (name == "cpu") { } else if (type == "CPU") {
return std::make_shared<CpuResource>(alias, enable_loader, enable_executor); return std::make_shared<CpuResource>(name, device_id, enable_loader, enable_executor);
} else if (name == "gpu") { } else if (type == "GPU") {
return std::make_shared<GpuResource>(alias, enable_loader, enable_executor); return std::make_shared<GpuResource>(name, device_id, enable_loader, enable_executor);
} else { } else {
return nullptr; return nullptr;
} }
......
...@@ -22,7 +22,8 @@ class ResourceFactory { ...@@ -22,7 +22,8 @@ class ResourceFactory {
public: public:
static std::shared_ptr<Resource> static std::shared_ptr<Resource>
Create(const std::string &name, Create(const std::string &name,
const std::string &alias = "", const std::string &type,
uint64_t device_id,
bool enable_loader = true, bool enable_loader = true,
bool enable_executor = true); bool enable_executor = true);
}; };
......
...@@ -48,6 +48,16 @@ ResourceMgr::Add(ResourcePtr &&resource) { ...@@ -48,6 +48,16 @@ ResourceMgr::Add(ResourcePtr &&resource) {
return ret; return ret;
} }
void
ResourceMgr::Connect(const std::string &name1, const std::string &name2, Connection &connection) {
auto res1 = get_resource_by_name(name1);
auto res2 = get_resource_by_name(name2);
if (res1 && res2) {
res1->AddNeighbour(std::static_pointer_cast<Node>(res2), connection);
res2->AddNeighbour(std::static_pointer_cast<Node>(res1), connection);
}
}
void void
ResourceMgr::Connect(ResourceWPtr &res1, ResourceWPtr &res2, Connection &connection) { ResourceMgr::Connect(ResourceWPtr &res1, ResourceWPtr &res2, Connection &connection) {
if (auto observe_a = res1.lock()) { if (auto observe_a = res1.lock()) {
...@@ -116,6 +126,16 @@ ResourceMgr::DumpTaskTables() { ...@@ -116,6 +126,16 @@ ResourceMgr::DumpTaskTables() {
return ss.str(); return ss.str();
} }
ResourcePtr
ResourceMgr::get_resource_by_name(const std::string &name) {
for (auto &res : resources_) {
if (res->Name() == name) {
return res;
}
}
return nullptr;
}
void void
ResourceMgr::event_process() { ResourceMgr::event_process() {
while (running_) { while (running_) {
......
...@@ -49,6 +49,9 @@ public: ...@@ -49,6 +49,9 @@ public:
ResourceWPtr ResourceWPtr
Add(ResourcePtr &&resource); Add(ResourcePtr &&resource);
void
Connect(const std::string &res1, const std::string &res2, Connection &connection);
/* /*
* Create connection between A and B; * Create connection between A and B;
*/ */
...@@ -80,6 +83,9 @@ public: ...@@ -80,6 +83,9 @@ public:
DumpTaskTables(); DumpTaskTables();
private: private:
ResourcePtr
get_resource_by_name(const std::string &name);
void void
event_process(); event_process();
......
...@@ -48,6 +48,7 @@ ToString(const TaskTimestamp &timestamp) { ...@@ -48,6 +48,7 @@ ToString(const TaskTimestamp &timestamp) {
ss << ", executed=" << timestamp.executed; ss << ", executed=" << timestamp.executed;
ss << ", move=" << timestamp.move; ss << ", move=" << timestamp.move;
ss << ", moved=" << timestamp.moved; ss << ", moved=" << timestamp.moved;
ss << ", finish=" << timestamp.finish;
ss << ">"; ss << ">";
return ss.str(); return ss.str();
} }
...@@ -92,6 +93,7 @@ TaskTableItem::Executed() { ...@@ -92,6 +93,7 @@ TaskTableItem::Executed() {
state = TaskTableItemState::EXECUTED; state = TaskTableItemState::EXECUTED;
lock.unlock(); lock.unlock();
timestamp.executed = get_now_timestamp(); timestamp.executed = get_now_timestamp();
timestamp.finish = get_now_timestamp();
return true; return true;
} }
return false; return false;
...@@ -114,6 +116,7 @@ TaskTableItem::Moved() { ...@@ -114,6 +116,7 @@ TaskTableItem::Moved() {
state = TaskTableItemState::MOVED; state = TaskTableItemState::MOVED;
lock.unlock(); lock.unlock();
timestamp.moved = get_now_timestamp(); timestamp.moved = get_now_timestamp();
timestamp.finish = get_now_timestamp();
return true; return true;
} }
return false; return false;
......
...@@ -36,6 +36,7 @@ struct TaskTimestamp { ...@@ -36,6 +36,7 @@ struct TaskTimestamp {
uint64_t loaded = 0; uint64_t loaded = 0;
uint64_t execute = 0; uint64_t execute = 0;
uint64_t executed = 0; uint64_t executed = 0;
uint64_t finish = 0;
}; };
struct TaskTableItem { struct TaskTableItem {
......
...@@ -20,7 +20,7 @@ next(std::list<ResourcePtr> &neighbours, std::list<ResourcePtr>::iterator &it) { ...@@ -20,7 +20,7 @@ next(std::list<ResourcePtr> &neighbours, std::list<ResourcePtr>::iterator &it) {
} }
} }
// TODO: this function called with only on tasks, so it will always push task to first neighbour
void void
push_task_round_robin(TaskTable &self_task_table, std::list<ResourcePtr> &neighbours) { push_task_round_robin(TaskTable &self_task_table, std::list<ResourcePtr> &neighbours) {
CacheMgr cache; CacheMgr cache;
...@@ -31,7 +31,7 @@ push_task_round_robin(TaskTable &self_task_table, std::list<ResourcePtr> &neighb ...@@ -31,7 +31,7 @@ push_task_round_robin(TaskTable &self_task_table, std::list<ResourcePtr> &neighb
for (auto index : indexes) { for (auto index : indexes) {
if (self_task_table.Move(index)) { if (self_task_table.Move(index)) {
auto task = self_task_table.Get(index)->task; auto task = self_task_table.Get(index)->task;
task = task->Clone(); // task = task->Clone();
(*it)->task_table().Put(task); (*it)->task_table().Put(task);
next(neighbours, it); next(neighbours, it);
} }
......
...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const CpuResource &resource) { ...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const CpuResource &resource) {
return out; return out;
} }
CpuResource::CpuResource(std::string name, bool enable_loader, bool enable_executor) CpuResource::CpuResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::CPU, enable_loader, enable_executor) {} : Resource(std::move(name), ResourceType::CPU, device_id, enable_loader, enable_executor) {}
void CpuResource::LoadFile(TaskPtr task) { void CpuResource::LoadFile(TaskPtr task) {
task->Load(LoadType::DISK2CPU, 0); task->Load(LoadType::DISK2CPU, 0);
......
...@@ -17,7 +17,7 @@ namespace engine { ...@@ -17,7 +17,7 @@ namespace engine {
class CpuResource : public Resource { class CpuResource : public Resource {
public: public:
explicit explicit
CpuResource(std::string name, bool enable_loader, bool enable_executor); CpuResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -15,8 +15,8 @@ std::ostream &operator<<(std::ostream &out, const DiskResource &resource) { ...@@ -15,8 +15,8 @@ std::ostream &operator<<(std::ostream &out, const DiskResource &resource) {
return out; return out;
} }
DiskResource::DiskResource(std::string name, bool enable_loader, bool enable_executor) DiskResource::DiskResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::DISK, enable_loader, enable_executor) { : Resource(std::move(name), ResourceType::DISK, device_id, enable_loader, enable_executor) {
} }
void DiskResource::LoadFile(TaskPtr task) { void DiskResource::LoadFile(TaskPtr task) {
......
...@@ -16,7 +16,7 @@ namespace engine { ...@@ -16,7 +16,7 @@ namespace engine {
class DiskResource : public Resource { class DiskResource : public Resource {
public: public:
explicit explicit
DiskResource(std::string name, bool enable_loader, bool enable_executor); DiskResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -16,11 +16,11 @@ std::ostream &operator<<(std::ostream &out, const GpuResource &resource) { ...@@ -16,11 +16,11 @@ std::ostream &operator<<(std::ostream &out, const GpuResource &resource) {
return out; return out;
} }
GpuResource::GpuResource(std::string name, bool enable_loader, bool enable_executor) GpuResource::GpuResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::GPU, enable_loader, enable_executor) {} : Resource(std::move(name), ResourceType::GPU, device_id, enable_loader, enable_executor) {}
void GpuResource::LoadFile(TaskPtr task) { void GpuResource::LoadFile(TaskPtr task) {
task->Load(LoadType::CPU2GPU, 0); task->Load(LoadType::CPU2GPU, device_id_);
} }
void GpuResource::Process(TaskPtr task) { void GpuResource::Process(TaskPtr task) {
......
...@@ -16,7 +16,7 @@ namespace engine { ...@@ -16,7 +16,7 @@ namespace engine {
class GpuResource : public Resource { class GpuResource : public Resource {
public: public:
explicit explicit
GpuResource(std::string name, bool enable_loader, bool enable_executor); GpuResource(std::string name, uint64_t device_id, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -18,10 +18,12 @@ std::ostream &operator<<(std::ostream &out, const Resource &resource) { ...@@ -18,10 +18,12 @@ std::ostream &operator<<(std::ostream &out, const Resource &resource) {
Resource::Resource(std::string name, Resource::Resource(std::string name,
ResourceType type, ResourceType type,
uint64_t device_id,
bool enable_loader, bool enable_loader,
bool enable_executor) bool enable_executor)
: name_(std::move(name)), : name_(std::move(name)),
type_(type), type_(type),
device_id_(device_id),
running_(false), running_(false),
enable_loader_(enable_loader), enable_loader_(enable_loader),
enable_executor_(enable_executor), enable_executor_(enable_executor),
......
...@@ -82,6 +82,11 @@ public: ...@@ -82,6 +82,11 @@ public:
subscriber_ = std::move(subscriber); subscriber_ = std::move(subscriber);
} }
inline std::string
Name() const {
return name_;
}
inline ResourceType inline ResourceType
Type() const { Type() const {
return type_; return type_;
...@@ -112,6 +117,7 @@ public: ...@@ -112,6 +117,7 @@ public:
protected: protected:
Resource(std::string name, Resource(std::string name,
ResourceType type, ResourceType type,
uint64_t device_id,
bool enable_loader, bool enable_loader,
bool enable_executor); bool enable_executor);
...@@ -163,6 +169,9 @@ private: ...@@ -163,6 +169,9 @@ private:
void void
executor_function(); executor_function();
protected:
uint64_t device_id_;
private: private:
std::string name_; std::string name_;
ResourceType type_; ResourceType type_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册