Skip to content

Commit

Permalink
[perf] simply some code, simple change parallel strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Mar 22, 2024
1 parent 9c0fd05 commit afc5c1c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
17 changes: 1 addition & 16 deletions src/GraphCtrl/GraphDaemon/GDaemonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,7 @@ CStatus GDaemonManager::clear() {


CSize GDaemonManager::getSize() const {
CSize size = daemons_.size();
return size;
}


GDaemonManagerPtr GDaemonManager::setInterval(CMSec interval) {
if (0 == interval) {
return this;
}

for (auto daemon : daemons_) {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(daemon)
daemon->setInterval(interval);
}

return this;
return daemons_.size();
}

CGRAPH_NAMESPACE_END
4 changes: 1 addition & 3 deletions src/GraphCtrl/GraphDaemon/GDaemonManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class GDaemonManager : public GDaemonObject,

~GDaemonManager() override;

GDaemonManager* setInterval(CMSec interval) override;

CStatus init() final;

CStatus destroy() final;
Expand All @@ -40,7 +38,7 @@ class GDaemonManager : public GDaemonObject,
CGRAPH_NO_ALLOWED_COPY(GDaemonManager)

private:
GDaemonSet daemons_; // daemon信息集合
GDaemonSet daemons_ {}; // daemon信息集合
};

using GDaemonManagerPtr = GDaemonManager *;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ CVoid GDynamicEngine::mark(const GSortedGElementPtrSet& elements) {


CVoid GDynamicEngine::analysisDagType(const GSortedGElementPtrSet& elements) {
if (total_element_arr_.empty() || front_element_arr_.size() == 1 && total_element_arr_.size() - 1 == linked_size_) {
if (total_element_arr_.empty()
|| (front_element_arr_.size() == 1 && total_element_arr_.size() - 1 == linked_size_)) {
/**
* 如果所有的信息中,只有一个是非linkable。则说明只有开头的那个是的,且只有一个开头
* 故,这里将其认定为一条 lineal 的情况
Expand Down Expand Up @@ -213,15 +214,13 @@ CVoid GDynamicEngine::parallelRunAll() {
* 非纯并行逻辑,不走此函数
*/
std::vector<std::future<CStatus>> futures;
futures.reserve(total_end_size_ - 1);
for (int i = 1; i < total_end_size_; i++) {
futures.reserve(total_end_size_);
for (int i = 0; i < total_end_size_; i++) {
futures.emplace_back(std::move(thread_pool_->commit([this, i] {
return total_element_arr_[i]->fatProcessor(CFunctionType::RUN);
}, calcIndex(total_element_arr_[i]))));
}

// 将 1~n 的数据,放入线程池。第0个,本地直接执行即可,类似亲和性处理
cur_status_ += (*front_element_arr_.begin())->fatProcessor(CFunctionType::RUN);
for (auto& fut : futures) {
cur_status_ += fut.get();
}
Expand Down
12 changes: 4 additions & 8 deletions src/GraphCtrl/GraphEvent/GEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,18 @@ CVoid GEvent::asyncWait(GEventAsyncStrategy strategy) {
switch (strategy) {
case GEventAsyncStrategy::PIPELINE_RUN_FINISH: {
for (auto& cur : async_run_finish_futures_) {
if (cur.valid()) {
cur.wait();
}
cur.valid() ? cur.wait() : void();
}
async_run_finish_futures_.clear();
}
break;
}
case GEventAsyncStrategy::PIPELINE_DESTROY: {
for (auto& cur : async_destroy_futures_) {
if (cur.valid()) {
cur.wait();
}
cur.valid() ? cur.wait() : void();
}
async_destroy_futures_.clear();
}
break;
}
default:
CGRAPH_THROW_EXCEPTION("unknown event async strategy type")
}
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Task/UTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

CGRAPH_NAMESPACE_BEGIN

class UTask : public UThreadObject {
class UTask : public CStruct {
struct TaskBased {
explicit TaskBased() = default;
virtual CVoid call() = 0;
Expand Down

0 comments on commit afc5c1c

Please sign in to comment.