-
Notifications
You must be signed in to change notification settings - Fork 420
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
Add Concurrent.cpu_requests
that is cgroups aware.
#1058
Conversation
Could you summarize in one/a few sentences why one should use cpu requests instead of cpu limits? |
@eregon CPU limits can lead to throttling and reduced performance under high load. So, as Tim Hockin suggested, I've set only requests in my application at company. I think this is a quiet common pattern and it'll be nice if we can provide method to get cpu requests. |
I've read quickly through the blog posts, so it seems the |
@byroot @casperisfine Could you review this too? |
if RbConfig::CONFIG["target_os"].include?("linux") | ||
if cgroups_v2? | ||
# Ref: https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2254-cgroup-v2#phase-1-convert-from-cgroups-v1-settings-to-v2 | ||
weight = File.read('/sys/fs/cgroup/cpu.weight').to_f |
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.
It's probably fine, but in compute_cpu_quota
we only ever read files we tested for existence prior.
Here we check /sys/fs/cgroup/cpu.max
and assume it means /sys/fs/cgroup/cpu.weight
exists? Maybe that's a correct assertion, but I personally don't know if it's true.
I think ultimately it would be simpler to not extract cgroups_v1? / cgroups_v2?
and check if /sys/fs/cgroup/cpu.weight
exists here.
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.
Agreed, this seems safer
weight = File.read('/sys/fs/cgroup/cpu.weight').to_f | ||
((((weight - 1) * 262142) / 9999) + 2) / 1024 | ||
elsif cgroups_v1? | ||
File.read('/sys/fs/cgroup/cpu/cpu.shares').to_f / 1024 |
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.
Same issue here.
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.
I'd undo the "extract method" for extra safety, but other than that LGTM.
In K8s environments, cpu requests are often more useful than limits, but concurrent-ruby currently lacks a related method, so I've added it. Below are links to articles about the usefulness of cpu requests.