You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/07/18 15:35:35 UTC

[GitHub] [incubator-doris] acelyc111 commented on a change in pull request #5781: [Compaction][ThreadPool]Support adjust compaction threads num at runtime

acelyc111 commented on a change in pull request #5781:
URL: https://github.com/apache/incubator-doris/pull/5781#discussion_r671859106



##########
File path: be/test/util/threadpool_test.cpp
##########
@@ -778,6 +778,85 @@ TEST_F(ThreadPoolTest, TestLIFOThreadWakeUps) {
 }
 */
 
+TEST_F(ThreadPoolTest, TestThreadPoolDynamicAdjustMaximumMinimum) {
+ASSERT_TRUE(rebuild_pool_with_builder(ThreadPoolBuilder(kDefaultPoolName)

Review comment:
       indent

##########
File path: be/src/util/threadpool.cpp
##########
@@ -610,6 +607,47 @@ void ThreadPool::check_not_pool_thread_unlocked() {
     }
 }
 
+Status ThreadPool::set_min_threads(int min_threads) {
+    if (min_threads <= _max_threads) {
+        _min_threads = min_threads;
+        if (min_threads > _num_threads + _num_threads_pending_start) {
+            int addition_threads = min_threads - _num_threads - _num_threads_pending_start;
+            _num_threads_pending_start += addition_threads;
+            for (int i = 0; i < addition_threads; i++) {
+                Status status = create_thread();
+                if (!status.ok()) {
+                    _num_threads_pending_start--;
+                    LOG(WARNING) << "Thread pool failed to create thread: " << status.to_string();
+                    return status;
+                }
+            }
+        }
+        return Status::OK();
+    }
+    return Status::InternalError("set thread pool min_threads failed");

Review comment:
       Better to clarify why it failed.

##########
File path: be/src/util/threadpool.cpp
##########
@@ -610,6 +607,47 @@ void ThreadPool::check_not_pool_thread_unlocked() {
     }
 }
 
+Status ThreadPool::set_min_threads(int min_threads) {
+    if (min_threads <= _max_threads) {
+        _min_threads = min_threads;

Review comment:
       Even though `_min_threads` is type of `AtomicInt32`, this function is not thread safe.

##########
File path: be/src/util/threadpool.cpp
##########
@@ -610,6 +607,47 @@ void ThreadPool::check_not_pool_thread_unlocked() {
     }
 }
 
+Status ThreadPool::set_min_threads(int min_threads) {
+    if (min_threads <= _max_threads) {
+        _min_threads = min_threads;
+        if (min_threads > _num_threads + _num_threads_pending_start) {
+            int addition_threads = min_threads - _num_threads - _num_threads_pending_start;
+            _num_threads_pending_start += addition_threads;
+            for (int i = 0; i < addition_threads; i++) {
+                Status status = create_thread();
+                if (!status.ok()) {
+                    _num_threads_pending_start--;
+                    LOG(WARNING) << "Thread pool failed to create thread: " << status.to_string();
+                    return status;
+                }
+            }
+        }
+        return Status::OK();
+    }
+    return Status::InternalError("set thread pool min_threads failed");
+}
+
+Status ThreadPool::set_max_threads(int max_threads) {
+    if (_min_threads <= max_threads) {

Review comment:
       Maybe Use short circuit return would make you code more elegant




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org