Skip to content

Commit

Permalink
Use CoreLocalCounter
Browse files Browse the repository at this point in the history
Signed-off-by: PengFei Li <[email protected]>
  • Loading branch information
banmoy committed Mar 11, 2024
1 parent acec610 commit 20c300b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 3 additions & 5 deletions be/src/util/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,9 @@ void ThreadPool::dispatch_thread() {
task.runnable.reset();
MonoTime finish_time = MonoTime::Now();

_total_executed_tasks.fetch_add(1, std::memory_order_relaxed);
_total_pending_time_ns.fetch_add(start_time.GetDeltaSince(task.submit_time).ToNanoseconds(),
std::memory_order_relaxed);
_total_execute_time_ns.fetch_add(finish_time.GetDeltaSince(start_time).ToNanoseconds(),
std::memory_order_relaxed);
_total_executed_tasks.increment(1);
_total_pending_time_ns.increment(start_time.GetDeltaSince(task.submit_time).ToNanoseconds());
_total_execute_time_ns.increment(finish_time.GetDeltaSince(start_time).ToNanoseconds());

l.lock();
_last_active_timestamp = MonoTime::Now();
Expand Down
13 changes: 7 additions & 6 deletions be/src/util/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "util/bthreads/semaphore.h"
// resolve `barrier` macro conflicts with boost/thread.hpp header file
#undef barrier
#include "util/metrics.h"
#include "util/monotime.h"
#include "util/priority_queue.h"

Expand Down Expand Up @@ -248,11 +249,11 @@ class ThreadPool {

int max_threads() const { return _max_threads.load(std::memory_order_acquire); }

int64_t total_executed_tasks() const { return _total_executed_tasks.load(); }
int64_t total_executed_tasks() const { return _total_executed_tasks.value(); }

int64_t total_pending_time_ns() const { return _total_pending_time_ns.load(); }
int64_t total_pending_time_ns() const { return _total_pending_time_ns.value(); }

int64_t total_execute_time_ns() const { return _total_execute_time_ns.load(); }
int64_t total_execute_time_ns() const { return _total_execute_time_ns.value(); }

private:
friend class ThreadPoolBuilder;
Expand Down Expand Up @@ -379,13 +380,13 @@ class ThreadPool {
std::unique_ptr<ThreadPoolToken> _tokenless;

// Total number of tasks that have finished
std::atomic<int64_t> _total_executed_tasks;
CoreLocalCounter<int64_t> _total_executed_tasks{MetricUnit::NOUNIT};

// Total time in nanoseconds that tasks pending in the queue.
std::atomic<int64_t> _total_pending_time_ns;
CoreLocalCounter<int64_t> _total_pending_time_ns{MetricUnit::NOUNIT};

// Total time in nanoseconds to execute tasks.
std::atomic<int64_t> _total_execute_time_ns;
CoreLocalCounter<int64_t> _total_execute_time_ns{MetricUnit::NOUNIT};

ThreadPool(const ThreadPool&) = delete;
const ThreadPool& operator=(const ThreadPool&) = delete;
Expand Down

0 comments on commit 20c300b

Please sign in to comment.