mirror of https://github.com/Icinga/icinga2.git
Implement an experimental variable to limit the number of threads
This commit is contained in:
parent
04fba90118
commit
9386a58bf2
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
{ }
|
||||
|
|
Loading…
Reference in New Issue