From 74aa99f575c073da9b7153dc6a251fe8a73426bf Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Thu, 8 Oct 2020 11:35:59 +0200 Subject: [PATCH 1/4] IDO-Logging: Add log timeout to log every 5 minutes --- lib/db_ido/dbconnection.cpp | 22 +++++++++++++++++----- lib/db_ido/dbconnection.hpp | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 6ab9b4e10..9dd7301ff 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -77,6 +77,8 @@ void DbConnection::Resume() m_CleanUpTimer->OnTimerExpired.connect(std::bind(&DbConnection::CleanUpHandler, this)); m_CleanUpTimer->Start(); + m_LogStatsTimeout = 0; + m_LogStatsTimer = new Timer(); m_LogStatsTimer->SetInterval(10); m_LogStatsTimer->OnTimerExpired.connect([this](const Timer * const&) { LogStatsHandler(); }); @@ -245,22 +247,27 @@ void DbConnection::LogStatsHandler() { auto pending = m_PendingQueries.load(); - if (pending == 0u) { + auto now = Utility::GetTime(); + bool timeoutReached = m_LogStatsTimeout < now; + + if (pending == 0u && !timeoutReached) { return; } - auto now = Utility::GetTime(); auto output = round(m_OutputQueries.CalculateRate(now, 10)); - if (pending < output * 2) { + if (pending < output * 2 && !timeoutReached) { return; } auto input = round(m_InputQueries.CalculateRate(now, 10)); - String timeInfo = " empty in "; + String timeInfo = ""; - { + // If we run into our logging timeout, we don't want to display our calculations + // because it should already be basically empty for over 5 minutes. + if (!timeoutReached) { + timeInfo = " empty in "; auto rate = output - input; if (rate <= 0) @@ -272,6 +279,11 @@ void DbConnection::LogStatsHandler() Log(LogInformation, GetReflectionType()->GetName()) << "Pending queries: " << pending << " (Input: " << input << "/s; Output: " << output << "/s)" << timeInfo; + + /* Reschedule next log entry in 5 minutes. */ + if (timeoutReached) { + m_LogStatsTimeout = now + 60 * 5; + } } void DbConnection::CleanUpExecuteQuery(const String&, const String&, double) diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 84e28d4c6..6af4fd908 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -106,6 +106,8 @@ private: Timer::Ptr m_CleanUpTimer; Timer::Ptr m_LogStatsTimer; + double m_LogStatsTimeout; + void CleanUpHandler(); void LogStatsHandler(); From 070c42acab98d9c716cbf0d2a1d9f5a51a889318 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Fri, 9 Oct 2020 14:56:17 +0200 Subject: [PATCH 2/4] IDO-Logging: Remove useless ETA --- lib/db_ido/dbconnection.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 9dd7301ff..ed78da2e4 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -262,23 +262,9 @@ void DbConnection::LogStatsHandler() auto input = round(m_InputQueries.CalculateRate(now, 10)); - String timeInfo = ""; - - // If we run into our logging timeout, we don't want to display our calculations - // because it should already be basically empty for over 5 minutes. - if (!timeoutReached) { - timeInfo = " empty in "; - auto rate = output - input; - - if (rate <= 0) - timeInfo += "infinite time, your task handler isn't able to keep up"; - else - timeInfo += Utility::FormatDuration(pending / rate); - } - Log(LogInformation, GetReflectionType()->GetName()) << "Pending queries: " << pending << " (Input: " << input - << "/s; Output: " << output << "/s)" << timeInfo; + << "/s; Output: " << output << "/s)"; /* Reschedule next log entry in 5 minutes. */ if (timeoutReached) { From bd8339ed46f5c93f40c6c8fa5380b8ee18a59fe1 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Fri, 9 Oct 2020 15:27:05 +0200 Subject: [PATCH 3/4] IDO-Logging: Don't log when not connected --- lib/db_ido/dbconnection.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index ed78da2e4..83cf6517e 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -245,6 +245,9 @@ void DbConnection::CleanUpHandler() void DbConnection::LogStatsHandler() { + if (!GetConnected()) + return; + auto pending = m_PendingQueries.load(); auto now = Utility::GetTime(); From f935fc9b400a48004e4980c87191e5e80f447529 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Fri, 9 Oct 2020 15:40:13 +0200 Subject: [PATCH 4/4] IDO-Logging: Increase logging threshold for nearly empty queue --- lib/db_ido/dbconnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 83cf6517e..62a9c5c3d 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -259,7 +259,7 @@ void DbConnection::LogStatsHandler() auto output = round(m_OutputQueries.CalculateRate(now, 10)); - if (pending < output * 2 && !timeoutReached) { + if (pending < output * 5 && !timeoutReached) { return; }