mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 09:10:48 +00:00
Implement CGroups Limit for CPU
This commit is contained in:
parent
43f0b419ea
commit
cbaf78df4f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user