Sha256: 35c65261d7b85158133da6b424fbadf05cd22e8487070845bad7fa22e5780fe2

Contents?: true

Size: 1.56 KB

Versions: 2662

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
module Parallel
  # TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
  module ProcessorCount
    # Number of processors seen by the OS, used for process scheduling
    def processor_count
      require 'etc'
      @processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
    end

    # Number of physical processor cores on the current system.
    def physical_processor_count
      @physical_processor_count ||= begin
        ppc =
          case RbConfig::CONFIG["target_os"]
          when /darwin[12]/
            IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
          when /linux/
            cores = {} # unique physical ID / core ID combinations
            phy = 0
            File.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
              if ln.start_with?("physical")
                phy = ln[/\d+/]
              elsif ln.start_with?("core")
                cid = "#{phy}:#{ln[/\d+/]}"
                cores[cid] = true unless cores[cid]
              end
            end
            cores.count
          when /mswin|mingw/
            require 'win32ole'
            result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
              "select NumberOfCores from Win32_Processor"
            )
            result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
          else
            processor_count
          end
        # fall back to logical count if physical info is invalid
        ppc > 0 ? ppc : processor_count
      end
    end
  end
end

Version data entries

2,662 entries across 2,662 versions & 17 rubygems

Version Path
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.13.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.12.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.11.1 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
mux_ruby-3.11.0 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb
cybrid_api_bank_ruby-0.68.55 vendor/bundle/ruby/3.2.0/gems/parallel-1.22.1/lib/parallel/processor_count.rb