mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 06:34:42 +02:00
parent
87bc291a55
commit
585f0537d2
@ -152,7 +152,7 @@ int Main(void)
|
|||||||
Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
|
Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
|
||||||
Application::DeclareRunAsUser(ICINGA_USER);
|
Application::DeclareRunAsUser(ICINGA_USER);
|
||||||
Application::DeclareRunAsGroup(ICINGA_GROUP);
|
Application::DeclareRunAsGroup(ICINGA_GROUP);
|
||||||
Application::DeclareConcurrency(boost::thread::hardware_concurrency());
|
Application::DeclareConcurrency(Utility::PhysicalConcurrency());
|
||||||
|
|
||||||
if (!ScriptGlobal::Exists("UseVfork"))
|
if (!ScriptGlobal::Exists("UseVfork"))
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -1339,7 +1339,7 @@ void Application::DeclareConcurrency(int ncpus)
|
|||||||
*/
|
*/
|
||||||
int Application::GetConcurrency(void)
|
int Application::GetConcurrency(void)
|
||||||
{
|
{
|
||||||
Value defaultConcurrency = boost::thread::hardware_concurrency();
|
static Value defaultConcurrency = Utility::PhysicalConcurrency();
|
||||||
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
|
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
typedef int SOCKET;
|
typedef int SOCKET;
|
||||||
#define INVALID_SOCKET (-1)
|
#define INVALID_SOCKET (-1)
|
||||||
|
@ -1936,3 +1936,69 @@ String Utility::GetIcingaDataPath(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
int Utility::PhysicalConcurrency(void)
|
||||||
|
{
|
||||||
|
#if BOOST_VERSION >= 106100
|
||||||
|
return boost::thread::physical_concurrency();
|
||||||
|
#elif defined(__linux__)
|
||||||
|
std::ifstream fp("/proc/cpuinfo");
|
||||||
|
std::string line;
|
||||||
|
bool htFlag = false;
|
||||||
|
|
||||||
|
while (std::getline(fp, line)) {
|
||||||
|
std::vector<String> tokens;
|
||||||
|
boost::algorithm::split(tokens, line, boost::is_any_of(":"));
|
||||||
|
|
||||||
|
if (tokens.size() != 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String key = tokens[0].Trim();
|
||||||
|
String value = tokens[1].Trim();
|
||||||
|
|
||||||
|
if (key != "flags")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<String> flags;
|
||||||
|
boost::algorithm::split(flags, value, boost::is_any_of(" "));
|
||||||
|
|
||||||
|
if (std::find(flags.begin(), flags.end(), "ht") != flags.end()) {
|
||||||
|
htFlag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::thread::hardware_concurrency() / (htFlag ? 2 : 1);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
DWORD size = 0;
|
||||||
|
|
||||||
|
GetLogicalProcessorInformation(NULL, &size);
|
||||||
|
|
||||||
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||||
|
return boost::thread::hardware_concurrency();
|
||||||
|
|
||||||
|
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> info(size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
|
||||||
|
|
||||||
|
if (GetLogicalProcessorInformation(&info.front(), &size) == FALSE)
|
||||||
|
return boost::thread::hardware_concurrency();
|
||||||
|
|
||||||
|
int ncpus = 0;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const SYSTEM_LOGICAL_PROCESSOR_INFORMATION& slpi, info) {
|
||||||
|
if (slpi.Relationship == RelationProcessorCore)
|
||||||
|
ncpus++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ncpus;
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
int ncpus;
|
||||||
|
size_t size = sizeof(ncpus);
|
||||||
|
|
||||||
|
if (sysctlbyname("hw.physicalcpu", &ncpus, &size, NULL, 0) == 0)
|
||||||
|
return ncpus;
|
||||||
|
else
|
||||||
|
return boost::thread::hardware_concurrency();
|
||||||
|
#else /* __APPLE__ */
|
||||||
|
return boost::thread::hardware_concurrency();
|
||||||
|
#endif /* __APPLE__ */
|
||||||
|
}
|
||||||
|
@ -153,6 +153,8 @@ public:
|
|||||||
static void IncrementTime(double);
|
static void IncrementTime(double);
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
|
static int PhysicalConcurrency(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utility(void);
|
Utility(void);
|
||||||
static void CollectPaths(const String& path, std::vector<String>& paths);
|
static void CollectPaths(const String& path, std::vector<String>& paths);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user