Add logs to GlobalOvercommitTracker

This commit is contained in:
Dmitry Novik 2021-12-07 01:06:00 +03:00
parent 5639fc35d2
commit 697ab52387
2 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,5 @@
#include "OvercommitTracker.h"
#include <base/logger_useful.h>
#include <chrono>
#include <Interpreters/ProcessList.h>
@ -60,24 +59,21 @@ void UserOvercommitTracker::pickQueryToExcludeImpl()
OvercommitRatio current_ratio{0, 0};
// At this moment query list must be read only
auto & queries = user_process_list->queries;
LOG_DEBUG(&Poco::Logger::get("OvercommitTracker"),
"Trying to choose query to stop from {} queries", queries.size());
LOG_DEBUG(logger, "Trying to choose query to stop from {} queries", queries.size());
for (auto const & query : queries)
{
if (query.second->isKilled())
continue;
auto * memory_tracker = query.second->getMemoryTracker();
auto ratio = memory_tracker->getOvercommitRatio();
LOG_DEBUG(&Poco::Logger::get("OvercommitTracker"),
"Query has ratio {}/{}", ratio.committed, ratio.soft_limit);
LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit);
if (ratio.soft_limit != 0 && current_ratio < ratio)
{
current_tracker = memory_tracker;
current_ratio = ratio;
}
}
LOG_DEBUG(&Poco::Logger::get("OvercommitTracker"),
"Selected to stop query with overcommit ratio {}/{}",
LOG_DEBUG(logger, "Selected to stop query with overcommit ratio {}/{}",
current_ratio.committed, current_ratio.soft_limit);
picked_tracker = current_tracker;
}
@ -86,19 +82,28 @@ void GlobalOvercommitTracker::pickQueryToExcludeImpl()
{
MemoryTracker * current_tracker = nullptr;
OvercommitRatio current_ratio{0, 0};
LOG_DEBUG(logger, "Trying to choose query to stop from {} queries", process_list->size());
process_list->processEachQueryStatus([&](DB::QueryStatus const & query)
{
auto * memory_tracker = query.getMemoryTracker();
if (query.isKilled())
return;
Int64 user_soft_limit = 0;
if (auto const * user_process_list = query.getUserProcessList())
user_soft_limit = user_process_list->user_memory_tracker.getSoftLimit();
if (user_soft_limit == 0)
return;
auto * memory_tracker = query.getMemoryTracker();
auto ratio = memory_tracker->getOvercommitRatio(user_soft_limit);
LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit);
if (current_ratio < ratio)
{
current_tracker = memory_tracker;
current_ratio = ratio;
}
});
LOG_DEBUG(logger, "Selected to stop query with overcommit ratio {}/{}",
current_ratio.committed, current_ratio.soft_limit);
picked_tracker = current_tracker;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <base/logger_useful.h>
#include <base/types.h>
#include <boost/core/noncopyable.hpp>
#include <cassert>
@ -93,6 +94,7 @@ protected:
private:
DB::ProcessListForUser * user_process_list;
Poco::Logger * logger = &Poco::Logger::get("UserOvercommitTracker");
};
struct GlobalOvercommitTracker : OvercommitTracker
@ -108,6 +110,7 @@ protected:
private:
DB::ProcessList * process_list;
Poco::Logger * logger = &Poco::Logger::get("GlobalOvercommitTracker");
};
struct BlockQueryIfMemoryLimit