class Concurrent::Utility::ProcessorCounter
def compute_cpu_shares
def compute_cpu_shares if RbConfig::CONFIG["target_os"].include?("linux") if File.exist?("/sys/fs/cgroup/cpu.weight") # cgroups v2: https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files # 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 ((((weight - 1) * 262142) / 9999) + 2) / 1024 elsif File.exist?("/sys/fs/cgroup/cpu/cpu.shares") # cgroups v1: https://kernel.googlesource.com/pub/scm/linux/kernel/git/glommer/memcg/+/cpu_stat/Documentation/cgroups/cpu.txt File.read("/sys/fs/cgroup/cpu/cpu.shares").to_f / 1024 end end end