Use per user soft limit in GlobalOvercommitTracker

This commit is contained in:
Dmitry Novik 2021-10-26 15:32:17 +03:00
parent 9464dc2fd3
commit 9c7e6c7814
4 changed files with 19 additions and 2 deletions

View File

@ -365,6 +365,12 @@ OvercommitRatio MemoryTracker::getOvercommitRatio()
}
OvercommitRatio MemoryTracker::getOvercommitRatio(Int64 limit)
{
return { amount.load(std::memory_order_relaxed), limit };
}
void MemoryTracker::resetCounters()
{
amount.store(0, std::memory_order_relaxed);

View File

@ -114,6 +114,11 @@ public:
void setSoftLimit(Int64 value);
void setHardLimit(Int64 value);
Int64 getSoftLimit() const
{
return soft_limit.load(std::memory_order_relaxed);
}
/** Set limit if it was not set.
* Otherwise, set limit to new value, if new value is greater than previous limit.
*/
@ -164,6 +169,7 @@ public:
}
OvercommitRatio getOvercommitRatio();
OvercommitRatio getOvercommitRatio(Int64 limit);
void setOvercommitTracker(OvercommitTracker * tracker) noexcept
{

View File

@ -39,7 +39,7 @@ void UserOvercommitTracker::pickQueryToExcludeImpl()
{
MemoryTracker * current_tracker = nullptr;
OvercommitRatio current_ratio{0, 0};
//TODO: ensure this container is not being modified
// At this moment query list must be read only
for (auto const & query : user_process_list->queries)
{
auto * memory_tracker = query.second->getMemoryTracker();
@ -61,7 +61,11 @@ void GlobalOvercommitTracker::pickQueryToExcludeImpl()
process_list->processEachQueryStatus([&](DB::QueryStatus const & query)
{
auto * memory_tracker = query.getMemoryTracker();
auto ratio = memory_tracker->getOvercommitRatio();
Int64 user_soft_limit = 0;
if (auto const * user_process_list = query.getUserProcessList())
user_soft_limit = user_process_list->user_memory_tracker.getSoftLimit();
auto ratio = memory_tracker->getOvercommitRatio(user_soft_limit);
if (current_ratio < ratio)
{
current_tracker = memory_tracker;

View File

@ -80,6 +80,7 @@ protected:
friend class ThreadStatus;
friend class CurrentThread;
friend class ProcessListEntry;
friend struct ::GlobalOvercommitTracker;
String query;
ClientInfo client_info;