You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/06/09 18:12:57 UTC

(kudu) branch branch-1.18.x updated: [util] Remove SchedulerThread code and tests

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

alexey pushed a commit to branch branch-1.18.x
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/branch-1.18.x by this push:
     new 87580082f [util] Remove SchedulerThread code and tests
87580082f is described below

commit 87580082ff5f248576fe20d8fcea08d825d00a99
Author: kedeng <kd...@gmail.com>
AuthorDate: Fri Jun 6 10:53:11 2025 +0800

    [util] Remove SchedulerThread code and tests
    
    This removes the SchedulerThread implementation and its associated tests.
    The TestSubmitAfterShutdown case has proven unstable in ARM+TSAN
    environments. The code was originally introduced in KUDU-3364 but has
    never been used outside of tests, and the original author appears to
    have no plans to maintain it.
    
    Removing this unused code simplifies the codebase and improves test
    stability. The removal was suggested by Alexey.
    
    Change-Id: I544488158db84dca580694e884b56d5c546d89c1
    Reviewed-on: http://gerrit.cloudera.org:8080/22987
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Alexey Serbin <al...@apache.org>
    (cherry picked from commit 7a3868519f1eed9617ee0e4c1a20154b55f85063)
      Conflicts:
        src/kudu/util/threadpool.h
    Reviewed-on: http://gerrit.cloudera.org:8080/22996
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
---
 src/kudu/util/threadpool-test.cc | 166 ---------------------------------------
 src/kudu/util/threadpool.cc      | 110 +-------------------------
 src/kudu/util/threadpool.h       | 123 -----------------------------
 3 files changed, 3 insertions(+), 396 deletions(-)

diff --git a/src/kudu/util/threadpool-test.cc b/src/kudu/util/threadpool-test.cc
index 35708ee0c..d288d2f1e 100644
--- a/src/kudu/util/threadpool-test.cc
+++ b/src/kudu/util/threadpool-test.cc
@@ -90,15 +90,6 @@ class ThreadPoolTest : public KuduTest {
         .Build(&pool_);
   }
 
-  Status RebuildPoolWithScheduler(int min_threads, int max_threads, int period_ms = 100) {
-    return ThreadPoolBuilder(kDefaultPoolName)
-        .set_min_threads(min_threads)
-        .set_max_threads(max_threads)
-        .set_enable_scheduler()
-        .set_schedule_period_ms(period_ms)
-        .Build(&pool_);
-  }
-
  protected:
   unique_ptr<ThreadPool> pool_;
 };
