From 97bd91dda20a7ea35320ef17372f99816a8d7876 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 16 Jan 2018 12:58:45 +0100 Subject: [PATCH] Replace concurrent_checks in CheckerComponent by global MaxConcurrentChecks refs #4841 --- icinga-app/icinga.cpp | 1 + lib/base/application.cpp | 42 +++++++++++++++++++++++++++++++++ lib/base/application.hpp | 5 ++++ lib/checker/checkercomponent.ti | 8 ++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 25282e6d8..ef6627818 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -161,6 +161,7 @@ static int Main() Application::DeclareRLimitStack(Application::GetDefaultRLimitStack()); #endif /* __linux__ */ Application::DeclareConcurrency(std::thread::hardware_concurrency()); + Application::DeclareMaxConcurrentChecks(Application::GetDefaultMaxConcurrentChecks()); ScriptGlobal::Set("AttachDebugger", false); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 573b92b3b..7c552eaeb 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -1552,6 +1552,48 @@ int Application::GetConcurrency() return ScriptGlobal::Get("Concurrency", &defaultConcurrency); } +/** + * Sets the max concurrent checks. + * + * @param maxChecks The new limit. + */ +void Application::SetMaxConcurrentChecks(int maxChecks) +{ + ScriptGlobal::Set("MaxConcurrentChecks", maxChecks); +} + +/** + * Sets the max concurrent checks. + * + * @param maxChecks The new limit. + */ +void Application::DeclareMaxConcurrentChecks(int maxChecks) +{ + if (!ScriptGlobal::Exists("MaxConcurrentChecks")) + ScriptGlobal::Set("MaxConcurrentChecks", maxChecks); +} + +/** + * Retrieves the max concurrent checks. + * + * @returns The max number of concurrent checks. + */ +int Application::GetMaxConcurrentChecks() +{ + Value defaultMaxConcurrentChecks = GetDefaultMaxConcurrentChecks(); + return ScriptGlobal::Get("MaxConcurrentChecks", &defaultMaxConcurrentChecks); +} + +/** + * Retrieves the default value for max concurrent checks. + * + * @returns The default max number of concurrent checks. + */ +int Application::GetDefaultMaxConcurrentChecks() +{ + return 512; +} + /** * Returns the global thread pool. * diff --git a/lib/base/application.hpp b/lib/base/application.hpp index dc54534cc..ecdb1e92b 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -146,6 +146,11 @@ public: static int GetConcurrency(); static void DeclareConcurrency(int ncpus); + static int GetMaxConcurrentChecks(); + static int GetDefaultMaxConcurrentChecks(); + static void DeclareMaxConcurrentChecks(int maxChecks); + static void SetMaxConcurrentChecks(int maxChecks); + static ThreadPool& GetTP(); static String GetAppVersion(); diff --git a/lib/checker/checkercomponent.ti b/lib/checker/checkercomponent.ti index 68fc614fc..119e44252 100644 --- a/lib/checker/checkercomponent.ti +++ b/lib/checker/checkercomponent.ti @@ -27,8 +27,14 @@ namespace icinga class CheckerComponent : ConfigObject { [config] int concurrent_checks { + get {{{ + return Application::GetMaxConcurrentChecks(); + }}} + set {{{ + Application::SetMaxConcurrentChecks(value); + }}} default {{{ - return 512; + return Application::GetDefaultMaxConcurrentChecks(); }}} }; };