Skip to content

Commit f62bcff

Browse files
committed
[perf] change schedule stragety, pipeline bind with unique thread pool.
1 parent a2fb102 commit f62bcff

File tree

22 files changed

+120
-129
lines changed

22 files changed

+120
-129
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ message("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
1010

1111
cmake_minimum_required(VERSION 3.5.0)
1212

13-
project(CGraph VERSION 2.3.1)
13+
project(CGraph VERSION 2.3.2)
1414

1515
# CGraph默认使用C++11版本,推荐使用C++17版本。暂不支持C++11以下版本
1616
set(CMAKE_CXX_STANDARD 11)

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
$ make -j8
5252
```
5353

54-
<div style="text-align: center;">
55-
56-
![CGraph Gamecock](https://github.com/ChunelFeng/CGraph/blob/main/doc/image/CGraph%20Gamecock.jpg)
57-
58-
</div>
59-
6054
* 若本地无法编译,提供基于`Ubuntu 20.04`的Docker镜像。输入以下指令,即可获取并进入
6155
```shell
6256
$ docker pull chunelfeng/cenv # 获取docker镜像
@@ -283,6 +277,9 @@ int main() {
283277

284278
[2023.01.25 - v2.3.1 - Chunel]
285279
* 提供针对C++11版本的支持。感谢 [MirrorYuChen](https://github.com/MirrorYuChen) 提供相关解决方案
280+
281+
[2023.02.10 - v2.3.2 - Chunel]
282+
* 优化调度策略,提供调度参数配置接口
286283
* 提供英文版本readme.md
287284

288285
</details>

README_en.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ At the same time, you can also control the graph conditional judgment, loop or c
2424

2525
You can transfer your params in many scenes. It is also possible to extend the functions of the above elements horizontally by adding `GAspect`, or to enhance the functions of individual nodes by introducing various `GAdapter`.
2626

27+
![CGraph Skeleton](https://github.com/ChunelFeng/CGraph/blob/main/doc/image/CGraph%20Skeleton.jpg)
28+
<br>
2729

2830
## 2. Compile
2931
* This project supports MacOS, Linux, and Windows systems without any third-party dependencies. C++11 is default and lowest version, C++17 is recommended.

doc/image/CGraph Gamecock.jpg

-321 KB
Binary file not shown.

src/GraphCtrl/GraphElement/GElement.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const std::string& GElement::getSession() const {
2222

2323
GElement::GElement() {
2424
this->session_ = CGRAPH_GENERATE_SESSION;
25-
this->thread_pool_ = UThreadPoolSingleton::get();
2625
}
2726

2827

@@ -236,4 +235,12 @@ CStatus GElement::notify(const std::string& key, CSize times) {
236235
CGRAPH_FUNCTION_END
237236
}
238237

238+
239+
GElement* GElement::setThreadPool(UThreadPoolPtr ptr) {
240+
CGRAPH_ASSERT_NOT_NULL_RETURN_NULL(ptr)
241+
CGRAPH_ASSERT_INIT_RETURN_NULL(false)
242+
this->thread_pool_ = ptr;
243+
return this;
244+
}
245+
239246
CGRAPH_NAMESPACE_END

src/GraphCtrl/GraphElement/GElement.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ class GElement : public GElementObject {
211211
*/
212212
CStatus notify(const std::string& key, CSize times = 1);
213213

214+
/**
215+
* 设置线程池信息
216+
* @param ptr
217+
* @return
218+
*/
219+
GElement* setThreadPool(UThreadPoolPtr ptr);
220+
214221
CGRAPH_NO_ALLOWED_COPY(GElement);
215222

216223
CGRAPH_DECLARE_GPARAM_MANAGER_WRAPPER

src/GraphCtrl/GraphElement/GElementManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ CStatus GElementManager::initEngine() {
135135
}
136136
CGRAPH_FUNCTION_CHECK_STATUS
137137

138+
engine_->setThreadPool(thread_pool_);
138139
status = engine_->setUp(manager_elements_);
139140
CGRAPH_FUNCTION_END
140141
}

src/GraphCtrl/GraphElement/GElementManager.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,22 @@ class GElementManager : public GElementObject, public GraphManager<GElement> {
7373
*/
7474
CStatus initEngine();
7575

76+
/**
77+
* 设置线程池
78+
* @param ptr
79+
* @return
80+
*/
81+
GElementManager* setThreadPool(UThreadPoolPtr ptr) {
82+
CGRAPH_ASSERT_NOT_NULL_RETURN_NULL(ptr)
83+
this->thread_pool_ = ptr;
84+
return this;
85+
}
86+
7687
private:
7788
GSortedGElementPtrSet manager_elements_; // 保存节点信息的内容
7889
GEnginePtr engine_ = nullptr; // 执行引擎
7990
GEngineType engine_type_ = GEngineType::STATIC; // 引擎执行方式
91+
UThreadPoolPtr thread_pool_ = nullptr; // 线程池
8092

8193
friend class GPipeline;
8294
friend class GRegion;

src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CStatus GRegion::init() {
3030
CGRAPH_ASSERT_NOT_NULL(manager_)
3131

3232
// 在region中,需要专门的调度逻辑
33+
this->manager_->setThreadPool(thread_pool_);
3334
this->manager_->setScheduleStrategy(CGRAPH_REGION_TASK_STRATEGY);
3435
status = this->manager_->init();
3536
CGRAPH_FUNCTION_CHECK_STATUS

src/GraphCtrl/GraphElement/GNode/GNode.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ class GNode : public GElement {
3535
*/
3636
GNode* setType(const GNodeType& type);
3737

38-
/**
39-
* 异步执行信息,适用于传入静态类函数或者lambda表达式信息
40-
* @tparam Func
41-
* @tparam Args
42-
* @param func
43-
* @param args
44-
*/
45-
template<typename Func, typename... Args>
46-
static CStatus doDetach(const Func&& func, Args&&... args);
47-
4838
private:
4939
GNodeType node_type_; // 节点类型
5040
};
@@ -54,6 +44,4 @@ using GNodePtrArr = std::vector<GNodePtr>;
5444

5545
CGRAPH_NAMESPACE_END
5646

57-
#include "GNode.inl"
58-
5947
#endif //CGRAPH_GNODE_H

0 commit comments

Comments
 (0)