Implement CGroups Limit for CPU

This commit is contained in:
Atri Sharma 2018-05-07 20:05:45 +05:30 committed by alexey-milovidov
parent 43f0b419ea
commit cbaf78df4f

View File

@ -1,5 +1,6 @@
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <thread>
#include <fstream>
#if defined(__x86_64__)
@ -15,6 +16,21 @@ unsigned getNumberOfPhysicalCPUCores()
{
#if defined(__x86_64__)
std::ifstream cgroup_read_in("/sys/fs/cgroup/cpu/cpu.cfs_quota_us");
if (cgroup_read_in.is_open())
{
std::string allocated_cpus_str{ std::istreambuf_iterator<char>(cgroup_read_in), std::istreambuf_iterator<char>() };
int allocated_cpus_int = std::stoi(allocated_cpus_str);
cgroup_read_in.close();
// If a valid value is present
if(allocated_cpus_int > -1)
{
return (unsigned) allocated_cpus_int;
}
}
cpu_raw_data_t raw_data;
if (0 != cpuid_get_raw_data(&raw_data))
throw DB::Exception("Cannot cpuid_get_raw_data: " + std::string(cpuid_error()), DB::ErrorCodes::CPUID_ERROR);