diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 72c1c1c7b..0e01d6710 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(); }); @@ -243,35 +245,34 @@ void DbConnection::CleanUpHandler() void DbConnection::LogStatsHandler() { + if (!GetConnected()) + return; + 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 * 5 && !timeoutReached) { return; } auto input = round(m_InputQueries.CalculateRate(now, 10)); - String 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) { + 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 38c93f3ba..a7749d7fa 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -108,6 +108,8 @@ private: Timer::Ptr m_CleanUpTimer; Timer::Ptr m_LogStatsTimer; + double m_LogStatsTimeout; + void CleanUpHandler(); void LogStatsHandler();