[CP] tenant set the cpu_cfs_quota according to cfs_period_us
This commit is contained in:
parent
505cfa1e53
commit
cf7d59372b
@ -1015,15 +1015,36 @@ void ObTenant::set_unit_max_cpu(double cpu)
|
||||
{
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
unit_max_cpu_ = cpu;
|
||||
const double default_cfs_period_us = 100000.0;
|
||||
int32_t cfs_quota_us = static_cast<int32_t>(default_cfs_period_us * cpu);
|
||||
if (is_sys_tenant(id_)) {
|
||||
cfs_quota_us = -1;
|
||||
}
|
||||
if (cgroup_ctrl_.is_valid()
|
||||
&& !is_meta_tenant(id_)
|
||||
&& OB_SUCCESS != (tmp_ret = cgroup_ctrl_.set_cpu_cfs_quota(cfs_quota_us, id_))) {
|
||||
LOG_WARN_RET(tmp_ret, "set cpu cfs quota failed", K(tmp_ret), K_(id), K(cfs_quota_us));
|
||||
int32_t cfs_period_us = 0;
|
||||
int32_t cfs_period_us_new = 0;
|
||||
if (!cgroup_ctrl_.is_valid() || is_meta_tenant(id_)) {
|
||||
// do nothing
|
||||
} else if (is_sys_tenant(id_)) {
|
||||
int32_t sys_cfs_quota_us = -1;
|
||||
if (OB_TMP_FAIL(cgroup_ctrl_.set_cpu_cfs_quota(sys_cfs_quota_us, id_))) {
|
||||
LOG_WARN_RET(tmp_ret, "set sys tennat cpu cfs quota failed", K(tmp_ret), K_(id), K(sys_cfs_quota_us));
|
||||
}
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.get_cpu_cfs_period(cfs_period_us_new, id_, INT64_MAX))) {
|
||||
LOG_WARN_RET(tmp_ret, "fail get cpu cfs period", K_(id));
|
||||
} else {
|
||||
uint32_t loop_times = 0;
|
||||
// to avoid kernel scaling cfs_period_us after get cpu_cfs_period,
|
||||
// we should check whether cfs_period_us has been changed after set cpu_cfs_quota.
|
||||
while (OB_SUCCESS == tmp_ret && cfs_period_us_new != cfs_period_us) {
|
||||
cfs_period_us = cfs_period_us_new;
|
||||
int32_t cfs_quota_us = static_cast<int32_t>(cfs_period_us * cpu);
|
||||
if (OB_TMP_FAIL(cgroup_ctrl_.set_cpu_cfs_quota(cfs_quota_us, id_))) {
|
||||
LOG_WARN_RET(tmp_ret, "set cpu cfs quota failed", K_(id), K(cfs_quota_us));
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.get_cpu_cfs_period(cfs_period_us_new, id_, INT64_MAX))) {
|
||||
LOG_ERROR_RET(tmp_ret, "fail get cpu cfs period", K_(id));
|
||||
} else {
|
||||
loop_times++;
|
||||
if (loop_times > 3) {
|
||||
tmp_ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR_RET(tmp_ret, "cpu_cfs_period has been always changing, thread may be hung", K_(id), K(cfs_period_us), K(cfs_period_us_new), K(cfs_quota_us));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user