@@ -106,8 +97,6 @@ class ThreadPoolTest : public KuduTest {
 TEST_F(ThreadPoolTest, TestNoTaskOpenClose) {
   ASSERT_OK(RebuildPoolWithMinMax(4, 4));
   pool_->Shutdown();
-  ASSERT_OK(RebuildPoolWithScheduler(4, 4));
-  pool_->Shutdown();
 }
 
 static void SimpleTaskMethod(int n, Atomic32* counter) {
@@ -133,8 +122,6 @@ class SimpleTask {
 };
 
 TEST_F(ThreadPoolTest, TestSimpleTasks) {
-  constexpr int kDelayMs = 500;
-
   ASSERT_OK(RebuildPoolWithMinMax(4, 4));
 
   Atomic32 counter(0);
@@ -147,19 +134,6 @@ TEST_F(ThreadPoolTest, TestSimpleTasks) {
   ASSERT_OK(pool_->Submit([&counter]() { SimpleTaskMethod(123, &counter); }));
   pool_->Wait();
   ASSERT_EQ(10 + 15 + 20 + 15 + 123, base::subtle::NoBarrier_Load(&counter));
-
-  ASSERT_OK(RebuildPoolWithScheduler(4, 4));
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  ASSERT_OK(token->Schedule([&counter]() {
-    SimpleTaskMethod(13, &counter);
-  }, kDelayMs));
-
-  // make sure the tasks scheduled and executed in SchedulerThread.
-  SleepFor(MonoDelta::FromMilliseconds(2 * kDelayMs));
-  // make sure all tasks executed in thread pool.
-  pool_->Wait();
-  // check the results.
-  ASSERT_EQ(10 + 15 + 20 + 15 + 123 + 13, base::subtle::NoBarrier_Load(&counter));
 }
 
 static void IssueTraceStatement() {
@@ -180,106 +154,12 @@ TEST_F(ThreadPoolTest, TestTracePropagation) {
   ASSERT_STR_CONTAINS(t->DumpToString(), "hello from task");
 }
 
-static void ContinuousIssueTraceStatement(ThreadPoolToken* token) {
-  Random r(SeedRandom());
-  // delay_ms is a random time: 1ms or 2ms or 3ms.
-  int delay_ms = 1 + static_cast<int>(r.Uniform(3));
-  Status status = token->Schedule(std::bind(&ContinuousIssueTraceStatement, token), delay_ms);
-  // At the case, 'pool_->Shutdown();' would shutdown its SchedulerThread firstly, after that
-  // 'token->Scheduler(...)' would return a IllegalState.
-  LOG_IF(WARNING, !status.ok()) << "ContinuousIssueTraceStatement: " << status.ToString();
-  ASSERT_TRUE(status.ok() || status.IsIllegalState());
-}
-
-TEST_F(ThreadPoolTest, TestExtremeScheduler) {
-  // The case is for the scenario:
-  //   1. There are many tasks in SchedulerThread need to be scheduled.
-  //   2. Every periodic schedule of SchedulerThread, many tasks can be scheduled.
-  //   3. At 1, 2 conditions, SchedulerThread's shutdown happened
-  //      and program should work well(no threads data race and core dump).
-  ASSERT_OK(RebuildPoolWithScheduler(1, 1, 1));
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  for (int i = 0; i < 2048; i++) {
-    ContinuousIssueTraceStatement(token.get());
-  }
-  SleepFor(MonoDelta::FromMilliseconds(5));
-  pool_->Shutdown();
-}
-
 TEST_F(ThreadPoolTest, TestSubmitAfterShutdown) {
   ASSERT_OK(RebuildPoolWithMinMax(1, 1));
   pool_->Shutdown();
   Status s = pool_->Submit(&IssueTraceStatement);
   ASSERT_EQ("Service unavailable: The pool has been shut down.",
             s.ToString());
-
-  ASSERT_OK(RebuildPoolWithScheduler(1, 1));
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  Atomic32 counter(0);
-  constexpr const int delay_ms = 100;
-  ASSERT_OK(token->Schedule([&counter]() { SimpleTaskMethod(10, &counter); }, delay_ms));
-  SleepFor(MonoDelta::FromMilliseconds(2 * delay_ms));
-  ASSERT_EQ(10, base::subtle::NoBarrier_Load(&counter));
-  token->Shutdown();
-  ASSERT_OK(token->Schedule([&counter]() { SimpleTaskMethod(3, &counter); }, delay_ms));
-  SleepFor(MonoDelta::FromMilliseconds(2 * delay_ms));
-  // The result does not change.
-  ASSERT_EQ(10, base::subtle::NoBarrier_Load(&counter));
-  pool_->Shutdown();
-  // Submit a delayed task, but it will not really executed.
-  ASSERT_TRUE(
-      token->Schedule([&counter]() { SimpleTaskMethod(5, &counter); }, delay_ms).IsIllegalState());
-  // The result does not change.
-  ASSERT_EQ(10, base::subtle::NoBarrier_Load(&counter));
-}
-
-TEST_F(ThreadPoolTest, TokenShutdownBeforeSchedulerExecute) {
-  ASSERT_OK(RebuildPoolWithScheduler(1, 1));
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  Atomic32 counter(0);
-  constexpr const int delay_ms = 200;
-  ASSERT_OK(token->Schedule([&counter]() { SimpleTaskMethod(10, &counter); }, delay_ms));
-  token->Shutdown();
-  ASSERT_EQ(0, base::subtle::NoBarrier_Load(&counter));
-  SleepFor(MonoDelta::FromMilliseconds(2 * delay_ms));
-  ASSERT_OK(token->Schedule([&counter]() { SimpleTaskMethod(3, &counter); }, delay_ms));
-  SleepFor(MonoDelta::FromMilliseconds(2 * delay_ms));
-  ASSERT_EQ(0, base::subtle::NoBarrier_Load(&counter));
-  pool_->Shutdown();
-  ASSERT_TRUE(
-      token->Schedule([&counter]() { SimpleTaskMethod(3, &counter); }, delay_ms).IsIllegalState());
-  SleepFor(MonoDelta::FromMilliseconds(2 * delay_ms));
-  ASSERT_EQ(0, base::subtle::NoBarrier_Load(&counter));
-}
-
-TEST_F(ThreadPoolTest, SchedulerShutdownBeforeTokenShutdown) {
-  ASSERT_OK(RebuildPoolWithScheduler(1, 1));
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  ASSERT_OK(token->Schedule(&IssueTraceStatement, 200));
-  SleepFor(MonoDelta::FromMilliseconds(500));
-  pool_->Shutdown();
-  Status status = token->Schedule(&IssueTraceStatement, 200);
-  ASSERT_TRUE(status.IsIllegalState() || status.IsServiceUnavailable());
-  token->Shutdown();
-}
-
-TEST_F(ThreadPoolTest, SchedulerWithNullToken) {
-  ASSERT_OK(RebuildPoolWithScheduler(1, 1));
-  ASSERT_OK(pool_->Schedule(nullptr, &IssueTraceStatement, MonoTime::Now()));
-
-  Atomic32 counter(0);
-  SimpleTask task(2, &counter);
-
-  ASSERT_OK(pool_->Submit([&counter]() { SimpleTaskMethod(1, &counter); }));
-  ASSERT_OK(pool_->Submit([&task]() { task.Run(); }));
-  // token is null is ok, but the task will ignore.
-  ASSERT_OK(pool_->Schedule(
-      nullptr, [&counter]() { SimpleTaskMethod(3, &counter); }, MonoTime::Now()));
-  // make sure the delayed task execute, the task would be ignored.
-  SleepFor(MonoDelta::FromMilliseconds(200));
-  // make sure all tasks executed in thread pool.
-  pool_->Wait();
-  ASSERT_EQ(1 + 2, base::subtle::NoBarrier_Load(&counter));
 }
 
 TEST_F(ThreadPoolTest, TestThreadPoolWithNoMinimum) {
@@ -316,52 +196,6 @@ TEST_F(ThreadPoolTest, TestThreadPoolWithNoMinimum) {
   ASSERT_EQ(0, pool_->num_threads());
 }
 
-TEST_F(ThreadPoolTest, TestThreadPoolWithSchedulerAndNoMinimum) {
-  constexpr int kIdleTimeoutMs = 1;
-  constexpr int kDelayMs = 1000;
-  ASSERT_OK(RebuildPoolWithBuilder(
-      ThreadPoolBuilder(kDefaultPoolName)
-      .set_min_threads(0)
-      .set_max_threads(4)
-      .set_enable_scheduler()
-      .set_idle_timeout(MonoDelta::FromMilliseconds(kIdleTimeoutMs))));
-  // There are no threads to start with.
-  ASSERT_EQ(0, pool_->active_threads_);
-  ASSERT_EQ(0, pool_->num_threads());
-
-  CountDownLatch latch(1);
-  SCOPED_CLEANUP({
-      latch.CountDown();
-  });
-  ASSERT_OK(pool_->Submit([&latch]() { latch.Wait(); }));
-  ASSERT_OK(pool_->Submit([&latch]() { latch.Wait(); }));
-  ASSERT_OK(pool_->Submit([&latch]() { latch.Wait(); }));
-  ASSERT_OK(pool_->Submit([&latch]() { latch.Wait(); }));
-  ASSERT_EQ(4, pool_->num_threads());
-  unique_ptr<ThreadPoolToken> token = pool_->NewToken(ThreadPool::ExecutionMode::SERIAL);
-  ASSERT_OK(token->Submit([&latch]() { latch.Wait(); }));
-  ASSERT_EQ(4, pool_->num_threads());
-  ASSERT_OK(token->Schedule([&latch]() { latch.Wait(); }, kDelayMs));
-  ASSERT_OK(token->Schedule([&latch]() { latch.Wait(); }, static_cast<int>(kDelayMs * 1.2)));
-  ASSERT_EQ(4, pool_->num_threads());
-  latch.CountDown();
-  pool_->Wait();
-
-  latch.Reset(1);
-  ASSERT_EQ(0, pool_->num_active_threads());
-  SleepFor(MonoDelta::FromMilliseconds(static_cast<int>(kDelayMs * 1.5)));
-  ASSERT_GT(pool_->num_active_threads(), 0);
-  ASSERT_OK(token->Schedule([&latch]() { latch.Wait(); }, kDelayMs));
-  latch.CountDown();
-  pool_->Wait();
-  ASSERT_EQ(0, pool_->num_active_threads());
-  SleepFor(MonoDelta::FromMilliseconds(10 * kIdleTimeoutMs));
-  ASSERT_EQ(0, pool_->num_threads());
-  ASSERT_EQ(0, pool_->num_active_threads());
-  pool_->Shutdown();
-  ASSERT_EQ(nullptr, pool_->scheduler_);
-}
-
 TEST_F(ThreadPoolTest, TestThreadPoolWithNoMaxThreads) {
   // By default a threadpool's max_threads is set to the number of CPUs, so
   // this test submits more tasks than that to ensure that the number of CPUs
diff --git a/src/kudu/util/threadpool.cc b/src/kudu/util/threadpool.cc
index 09e2c4ad2..b4c6e3ffc 100644
--- a/src/kudu/util/threadpool.cc
+++ b/src/kudu/util/threadpool.cc
@@ -17,6 +17,7 @@
 
 #include "kudu/util/threadpool.h"
 
+#include <cstdint>
 #include <deque>
 #include <functional>
 #include <limits>
@@ -57,9 +58,7 @@ ThreadPoolBuilder::ThreadPoolBuilder(string name)
       min_threads_(0),
       max_threads_(base::NumCPUs()),
       max_queue_size_(std::numeric_limits<int>::max()),
-      idle_timeout_(MonoDelta::FromMilliseconds(500)),
-      enable_scheduler_(false),
-      schedule_period_ms_(100) {}
+      idle_timeout_(MonoDelta::FromMilliseconds(500)) {}
 
 ThreadPoolBuilder& ThreadPoolBuilder::set_trace_metric_prefix(const string& prefix) {
   trace_metric_prefix_ = prefix;
@@ -93,16 +92,6 @@ ThreadPoolBuilder& ThreadPoolBuilder::set_metrics(ThreadPoolMetrics metrics) {
   return *this;
 }
 
-ThreadPoolBuilder& ThreadPoolBuilder::set_enable_scheduler() {
-  enable_scheduler_ = true;
-  return *this;
-}
-
-ThreadPoolBuilder& ThreadPoolBuilder::set_schedule_period_ms(uint32_t schedule_period_ms) {
-  schedule_period_ms_ = schedule_period_ms;
-  return *this;
-}
-
 ThreadPoolBuilder& ThreadPoolBuilder::set_queue_overload_threshold(
     const MonoDelta& threshold) {
   queue_overload_threshold_ = threshold;
@@ -114,65 +103,6 @@ Status ThreadPoolBuilder::Build(unique_ptr<ThreadPool>* pool) const {
   return (*pool)->Init();
 }
 
-SchedulerThread::SchedulerThread(string thread_pool_name, uint32_t schedule_period_ms)
-    : thread_pool_name_(std::move(thread_pool_name)),
-      schedule_period_ms_(schedule_period_ms),
-      shutdown_(1) {}
-
-SchedulerThread::~SchedulerThread() {
-  if (thread_) {
-    Shutdown();
-  }
-}
-
-Status SchedulerThread::Start() {
-  return Thread::Create(
-      thread_pool_name_, "scheduler", [this]() { this->RunLoop(); }, &thread_);
-}
-
-void SchedulerThread::Shutdown() {
-  if (thread_) {
-    shutdown_.CountDown();
-    thread_->Join();
-  }
-}
-
-void SchedulerThread::RunLoop() {
-  while (!shutdown_.WaitFor(MonoDelta::FromMilliseconds(schedule_period_ms_))) {
-    MonoTime now = MonoTime::Now();
-    vector<SchedulerTask> pending_tasks;
-    {
-      std::lock_guard auto_lock(mutex_);
-      auto upper_it = future_tasks_.upper_bound(now);
-      for (auto it = future_tasks_.begin(); it != upper_it; it++) {
-        pending_tasks.emplace_back(std::move(it->second));
-      }
-      future_tasks_.erase(future_tasks_.begin(), upper_it);
-    }
-
-    for (const auto& task : pending_tasks) {
-      ThreadPoolToken* token = task.thread_pool_token();
-      while (token != nullptr) {
-        Status s = token->Submit(task.func());
-        if (s.ok()) {
-          break;
-        }
-        DCHECK(s.IsServiceUnavailable())
-            << Substitute("threadpool token Submit status: $0", s.ToString());
-
-        if (!token->MaySubmitNewTasks()) {
-          // threadpool token is Shutdown, skip the task.
-          break;
-        }
-        // If developers use ThreadPoolToken::Schedule(...) too frequent, blocking queue's
-        // capacity will be full, then retry submit the task again.
-        VLOG(1) << Substitute("threadpool token Submit status: $0, retry the task", s.ToString());
-        SleepFor(MonoDelta::FromMilliseconds(1));
-      }
-    }
-  }
-}
-
 ////////////////////////////////////////////////////////
 // ThreadPoolToken
 ////////////////////////////////////////////////////////
@@ -257,14 +187,6 @@ void ThreadPoolToken::Shutdown() {
   }
 }
 
-// Submit a task, running after delay_ms delay some time
-Status ThreadPoolToken::Schedule(std::function<void()> f, int64_t delay_ms) {
-  CHECK(mode() == ThreadPool::ExecutionMode::SERIAL);
-  return pool_->Schedule(this,
-                         std::move(f),
-                         MonoTime::Now() + MonoDelta::FromMilliseconds(delay_ms));
-}
-
 void ThreadPoolToken::Wait() {
   std::lock_guard unique_lock(pool_->lock_);
   pool_->CheckNotPoolThreadUnlocked();
@@ -365,10 +287,7 @@ ThreadPool::ThreadPool(const ThreadPoolBuilder& builder)
       active_threads_(0),
       total_queued_tasks_(0),
       tokenless_(NewToken(ExecutionMode::CONCURRENT)),
-      metrics_(builder.metrics_),
-      scheduler_(nullptr),
-      schedule_period_ms_(builder.schedule_period_ms_),
-      enable_scheduler_(builder.enable_scheduler_) {
+      metrics_(builder.metrics_) {
   string prefix = !builder.trace_metric_prefix_.empty() ?
       builder.trace_metric_prefix_ : builder.name_;
 
@@ -411,22 +330,10 @@ Status ThreadPool::Init() {
       return status;
     }
   }
-  if (enable_scheduler_) {
-    scheduler_ = new SchedulerThread(name_, schedule_period_ms_);
-    RETURN_NOT_OK(scheduler_->Start());
-  }
   return Status::OK();
 }
 
 void ThreadPool::Shutdown() {
-  {
-    std::lock_guard l(scheduler_lock_);
-    if (scheduler_) {
-      delete scheduler_;
-      scheduler_ = nullptr;
-    }
-  }
-
   std::unique_lock lock(lock_);
   CheckNotPoolThreadUnlocked();
   // Note: this is the same error seen at submission if the pool is at
@@ -531,17 +438,6 @@ Status ThreadPool::Submit(std::function<void()> f) {
   return DoSubmit(std::move(f), tokenless_.get());
 }
 
-Status ThreadPool::Schedule(ThreadPoolToken* token,
-                            std::function<void()> f,
-                            MonoTime execute_time) {
-  std::lock_guard l(scheduler_lock_);
-  if (!scheduler_) {
-    return Status::IllegalState("scheduler thread has been shutdown");
-  }
-  scheduler_->Schedule(token, std::move(f), execute_time);
-  return Status::OK();
-}
-
 Status ThreadPool::DoSubmit(std::function<void()> f, ThreadPoolToken* token) {
   DCHECK(token);
   const MonoTime submit_time = MonoTime::Now();
diff --git a/src/kudu/util/threadpool.h b/src/kudu/util/threadpool.h
index 887594423..71f4c9850 100644
--- a/src/kudu/util/threadpool.h
+++ b/src/kudu/util/threadpool.h
@@ -20,15 +20,12 @@
 
 #include <atomic>
 #include <cstddef>
-#include <cstdint>
 #include <deque>
 #include <functional>
 #include <iosfwd>
-#include <map>
 #include <memory>
 #include <string>
 #include <unordered_set>
-#include <utility>
 
 #include <boost/intrusive/list.hpp>
 #include <boost/intrusive/list_hook.hpp>
@@ -38,7 +35,6 @@
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/util/condition_variable.h"
-#include "kudu/util/countdown_latch.h"
 #include "kudu/util/metrics.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/mutex.h"
@@ -123,8 +119,6 @@ class ThreadPoolBuilder {
   ThreadPoolBuilder& set_idle_timeout(const MonoDelta& idle_timeout);
   ThreadPoolBuilder& set_queue_overload_threshold(const MonoDelta& threshold);
   ThreadPoolBuilder& set_metrics(ThreadPoolMetrics metrics);
-  ThreadPoolBuilder& set_enable_scheduler();
-  ThreadPoolBuilder& set_schedule_period_ms(uint32_t schedule_period_ms);
 
   // Instantiate a new ThreadPool with the existing builder arguments.
   Status Build(std::unique_ptr<ThreadPool>* pool) const;
@@ -139,100 +133,10 @@ class ThreadPoolBuilder {
   MonoDelta idle_timeout_;
   MonoDelta queue_overload_threshold_;
   ThreadPoolMetrics metrics_;
-  bool enable_scheduler_;
-  uint32_t schedule_period_ms_ = 100;
 
   DISALLOW_COPY_AND_ASSIGN(ThreadPoolBuilder);
 };
 
-// SchedulerThread for asynchronized delay task execution.
-//
-// Notice: Take care of Shutdown's order.
-//
-// Firstly, shutdown the ThreadPool and wait SchedulerThread stop.
-// Secondly, delete all the thread pool tokens to release all tokens for the ThreadPool.
-// Lastly, release the ThreadPool.
-//
-// For example:
-//   static void Func(int n) { ... }
-//
-//   unique_ptr<ThreadPool> scheduler_pool;
-//   ThreadPoolBuilder("scheduler")
-//            .set_min_threads(1)
-//            .set_max_threads(4)
-//            .set_enable_scheduler()
-//            .set_schedule_period_ms(100)
-//            .Build(&scheduler_pool);
-//   unique_ptr<ThreadPoolToken> token =
-//            scheduler_pool.NewToken(ThreadPool::ExecutionMode::SERIAL);
-//   RETURN_NOT_OK(token->Schedule([]() { Func(10); }, 1000));
-//
-// The order of Shutdown and Release should adhere to the notice above, for example:
-//   scheduler_pool.Shutdown(); // shutdown scheduler_pool and wait scheduler thread stop.
-//   // The 'token' and 'scheduler_pool' will be released automatically in reverse order of
-//   // their declaration: that's the proper sequence as prescribed above.
-//
-class SchedulerThread {
-public:
-  explicit SchedulerThread(std::string thread_pool_name, uint32_t schedule_period_ms);
-
-  ~SchedulerThread();
-
-  // Start a thread to judge which tasks can be execute now.
-  Status Start();
-
-  // Shutdown the thread and clear the pending tasks.
-  void Shutdown();
-
-  class SchedulerTask {
-   public:
-    SchedulerTask(ThreadPoolToken* thread_pool_token, std::function<void()> func)
-        : thread_pool_token_(thread_pool_token), func_(std::move(func)) {}
-    ThreadPoolToken* thread_pool_token() const { return thread_pool_token_; }
-    const std::function<void()>& func() const { return func_; }
-
-   private:
-    ThreadPoolToken* thread_pool_token_;
-    std::function<void()> func_;
-  };
-
-  // Submit a task to 'token', execute the task at execute_time.
-  void Schedule(ThreadPoolToken* token,
-                std::function<void()> f,
-                const MonoTime& execute_time) {
-    std::lock_guard lock(mutex_);
-    future_tasks_.insert({execute_time, SchedulerTask({token, std::move(f)})});
-  }
-
-  bool empty() const {
-    std::lock_guard lock(mutex_);
-    return future_tasks_.empty();
-  }
-
-private:
-  friend class ThreadPool;
-  friend class ThreadPoolToken;
-
-  void RunLoop();
-
-  const std::string thread_pool_name_;
-
-  // scheduler's period checking time.
-  const uint32_t schedule_period_ms_;
-
-  CountDownLatch shutdown_;
-
-  // Protect `future_tasks_` data race.
-  mutable Mutex mutex_;
-
-  // Thread to drive `future_tasks_` by absolutely time.
-  scoped_refptr<Thread> thread_;
-
-  // Tasks order by their execute timepoint. The `thread_` would execute tasks,
-  // the tasks match the condition its timepoint <= now timepoint.
-  std::multimap<MonoTime, SchedulerTask> future_tasks_;
-};
-
 // Thread pool with a variable number of threads.
 //
 // Tasks submitted directly to the thread pool enter a FIFO queue and are
@@ -281,9 +185,6 @@ class ThreadPool {
   // Submits a new task.
   Status Submit(std::function<void()> f) WARN_UNUSED_RESULT;
 
-  // Submit a task to 'token', execute the task at execute_time.
-  Status Schedule(ThreadPoolToken* token, std::function<void()> f, MonoTime execute_time);
-
   // Waits until all the tasks are completed.
   void Wait();
 
@@ -329,9 +230,7 @@ class ThreadPool {
                        MonoDelta* threshold = nullptr) const;
 
  private:
-  FRIEND_TEST(ThreadPoolTest, TestSimpleTasks);
   FRIEND_TEST(ThreadPoolTest, TestThreadPoolWithNoMinimum);
-  FRIEND_TEST(ThreadPoolTest, TestThreadPoolWithSchedulerAndNoMinimum);
   FRIEND_TEST(ThreadPoolTest, TestVariableSizeThreadPool);
 
   friend class ThreadPoolBuilder;
@@ -511,13 +410,6 @@ class ThreadPool {
   //  * a new task has been scheduled (i.e. added into the queue)
   void NotifyLoadMeterUnlocked(const MonoDelta& queue_time = MonoDelta());
 
-  // Return the number of threads currently running for this thread pool.
-  // Used by tests to avoid tsan test case down.
-  int num_active_threads() {
-    std::lock_guard l(lock_);
-    return active_threads_;
-  }
-
   const std::string name_;
   const int min_threads_;
   const int max_threads_;
@@ -611,17 +503,6 @@ class ThreadPool {
   // Metrics for the entire thread pool.
   const ThreadPoolMetrics metrics_;
 
-  // Protect 'scheduler_'.
-  mutable Mutex scheduler_lock_;
-
-  // TimerThread is used for some scenarios, such as
-  // make a task delay execution.
-  // It would shut down and be deleted firstly when 'Shutdown'.
-  SchedulerThread* scheduler_;
-  uint32_t schedule_period_ms_;
-
-  bool enable_scheduler_;
-
   const char* queue_time_trace_metric_name_;
   const char* run_wall_time_trace_metric_name_;
   const char* run_cpu_time_trace_metric_name_;
@@ -645,9 +526,6 @@ class ThreadPoolToken {
   // Submits a new task.
   Status Submit(std::function<void()> f) WARN_UNUSED_RESULT;
 
-  // Submit a task, execute the task after delay_ms later.
-  Status Schedule(std::function<void()> f, int64_t delay_ms) WARN_UNUSED_RESULT;
-
   // Marks the token as unusable for future submissions. Any queued tasks not
   // yet running are destroyed. If tasks are in flight, Shutdown() will wait
   // on their completion before returning.
@@ -669,7 +547,6 @@ class ThreadPoolToken {
   bool WaitFor(const MonoDelta& delta);
 
  private:
-  friend class SchedulerThread;
   // All possible token states. Legal state transitions:
   //   IDLE      -> RUNNING: task is submitted via token
   //   IDLE      -> QUIESCED: token or pool is shut down