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.68k stars 418 forks source link

Add Concurrent.usable_processor_count that is cgroups aware #1038

Closed casperisfine closed 8 months ago

casperisfine commented 8 months ago

Closes: https://github.com/ruby-concurrency/concurrent-ruby/pull/1035

A running gag since the introduction of containerization is software that starts one process per logical or physical core while running inside a container with a restricted CPU quota and totally blowing up memory usage in containerized environments.

The proper question to ask is how many CPU cores are usable, not how many the machine has. To do that we have to read the cgroup info from /sys. There is two way of doing it depending on the version of cgroups used.

Co-Authored-By: @usiegl00

casperisfine commented 8 months ago

Arf:

     NoMethodError:
       undefined method `match?' for "linux":String

I'll fix 2.3 compat.

casperisfine commented 8 months ago

Thanks!

nertzy commented 3 months ago

Thanks for this! The PR's title has a different method name than the one that landed. I added PR #1049 to fix the CHANGELOG.