mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Update getNumberOfPhysicalCPUCores.cpp
In Kubernetes shares are calculated from resources.requests.cpu, quota & period - from limits. When you configure only requests without limits - the container still can use all the cores. So you see all the cores the system has. (because of requests the pod just can't be scheduled on the node which have less cpus) So the effective CPU count is all the available cores if you don't have limits, or calculated from quota & period if you have the limits.
This commit is contained in:
parent
1d480178c4
commit
24d72a18d0
@ -38,21 +38,7 @@ unsigned getCGroupLimitedCPUCores(unsigned default_cpu_count)
|
|||||||
quota_count = ceil(static_cast<float>(cgroup_quota) / static_cast<float>(cgroup_period));
|
quota_count = ceil(static_cast<float>(cgroup_quota) / static_cast<float>(cgroup_period));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Share number (typically a number relative to 1024) (2048 typically expresses 2 CPUs worth of processing)
|
return std::min(default_cpu_count, quota_count);
|
||||||
// -1 for no share setup
|
|
||||||
int cgroup_share = read_from("/sys/fs/cgroup/cpu/cpu.shares", -1);
|
|
||||||
// Convert 1024 to no shares setup
|
|
||||||
if (cgroup_share == 1024)
|
|
||||||
cgroup_share = -1;
|
|
||||||
|
|
||||||
# define PER_CPU_SHARES 1024
|
|
||||||
unsigned share_count = default_cpu_count;
|
|
||||||
if (cgroup_share > -1)
|
|
||||||
{
|
|
||||||
share_count = ceil(static_cast<float>(cgroup_share) / static_cast<float>(PER_CPU_SHARES));
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::min(default_cpu_count, std::min(share_count, quota_count));
|
|
||||||
}
|
}
|
||||||
#endif // OS_LINUX
|
#endif // OS_LINUX
|
||||||
|
|
||||||
@ -91,6 +77,7 @@ unsigned getNumberOfPhysicalCPUCores()
|
|||||||
cpu_count = std::thread::hardware_concurrency();
|
cpu_count = std::thread::hardware_concurrency();
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
|
/// TODO: add a setting for disabling that, similar to UseContainerSupport in java
|
||||||
cpu_count = getCGroupLimitedCPUCores(cpu_count);
|
cpu_count = getCGroupLimitedCPUCores(cpu_count);
|
||||||
#endif // OS_LINUX
|
#endif // OS_LINUX
|
||||||
return cpu_count;
|
return cpu_count;
|
||||||
|
Loading…
Reference in New Issue
Block a user