]> granicus.if.org Git - icinga2/commitdiff
Implement an experimental variable to limit the number of threads
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 16 Nov 2014 12:14:42 +0000 (13:14 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 16 Nov 2014 12:14:42 +0000 (13:14 +0100)
icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.hpp
lib/base/threadpool.cpp
lib/base/workqueue.cpp

index 14925ec089610fa9d5362bd5c6e911455d27279e..38525fc656f0a9d1d7d8fb9a9795910a169233a1 100644 (file)
@@ -156,6 +156,7 @@ int Main(void)
        Application::DeclareApplicationType("icinga/IcingaApplication");
        Application::DeclareRunAsUser(ICINGA_USER);
        Application::DeclareRunAsGroup(ICINGA_GROUP);
+       Application::DeclareConcurrency(boost::thread::hardware_concurrency());
 
        LogSeverity logLevel = Logger::GetConsoleLogSeverity();
        Logger::SetConsoleLogSeverity(LogWarning);
index d5085bfd775c550fa008ac19f4dee510c3667019..6e489d3efd38f9a61ff7162d6b5221ae6b58ba0c 100644 (file)
@@ -1093,6 +1093,7 @@ void Application::DeclareRunAsUser(const String& user)
 {
        ScriptVariable::Set("RunAsUser", user, false);
 }
+
 /**
  * Retrieves the name of the group.
  *
@@ -1103,6 +1104,27 @@ String Application::GetRunAsGroup(void)
        return ScriptVariable::Get("RunAsGroup");
 }
 
+/**
+ * Sets the concurrency level.
+ *
+ * @param path The new concurrency level.
+ */
+void Application::DeclareConcurrency(int ncpus)
+{
+       ScriptVariable::Set("Concurrency", ncpus, false);
+}
+
+/**
+ * Retrieves the concurrency level.
+ *
+ * @returns The concurrency level.
+ */
+int Application::GetConcurrency(void)
+{
+       Value defaultConcurrency = boost::thread::hardware_concurrency();
+       return ScriptVariable::Get("Concurrency", &defaultConcurrency);
+}
+
 /**
  * Sets the name of the group.
  *
index 42db856965357a99eec20906f0331d518f542f45..be662297ec707036e79873cc5fd0e8650f4005cd 100644 (file)
@@ -122,6 +122,9 @@ public:
        static String GetRunAsGroup(void);
        static void DeclareRunAsGroup(const String& group);
 
+       static int GetConcurrency(void);
+       static void DeclareConcurrency(int ncpus);
+
        static void MakeVariablesConstant(void);
 
        static ThreadPool& GetTP(void);
index b9771c4064208f0c9046c2a8c450101fa469aee2..2b26828609bc087cfacd2984d690dc2957685f21 100644 (file)
@@ -22,6 +22,7 @@
 #include "base/debug.hpp"
 #include "base/utility.hpp"
 #include "base/exception.hpp"
+#include "base/application.hpp"
 #include <boost/bind.hpp>
 #include <iostream>
 
@@ -260,7 +261,7 @@ void ThreadPool::ManagerThreadProc(void)
                                int tthreads = wthreads - alive;
 
                                /* Make sure there is at least one thread per CPU */
-                               int ncput = std::max(boost::thread::hardware_concurrency() / QUEUECOUNT, 4U);
+                               int ncput = std::max(static_cast<unsigned int>(Application::GetConcurrency()) / QUEUECOUNT, 4U);
                                if (alive + tthreads < ncput)
                                        tthreads = ncput - alive;
 
index 1d0256329d426773aa03b364b3d5c79eb60d8818..0450493b50fea5a926fdcf9a5ad1daeede0fc99e 100644 (file)
@@ -21,6 +21,7 @@
 #include "base/utility.hpp"
 #include "base/logger.hpp"
 #include "base/convert.hpp"
+#include "base/application.hpp"
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 
@@ -177,7 +178,7 @@ void WorkQueue::WorkerThreadProc(void)
 }
 
 ParallelWorkQueue::ParallelWorkQueue(void)
-       : m_QueueCount(boost::thread::hardware_concurrency()),
+       : m_QueueCount(Application::GetConcurrency()),
          m_Queues(new WorkQueue[m_QueueCount]),
          m_Index(0)
 { }