Skip to content

Commit

Permalink
[perf] optimize schedule strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Jun 3, 2023
1 parent 50317ed commit dc2f9cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/GraphCtrl/GraphEvent/GEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ CStatus GEvent::process(GEventType type) {
break;
case GEventType::ASYNC: // 异步触发
CGRAPH_ASSERT_NOT_NULL(this->thread_pool_)
thread_pool_->commit([this] {
thread_pool_->commitWithPriority([this] {
this->trigger(this->param_);
}, CGRAPH_EVENT_TASK_STRATEGY);
}, CGRAPH_DEFAULT_PRIORITY);
break;
default:
CGRAPH_RETURN_ERROR_STATUS("unknown event type")
Expand Down
2 changes: 1 addition & 1 deletion src/GraphCtrl/GraphPipeline/GPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ std::future<CStatus> GPipeline::asyncRun() {

return tp->commitWithPriority([this] {
return run();
}, 0);
}, CGRAPH_DEFAULT_PRIORITY);
}


Expand Down
2 changes: 1 addition & 1 deletion src/GraphCtrl/GraphPipeline/GPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class GPipeline : public GPipelineObject,
* @param runTimes
* @return
*/
std::future<CStatus> asyncProcess(CSize runTimes);
std::future<CStatus> asyncProcess(CSize runTimes = CGRAPH_DEFAULT_LOOP_TIMES);

/**
* 停止执行流程,多用于异步执行流程中
Expand Down
4 changes: 4 additions & 0 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ CStatus UThreadPool::createSecondaryThread(CInt size) {

int leftSize = (int)(config_.max_thread_size_ - config_.default_thread_size_ - secondary_threads_.size());
int realSize = std::min(size, leftSize); // 使用 realSize 来确保所有的线程数量之和,不会超过设定max值
if (realSize <= 0) {
CGRAPH_RETURN_ERROR_STATUS("cannot create more thread")
}

for (int i = 0; i < realSize; i++) {
auto ptr = CGRAPH_MAKE_UNIQUE_COBJECT(UThreadSecondary)
ptr->setThreadPoolInfo(&task_queue_, &priority_task_queue_, &config_);
Expand Down
5 changes: 2 additions & 3 deletions src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ static const int CGRAPH_THREAD_MAX_PRIORITY = 99;
static const CMSec CGRAPH_MAX_BLOCK_TTL = 3999999999; // 最大阻塞时间,单位为ms
static const CUint CGRAPH_DEFAULT_RINGBUFFER_SIZE = 1024; // 默认环形队列的大小
static const CIndex CGRAPH_SECONDARY_THREAD_COMMON_ID = -1; // 辅助线程统一id标识
static const CInt CGRAPH_DEFAULT_PRIORITY = 0; // 默认优先级

static const int CGRAPH_DEFAULT_TASK_STRATEGY = -1; // 默认线程调度策略
static const int CGRAPH_LONG_TIME_TASK_STRATEGY = -101; // 长时间任务调度策略
static const int CGRAPH_REGION_TASK_STRATEGY = -102; // region的调度策略
static const int CGRAPH_EVENT_TASK_STRATEGY = -103; // event的调度策略
static const int CGRAPH_PIPELINE_TASK_STRATEGY = -104; // pipeline的调度策略

/**
* 以下为线程池配置信息
Expand All @@ -71,7 +70,7 @@ static const int CGRAPH_MAX_STEAL_BATCH_SIZE = 2;
static const int CGRAPH_SECONDARY_THREAD_TTL = 10; // 辅助线程ttl,单位为s
static const bool CGRAPH_MONITOR_ENABLE = false; // 是否开启监控程序(如果不开启,辅助线程策略将失效)
static const int CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
static const bool CGRAPH_BIND_CPU_ENABLE = true; // 是否开启绑定cpu模式(仅针对主线程)
static const bool CGRAPH_BIND_CPU_ENABLE = false; // 是否开启绑定cpu模式(仅针对主线程)
static const int CGRAPH_PRIMARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 主线程调度策略
static const int CGRAPH_SECONDARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 辅助线程调度策略
static const int CGRAPH_PRIMARY_THREAD_PRIORITY = CGRAPH_THREAD_MIN_PRIORITY; // 主线程调度优先级(取值范围0~99)
Expand Down

0 comments on commit dc2f9cd

Please sign in to comment.