fix cpu time of no cgroup
This commit is contained in:
@ -2024,6 +2024,27 @@ int ObMultiTenant::get_tenant_worker_time(const uint64_t tenant_id, int64_t &wor
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObMultiTenant::get_tenant_cpu_time(const uint64_t tenant_id, int64_t &cpu_time) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObTenant *tenant = nullptr;
|
||||
cpu_time = 0;
|
||||
if (GCONF.enable_cgroup) {
|
||||
ret = GCTX.cgroup_ctrl_->get_cpu_time(tenant_id, cpu_time);
|
||||
} else {
|
||||
if (!lock_.try_rdlock()) {
|
||||
ret = OB_EAGAIN;
|
||||
} else {
|
||||
if (OB_FAIL(get_tenant_unsafe(tenant_id, tenant))) {
|
||||
} else {
|
||||
cpu_time = tenant->get_ru_cputime();
|
||||
}
|
||||
lock_.unlock();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObMultiTenant::get_tenant_cpu(
|
||||
const uint64_t tenant_id, double &min_cpu, double &max_cpu) const
|
||||
|
@ -136,6 +136,7 @@ public:
|
||||
inline int64_t get_times_of_workers() const;
|
||||
int get_tenant_cpu_usage(const uint64_t tenant_id, double &usage) const;
|
||||
int get_tenant_worker_time(const uint64_t tenant_id, int64_t &worker_time) const;
|
||||
int get_tenant_cpu_time(const uint64_t tenant_id, int64_t &rusage_time) const;
|
||||
int get_tenant_cpu(
|
||||
const uint64_t tenant_id,
|
||||
double &min_cpu, double &max_cpu) const;
|
||||
|
@ -431,6 +431,7 @@ public:
|
||||
|
||||
OB_INLINE void add_idle_time(int64_t idle_time) { IGNORE_RETURN ATOMIC_FAA(reinterpret_cast<uint64_t *>(&idle_us_), idle_time); }
|
||||
OB_INLINE void add_worker_time(int64_t req_time) { IGNORE_RETURN ATOMIC_FAA(reinterpret_cast<uint64_t *>(&worker_us_), req_time); }
|
||||
OB_INLINE void add_ru_cputime(int64_t ru_utime) { IGNORE_RETURN ATOMIC_FAA(reinterpret_cast<uint64_t *>(&ru_cputime_us_), ru_utime); }
|
||||
int rdlock(common::ObLDHandle &handle);
|
||||
int wrlock(common::ObLDHandle &handle);
|
||||
int try_rdlock(common::ObLDHandle &handle);
|
||||
@ -486,6 +487,8 @@ public:
|
||||
OB_INLINE bool user_sched_enabled() const { return !disable_user_sched_; }
|
||||
OB_INLINE double get_token_usage() const { return token_usage_; }
|
||||
OB_INLINE int64_t get_worker_time() const { return ATOMIC_LOAD(&worker_us_); }
|
||||
OB_INLINE int64_t get_ru_cputime() const { return ATOMIC_LOAD(&ru_cputime_us_); }
|
||||
int64_t get_rusage_time();
|
||||
// sql throttle
|
||||
void update_sql_throttle_metrics(const ObSqlThrottleMetrics &metrics)
|
||||
{ st_metrics_ = metrics; }
|
||||
@ -612,6 +615,7 @@ public:
|
||||
// idle time between two checkpoints
|
||||
int64_t worker_us_ CACHE_ALIGNED;
|
||||
int64_t idle_us_ CACHE_ALIGNED;
|
||||
int64_t ru_cputime_us_ CACHE_ALIGNED;
|
||||
}; // end of class ObTenant
|
||||
|
||||
OB_INLINE int64_t ObResourceGroup::min_worker_cnt() const
|
||||
|
@ -107,7 +107,7 @@ ObThWorker::ObThWorker()
|
||||
priority_limit_(RQ_LOW), is_lq_yield_(false),
|
||||
query_start_time_(0), last_check_time_(0),
|
||||
can_retry_(true), need_retry_(false),
|
||||
has_add_to_cgroup_(false), last_wakeup_ts_(0), is_blocking_(nullptr)
|
||||
has_add_to_cgroup_(false), last_wakeup_ts_(0), is_blocking_(nullptr), ru_cputime_(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -312,6 +312,16 @@ void ObThWorker::set_th_worker_thread_name(uint64_t tenant_id)
|
||||
}
|
||||
}
|
||||
|
||||
void ObThWorker::update_ru_cputime()
|
||||
{
|
||||
struct rusage ru;
|
||||
getrusage(RUSAGE_THREAD, &ru);
|
||||
int64_t ru_utime =
|
||||
ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec
|
||||
+ ru.ru_stime.tv_sec * 1000000 + ru.ru_stime.tv_usec;
|
||||
tenant_->add_ru_cputime(ru_utime - ru_cputime_);
|
||||
ru_cputime_ = ru_utime;
|
||||
}
|
||||
void ObThWorker::worker(int64_t &tenant_id, int64_t &req_recv_timestamp, int32_t &worker_level)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -408,6 +418,9 @@ void ObThWorker::worker(int64_t &tenant_id, int64_t &req_recv_timestamp, int32_t
|
||||
process_request(*req);
|
||||
req_end_time = ObTimeUtility::current_time();
|
||||
tenant_->add_worker_time(req_end_time - req_start_time);
|
||||
if (!GCONF.enable_cgroup) {
|
||||
update_ru_cputime();
|
||||
}
|
||||
query_enqueue_time_ = INT64_MAX;
|
||||
query_start_time_ = INT64_MAX;
|
||||
} else {
|
||||
|
@ -101,8 +101,10 @@ public:
|
||||
OB_INLINE int64_t get_last_wakeup_ts() { return last_wakeup_ts_; }
|
||||
OB_INLINE void set_last_wakeup_ts(int64_t last_wakeup_ts) { last_wakeup_ts_ = last_wakeup_ts; }
|
||||
OB_INLINE bool is_blocking() const { return OB_NOT_NULL(is_blocking_) && (0 != *is_blocking_); }
|
||||
|
||||
private:
|
||||
void set_th_worker_thread_name(uint64_t tenant_id);
|
||||
void update_ru_cputime();
|
||||
void process_request(rpc::ObRequest &req);
|
||||
|
||||
void th_created();
|
||||
@ -135,6 +137,7 @@ private:
|
||||
|
||||
int64_t last_wakeup_ts_;
|
||||
uint8_t* is_blocking_;
|
||||
int64_t ru_cputime_;
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObThWorker);
|
||||
}; // end of class ObThWorker
|
||||
|
@ -233,13 +233,10 @@ int ObAllVirtualSysStat::update_all_stats_(const int64_t tenant_id, ObStatEventS
|
||||
stat_events.get(ObStatEventIds::OBSERVER_PARTITION_TABLE_UPATER_CORE_QUEUE_SIZE - ObStatEventIds::STAT_EVENT_ADD_END -1)->stat_value_
|
||||
= 0;
|
||||
}
|
||||
if (NULL != GCTX.cgroup_ctrl_) {
|
||||
int64_t cpu_time = 0;
|
||||
if (!OB_FAIL(GCTX.cgroup_ctrl_->get_cpu_time(tenant_id, cpu_time))) {
|
||||
stat_events.get(ObStatEventIds::CPU_TIME - ObStatEventIds::STAT_EVENT_ADD_END -1)->stat_value_
|
||||
= cpu_time;
|
||||
}
|
||||
}
|
||||
int64_t cpu_time = 0;
|
||||
GCTX.omt_->get_tenant_cpu_time(tenant_id, cpu_time);
|
||||
stat_events.get(ObStatEventIds::CPU_TIME - ObStatEventIds::STAT_EVENT_ADD_END -1)->stat_value_
|
||||
= cpu_time;
|
||||
ret = ret_bk;
|
||||
}
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user