From f64b649339077f60251eeeaebe6e0340fee56ffb Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 18 Jun 2012 00:14:34 +0200 Subject: [PATCH 1/2] Bugfixes. --- components/checker/checkercomponent.cpp | 15 ++++++++++----- components/checker/checkercomponent.h | 14 +++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index cbd09176c..e76989be2 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -64,10 +64,10 @@ void CheckerComponent::CheckTimerHandler(void) time_t now; time(&now); - if (m_Services.size() == 0) - return; - for (;;) { + if (m_Services.size() == 0) + break; + Service service = m_Services.top(); if (service.GetNextCheck() > now || service.HasPendingCheck()) @@ -83,7 +83,6 @@ void CheckerComponent::CheckTimerHandler(void) m_PendingTasks.push_back(task); service.SetNextCheck(now + service.GetCheckInterval()); - m_Services.push(service); } AdjustCheckTimer(); @@ -101,10 +100,13 @@ void CheckerComponent::ResultTimerHandler(void) continue; } - task->GetService().SetPendingCheck(false); + Service service = task->GetService(); + service.SetPendingCheck(false); CheckResult result = task->GetResult(); Application::Log(LogInformation, "checker", "Got result! Plugin output: " + result.Output); + + m_Services.push(service); } m_PendingTasks = unfinishedTasks; @@ -176,6 +178,9 @@ void CheckerComponent::RevokeServiceRequestHandler(const Endpoint::Ptr& sender, if (service.GetName() == name) continue; + if (service.HasPendingCheck()) // TODO: remember services that should be removed once their pending check is done + throw runtime_error("not yet implemented"); + services.push_back(service); } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index da924d47c..e33402eb1 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -23,14 +23,11 @@ namespace icinga { -struct ServiceCheckPriorityLessComparer +struct ServiceNextCheckLessComparer { public: bool operator()(const Service& a, const Service& b) { - if (a.HasPendingCheck() && !b.HasPendingCheck()) - return true; - return a.GetNextCheck() > b.GetNextCheck(); } }; @@ -44,17 +41,20 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef priority_queue, ServiceCheckPriorityLessComparer> ServiceQueue; + typedef priority_queue, ServiceNextCheckLessComparer> ServiceQueue; virtual string GetName(void) const; virtual void Start(void); virtual void Stop(void); private: - ServiceQueue m_Services; - Timer::Ptr m_CheckTimer; VirtualEndpoint::Ptr m_CheckerEndpoint; + ServiceQueue m_Services; + set m_PendingServices; + + Timer::Ptr m_CheckTimer; + Timer::Ptr m_ResultTimer; vector m_PendingTasks; From 86ffd15eb94e62ed773034446d24f20c7e79d5c4 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 18 Jun 2012 01:29:02 +0200 Subject: [PATCH 2/2] Performance fixes. --- base/threadpool.h | 4 ++-- base/timer.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/base/threadpool.h b/base/threadpool.h index 52b766400..2eded6ef9 100644 --- a/base/threadpool.h +++ b/base/threadpool.h @@ -12,7 +12,7 @@ public: typedef function Task; - ThreadPool(long numThreads = 16); + ThreadPool(long numThreads = 64); ~ThreadPool(void); static ThreadPool::Ptr GetDefaultPool(void); @@ -33,4 +33,4 @@ private: } -#endif /* THREADPOOL_H */ \ No newline at end of file +#endif /* THREADPOOL_H */ diff --git a/base/timer.cpp b/base/timer.cpp index 9159abe90..caeaca719 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -131,8 +131,6 @@ void Timer::Start(void) Stop(); Timers.push_back(GetSelf()); - - Reschedule(time(NULL) + m_Interval); } /**