opt calc global bound for sql auto memory mgr
This commit is contained in:
parent
15307ef94e
commit
a5ceb247de
@ -521,13 +521,16 @@ int ObTenantSqlMemoryManager::get_work_area_size(
|
||||
increase(profile.get_cache_size());
|
||||
LOG_TRACE("trace drift size", K(drift_size_), K(global_bound_size_));
|
||||
if (need_manual_calc_bound()) {
|
||||
++manual_calc_cnt_;
|
||||
if (OB_FAIL(calculate_global_bound_size(allocator, false))) {
|
||||
LOG_WARN("failed to calculate global bound size", K(global_bound_size_));
|
||||
} else {
|
||||
profile.inc_calc_count();
|
||||
LOG_TRACE("trace manual calc global bound size", K(global_bound_size_),
|
||||
K(profile.get_one_pass_size()), K(drift_size_), K(mem_target_));
|
||||
if (OB_SUCCESS == global_bound_update_lock_.try_wrlock(common::ObLatchIds::SQL_MEMORY_MGR_MUTEX_LOCK)) {
|
||||
++manual_calc_cnt_;
|
||||
if (OB_FAIL(calculate_global_bound_size(allocator, false))) {
|
||||
LOG_WARN("failed to calculate global bound size", K(global_bound_size_));
|
||||
} else {
|
||||
profile.inc_calc_count();
|
||||
LOG_TRACE("trace manual calc global bound size", K(global_bound_size_),
|
||||
K(profile.get_one_pass_size()), K(drift_size_), K(mem_target_));
|
||||
}
|
||||
global_bound_update_lock_.unlock();
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
@ -566,6 +569,7 @@ int ObTenantSqlMemoryManager::register_work_area_profile(ObSqlWorkAreaProfile &p
|
||||
} else if (OB_FAIL(profile_lists_[hash_val].register_work_area_profile(profile))) {
|
||||
LOG_WARN("failed to register work area profile", K(hash_val), K(profile));
|
||||
} else {
|
||||
increase_profile_cnt();
|
||||
profile.active_time_ = ObTimeUtility::current_time();
|
||||
}
|
||||
}
|
||||
@ -584,17 +588,20 @@ int ObTenantSqlMemoryManager::update_work_area_profile(
|
||||
// delta_size maybe negative integer
|
||||
(ATOMIC_AAF(&drift_size_, delta_size));
|
||||
if (need_manual_by_drift()) {
|
||||
int64_t pre_drift_size = drift_size_;
|
||||
++manual_calc_cnt_;
|
||||
if (OB_ISNULL(allocator)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("allocator is null", K(lbt()));
|
||||
} else if (OB_FAIL(calculate_global_bound_size(allocator, false))) {
|
||||
LOG_WARN("failed to calculate global bound size", K(global_bound_size_));
|
||||
} else {
|
||||
profile.inc_calc_count();
|
||||
LOG_TRACE("trace manual calc global bound size by drift", K(global_bound_size_),
|
||||
K(profile.get_one_pass_size()), K(drift_size_), K(mem_target_), K(pre_drift_size));
|
||||
if (OB_SUCCESS == global_bound_update_lock_.try_wrlock(common::ObLatchIds::SQL_MEMORY_MGR_MUTEX_LOCK)) {
|
||||
int64_t pre_drift_size = drift_size_;
|
||||
++manual_calc_cnt_;
|
||||
if (OB_ISNULL(allocator)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("allocator is null", K(lbt()));
|
||||
} else if (OB_FAIL(calculate_global_bound_size(allocator, false))) {
|
||||
LOG_WARN("failed to calculate global bound size", K(global_bound_size_));
|
||||
} else {
|
||||
profile.inc_calc_count();
|
||||
LOG_TRACE("trace manual calc global bound size by drift", K(global_bound_size_),
|
||||
K(profile.get_one_pass_size()), K(drift_size_), K(mem_target_), K(pre_drift_size));
|
||||
}
|
||||
global_bound_update_lock_.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -807,6 +814,7 @@ int ObTenantSqlMemoryManager::unregister_work_area_profile(ObSqlWorkAreaProfile
|
||||
} else if (OB_FAIL(profile_lists_[hash_val].unregister_work_area_profile(profile))) {
|
||||
LOG_WARN("failed to register work area profile", K(hash_val), K(profile));
|
||||
} else {
|
||||
decrease_profile_cnt();
|
||||
if (enable_auto_memory_mgr_ && profile.get_auto_policy()) {
|
||||
decrease(profile.get_cache_size());
|
||||
}
|
||||
@ -1060,7 +1068,7 @@ int ObTenantSqlMemoryManager::count_profile_into_work_area_intervals(
|
||||
ObDList<ObSqlWorkAreaProfile> &profile_list = profile_lists_[i].get_profile_list();
|
||||
DLIST_FOREACH_X(profile, profile_list, OB_SUCC(ret)) {
|
||||
if (!profile->get_auto_policy()) {
|
||||
// 没有使用auto的不作为统计之内
|
||||
++cur_profile_cnt;
|
||||
} else if (OB_FAIL(find_interval_index(profile->get_cache_size(), interval_idx, cache_size))) {
|
||||
LOG_WARN("failed to find interval index", K(*profile));
|
||||
} else {
|
||||
|
@ -580,7 +580,7 @@ public:
|
||||
mem_target_(0), max_workarea_size_(0), workarea_hold_size_(0), max_auto_workarea_size_(0),
|
||||
max_tenant_memory_size_(0),
|
||||
manual_calc_cnt_(0), wa_start_(0), wa_end_(0), wa_cnt_(0),
|
||||
lock_()
|
||||
lock_(), global_bound_update_lock_()
|
||||
{}
|
||||
~ObTenantSqlMemoryManager() {}
|
||||
public:
|
||||
@ -632,11 +632,12 @@ private:
|
||||
OB_INLINE bool need_manual_by_drift();
|
||||
|
||||
OB_INLINE void increase(int64_t size)
|
||||
{ (ATOMIC_AAF(&drift_size_, size)); ATOMIC_INC(&profile_cnt_); }
|
||||
{ (ATOMIC_AAF(&drift_size_, size)); }
|
||||
OB_INLINE void decrease(int64_t size)
|
||||
{ (ATOMIC_SAF(&drift_size_, size)); ATOMIC_DEC(&profile_cnt_); }
|
||||
{ (ATOMIC_SAF(&drift_size_, size)); }
|
||||
OB_INLINE int64_t get_drift_size() { return (ATOMIC_LOAD(&drift_size_)); }
|
||||
|
||||
OB_INLINE void increase_profile_cnt() { ATOMIC_INC(&profile_cnt_); }
|
||||
OB_INLINE void decrease_profile_cnt() { ATOMIC_DEC(&profile_cnt_); }
|
||||
void reset();
|
||||
int try_push_profiles_work_area_size(int64_t global_bound_size);
|
||||
int calc_work_area_size_by_profile(int64_t global_bound_size, ObSqlWorkAreaProfile &profile);
|
||||
@ -702,6 +703,7 @@ private:
|
||||
static const int64_t DRIFT_CNT_PERCENT = 10;
|
||||
|
||||
static const int64_t HASH_CNT = 256;
|
||||
static const int64_t MIN_PROFILE_CHANEG_CNT = 8;
|
||||
|
||||
ObTenantSqlMemoryCallback sql_mem_callback_;
|
||||
common::ObFIFOAllocator allocator_;
|
||||
@ -730,6 +732,7 @@ private:
|
||||
int64_t wa_end_;
|
||||
int64_t wa_cnt_;
|
||||
ObLatch lock_;
|
||||
ObLatch global_bound_update_lock_;
|
||||
hash::ObHashMap<ObSqlWorkAreaStat::WorkareaKey,
|
||||
ObSqlWorkAreaStat*, hash::NoPthreadDefendMode> wa_ht_;
|
||||
ObSEArray<ObSqlWorkAreaStat, MAX_WORKAREA_STAT_CNT> workarea_stats_;
|
||||
@ -753,14 +756,16 @@ OB_INLINE bool ObTenantSqlMemoryManager::need_manual_calc_bound()
|
||||
if (need_manual_by_drift()) {
|
||||
manual_calc_bound = true;
|
||||
} else {
|
||||
int64_t delta_cnt = pre_profile_cnt_ - profile_cnt_;
|
||||
if (delta_cnt > 0) {
|
||||
int64_t delta_cnt = std::abs(pre_profile_cnt_ - profile_cnt_);
|
||||
if (delta_cnt >= MIN_PROFILE_CHANEG_CNT) {
|
||||
manual_calc_bound = profile_cnt_ * DRIFT_CNT_PERCENT / 100 < delta_cnt;
|
||||
} else {
|
||||
manual_calc_bound = profile_cnt_ * DRIFT_CNT_PERCENT / 100 < -delta_cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
SQL_ENG_LOG(DEBUG, "print need calc bound", K(manual_calc_bound),
|
||||
K(global_bound_size_),
|
||||
K(drift_size_), K(mem_target_), K(profile_cnt_),
|
||||
K(pre_profile_cnt_), K(profile_cnt_));
|
||||
return manual_calc_bound;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user