ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.71k stars 420 forks source link

Add `Concurrent.cpu_requests` that is cgroups aware. #1058

Closed heka1024 closed 3 months ago

heka1024 commented 3 months ago

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.

eregon commented 3 months ago

Could you summarize in one/a few sentences why one should use cpu requests instead of cpu limits?

heka1024 commented 3 months ago

@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.

eregon commented 3 months ago

I've read quickly through the blog posts, so it seems the limit/quota is a hard limit (don't use more CPU even if idle) and this requests/shares/weight is like a relative share for each pod/workload on the node, so can use more of the CPU if available. Makes sense.

eregon commented 3 months ago

@byroot @casperisfine Could you review this too?

heka1024 commented 3 months ago

@byroot @eregon I'd undo the "extract method" and replace it with file existence check. Could you review this once again?