From a14f68f1bb4601c9fa88bbf16db099a3aa3596ca Mon Sep 17 00:00:00 2001 From: ChunelFeng Date: Tue, 17 Sep 2024 21:01:13 +0800 Subject: [PATCH] [tag] v2.6.1, lower cpu cost. --- src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h | 32 +++++++++++--------- src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h | 6 ++-- test/Functional/test-functional-04.cpp | 2 +- test/Performance/test-performance-04.cpp | 1 + 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h b/src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h index 1c2f6bb8..92256d46 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h +++ b/src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h @@ -9,6 +9,8 @@ #ifndef CGRAPH_UTHREADPOOLCONFIG_H #define CGRAPH_UTHREADPOOLCONFIG_H +#include + #include "UThreadObject.h" #include "UThreadPoolDefine.h" @@ -16,25 +18,25 @@ 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 diff --git a/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h b/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h index aa677ef9..0c9e9376 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h +++ b/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h @@ -15,7 +15,6 @@ #else # include #endif -#include #include "../UtilsDefine.h" @@ -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; // 长时间任务调度策略 @@ -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 diff --git a/test/Functional/test-functional-04.cpp b/test/Functional/test-functional-04.cpp index 515629ea..fcb35692 100644 --- a/test/Functional/test-functional-04.cpp +++ b/test/Functional/test-functional-04.cpp @@ -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_); } diff --git a/test/Performance/test-performance-04.cpp b/test/Performance/test-performance-04.cpp index 1f08846a..049e93aa 100644 --- a/test/Performance/test-performance-04.cpp +++ b/test/Performance/test-performance-04.cpp @@ -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); // 实现一个全连接