-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement CGroups Limit Enforcement for CPUs Allocated #2325
Conversation
Issue: #2261 |
if(allocated_cpus_share_int > -1) | ||
{ | ||
unsigned int allocated_cpus = round (allocated_cpus_share_int / 1000); | ||
return allocated_cpus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method should never return zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 will ensure that
@@ -15,6 +17,22 @@ unsigned getNumberOfPhysicalCPUCores() | |||
{ | |||
#if defined(__x86_64__) | |||
|
|||
std::ifstream cgroup_read_in("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to wrap into something like #if defined(__linux__)
as cgroups exist only on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// If a valid value is present | ||
if(allocated_cpus_share_int > -1) | ||
{ | ||
unsigned int allocated_cpus = round (allocated_cpus_share_int / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: round does nothing as you use integer division.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -1,5 +1,7 @@ | |||
#include <Common/getNumberOfPhysicalCPUCores.h> | |||
#include <thread> | |||
#include <fstream> | |||
#include <math.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for round
.
You may round up, like this: (allocated_cpus_share_int + 999) / 1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks
cgroup_read_in.close(); | ||
|
||
// If a valid value is present | ||
if(allocated_cpus_share_int > -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> -1
looks less clear than >= 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value if the limit is not set is -1, hence used the value. However, using > 0 makes sense since that will allow us to avoid corner cases where the CPU limit is read as 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost Ok.
@alexey-milovidov Please review the second version |
If you want to use throttling, be aware that it's broken: |
OpenJDK is using both shares and determine CPU limit: |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en