Skip to content

Commit

Permalink
[tag] v2.6.1, lower cpu cost.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Sep 17, 2024
1 parent da02a25 commit a14f68f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
32 changes: 17 additions & 15 deletions src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@
#ifndef CGRAPH_UTHREADPOOLCONFIG_H
#define CGRAPH_UTHREADPOOLCONFIG_H

#include <algorithm>

#include "UThreadObject.h"
#include "UThreadPoolDefine.h"

CGRAPH_NAMESPACE_BEGIN

struct UThreadPoolConfig : public CStruct {
/** 具体值含义,参考UThreadPoolDefine.h文件 */
int default_thread_size_ = CGRAPH_DEFAULT_THREAD_SIZE;
int secondary_thread_size_ = CGRAPH_SECONDARY_THREAD_SIZE;
int max_thread_size_ = CGRAPH_MAX_THREAD_SIZE;
int max_task_steal_range_ = CGRAPH_MAX_TASK_STEAL_RANGE;
int max_local_batch_size_ = CGRAPH_MAX_LOCAL_BATCH_SIZE;
int max_pool_batch_size_ = CGRAPH_MAX_POOL_BATCH_SIZE;
int max_steal_batch_size_ = CGRAPH_MAX_STEAL_BATCH_SIZE;
int primary_thread_busy_epoch_ = CGRAPH_PRIMARY_THREAD_BUSY_EPOCH;
CInt default_thread_size_ = CGRAPH_DEFAULT_THREAD_SIZE;
CInt secondary_thread_size_ = CGRAPH_SECONDARY_THREAD_SIZE;
CInt max_thread_size_ = CGRAPH_MAX_THREAD_SIZE;
CInt max_task_steal_range_ = CGRAPH_MAX_TASK_STEAL_RANGE;
CInt max_local_batch_size_ = CGRAPH_MAX_LOCAL_BATCH_SIZE;
CInt max_pool_batch_size_ = CGRAPH_MAX_POOL_BATCH_SIZE;
CInt max_steal_batch_size_ = CGRAPH_MAX_STEAL_BATCH_SIZE;
CInt primary_thread_busy_epoch_ = CGRAPH_PRIMARY_THREAD_BUSY_EPOCH;
CMSec primary_thread_empty_interval_ = CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL;
CSec secondary_thread_ttl_ = CGRAPH_SECONDARY_THREAD_TTL;
CSec monitor_span_ = CGRAPH_MONITOR_SPAN;
CMSec queue_emtpy_interval_ = CGRAPH_QUEUE_EMPTY_INTERVAL;
int primary_thread_policy_ = CGRAPH_PRIMARY_THREAD_POLICY;
int secondary_thread_policy_ = CGRAPH_SECONDARY_THREAD_POLICY;
int primary_thread_priority_ = CGRAPH_PRIMARY_THREAD_PRIORITY;
int secondary_thread_priority_ = CGRAPH_SECONDARY_THREAD_PRIORITY;
bool bind_cpu_enable_ = CGRAPH_BIND_CPU_ENABLE;
bool batch_task_enable_ = CGRAPH_BATCH_TASK_ENABLE;
bool monitor_enable_ = CGRAPH_MONITOR_ENABLE;
CInt primary_thread_policy_ = CGRAPH_PRIMARY_THREAD_POLICY;
CInt secondary_thread_policy_ = CGRAPH_SECONDARY_THREAD_POLICY;
CInt primary_thread_priority_ = CGRAPH_PRIMARY_THREAD_PRIORITY;
CInt secondary_thread_priority_ = CGRAPH_SECONDARY_THREAD_PRIORITY;
CBool bind_cpu_enable_ = CGRAPH_BIND_CPU_ENABLE;
CBool batch_task_enable_ = CGRAPH_BATCH_TASK_ENABLE;
CBool monitor_enable_ = CGRAPH_MONITOR_ENABLE;

CStatus check() const {
CGRAPH_FUNCTION_BEGIN
Expand Down
6 changes: 2 additions & 4 deletions src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#else
# include <mutex>
#endif
#include <memory>

#include "../UtilsDefine.h"

Expand All @@ -41,7 +40,6 @@ static const CUInt CGRAPH_DEFAULT_RINGBUFFER_SIZE = 64;
static const CIndex CGRAPH_MAIN_THREAD_ID = -1; // 启动线程id标识(非上述主线程)
static const CIndex CGRAPH_SECONDARY_THREAD_COMMON_ID = -2; // 辅助线程统一id标识


static const CInt CGRAPH_DEFAULT_TASK_STRATEGY = -1; // 默认线程调度策略
static const CInt CGRAPH_POOL_TASK_STRATEGY = -2; // 固定用pool中的队列的调度策略
static const CInt CGRAPH_LONG_TIME_TASK_STRATEGY = -101; // 长时间任务调度策略
Expand All @@ -57,8 +55,8 @@ static const CBool CGRAPH_BATCH_TASK_ENABLE = false;
static const CInt CGRAPH_MAX_LOCAL_BATCH_SIZE = 2; // 批量执行本地任务最大值
static const CInt CGRAPH_MAX_POOL_BATCH_SIZE = 2; // 批量执行通用任务最大值
static const CInt CGRAPH_MAX_STEAL_BATCH_SIZE = 2; // 批量盗取任务最大值
static const CInt CGRAPH_PRIMARY_THREAD_BUSY_EPOCH = 10; // 主线程进入wait状态的轮数,数值越大,理论性能越高,但空转可能性也越大
static const CMSec CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL = 10; // 主线程进入休眠状态的默认时间
static const CInt CGRAPH_PRIMARY_THREAD_BUSY_EPOCH = 5; // 主线程进入wait状态的轮数,数值越大,理论性能越高,但空转可能性也越大
static const CMSec CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL = 1000; // 主线程进入休眠状态的默认时间
static const CSec CGRAPH_SECONDARY_THREAD_TTL = 10; // 辅助线程ttl,单位为s
static const CBool CGRAPH_MONITOR_ENABLE = false; // 是否开启监控程序
static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
Expand Down
2 changes: 1 addition & 1 deletion test/Functional/test-functional-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_functional_04() {
status += pipeline->process(runTimes);
}

status += CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 25)
status += CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 1500)
if (mp->num_ != halfArrSize * runTimes * 2) {
CGRAPH_ECHO("result num is wrong, num is [%lu]", mp->num_);
}
Expand Down
1 change: 1 addition & 0 deletions test/Performance/test-performance-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void test_performance_04() {
config.max_thread_size_ = nodePerLayer;
config.max_task_steal_range_ = nodePerLayer - 1;
config.primary_thread_busy_epoch_ = 500;
config.primary_thread_empty_interval_ = 0;
pipeline->setUniqueThreadPoolConfig(config);

// 实现一个全连接
Expand Down

0 comments on commit a14f68f

Please sign in to comment.