This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
     new bf98ed4195 [enhancement](compaction) set base compaction idle schedule 
(#16462)
bf98ed4195 is described below

commit bf98ed419576ca351e509550e8390d7b425ab23d
Author: yixiutt <[email protected]>
AuthorDate: Wed Feb 8 11:36:45 2023 +0800

    [enhancement](compaction) set base compaction idle schedule (#16462)
---
 be/src/common/config.h          |  1 +
 be/src/olap/base_compaction.cpp |  3 +++
 be/src/util/thread.cpp          | 17 +++++++++++++++++
 be/src/util/thread.h            |  2 ++
 4 files changed, 23 insertions(+)

diff --git a/be/src/common/config.h b/be/src/common/config.h
index 190f553d1b..ba117fe1af 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -232,6 +232,7 @@ CONF_mInt64(base_compaction_num_cumulative_deltas, "5");
 CONF_mDouble(base_cumulative_delta_ratio, "0.3");
 CONF_mInt64(base_compaction_interval_seconds_since_last_operation, "86400");
 CONF_mInt32(base_compaction_write_mbytes_per_sec, "5");
+CONF_Bool(enable_base_compaction_idle_sched, "true");
 
 // config the cumulative compaction policy
 // Valid configs: num_based, size_based
diff --git a/be/src/olap/base_compaction.cpp b/be/src/olap/base_compaction.cpp
index 37125cde52..b6cdbe4cb4 100644
--- a/be/src/olap/base_compaction.cpp
+++ b/be/src/olap/base_compaction.cpp
@@ -51,6 +51,9 @@ OLAPStatus BaseCompaction::prepare_compact() {
 }
 
 OLAPStatus BaseCompaction::execute_compact_impl() {
+    if (config::enable_base_compaction_idle_sched) {
+        Thread::set_idle_sched();
+    }
     MutexLock lock(_tablet->get_base_lock(), TRY_LOCK);
     if (!lock.own_lock()) {
         LOG(WARNING) << "another base compaction is running. tablet=" << 
_tablet->full_name();
diff --git a/be/src/util/thread.cpp b/be/src/util/thread.cpp
index a8d79fc6a5..44f93da87f 100644
--- a/be/src/util/thread.cpp
+++ b/be/src/util/thread.cpp
@@ -71,6 +71,8 @@ public:
 
     static void set_thread_name(const std::string& name, int64_t tid);
 
+    static void set_idle_sched(int64_t tid);
+
     // not the system TID, since pthread_t is less prone to being recycled.
     void add_thread(const pthread_t& pthread_id, const std::string& name,
                     const std::string& category, int64_t tid);
@@ -135,6 +137,17 @@ void ThreadMgr::set_thread_name(const std::string& name, 
int64_t tid) {
     }
 }
 
+void ThreadMgr::set_idle_sched(int64_t tid) {
+    if (tid == getpid()) {
+        return;
+    }
+    struct sched_param sp = {.sched_priority = 0};
+    int err = sched_setscheduler(0, SCHED_IDLE, &sp);
+    if (err < 0 && errno != EPERM) {
+        LOG(ERROR) << "set_thread_idle_sched";
+    }
+}
+
 void ThreadMgr::add_thread(const pthread_t& pthread_id, const std::string& 
name,
                            const std::string& category, int64_t tid) {
     // These annotations cause TSAN to ignore the synchronization on lock_
@@ -260,6 +273,10 @@ void Thread::set_self_name(const std::string& name) {
     ThreadMgr::set_thread_name(name, current_thread_id());
 }
 
+void Thread::set_idle_sched() {
+    ThreadMgr::set_idle_sched(current_thread_id());
+}
+
 void Thread::join() {
     ThreadJoiner(this).join();
 }
diff --git a/be/src/util/thread.h b/be/src/util/thread.h
index f3f76d12d9..b79878c4a2 100644
--- a/be/src/util/thread.h
+++ b/be/src/util/thread.h
@@ -87,6 +87,8 @@ public:
 
     static void set_self_name(const std::string& name);
 
+    static void set_idle_sched();
+
     ~Thread();
 
     // Blocks until this thread finishes execution. Once this method returns, 
the thread


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to