Skip to content
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

Merged
merged 5 commits into from
May 8, 2018

Conversation

atris
Copy link
Contributor

@atris atris commented May 7, 2018

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@atris
Copy link
Contributor Author

atris commented May 7, 2018

Issue: #2261

if(allocated_cpus_share_int > -1)
{
unsigned int allocated_cpus = round (allocated_cpus_share_int / 1000);
return allocated_cpus;
Copy link
Member

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.

Copy link
Contributor Author

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");
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

@alexey-milovidov alexey-milovidov May 7, 2018

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.

Copy link
Contributor Author

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>
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost Ok.

@atris
Copy link
Contributor Author

atris commented May 8, 2018

@alexey-milovidov Please review the second version

@alexey-milovidov alexey-milovidov merged commit fd9938c into ClickHouse:master May 8, 2018
@atris atris deleted the CGroupsCPULimit branch May 8, 2018 09:57
@bobrik
Copy link
Contributor

bobrik commented Jul 16, 2018

If you want to use throttling, be aware that it's broken:

@bobrik
Copy link
Contributor

bobrik commented Jul 16, 2018

OpenJDK is using both shares and determine CPU limit:

alexey-milovidov added a commit that referenced this pull request Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants