Sha256: c59aab488e2d266360dbc6f28efd7540a33087cf7e2afe616424a68794574391

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

require 'etc'

module Parallel
  module ProcessorCount
    # Number of processors seen by the OS and used for process scheduling. It's just wrapper for Etc.nprocessors
    def processor_count
      @processor_count ||= begin
        Etc.nprocessors
      end
    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 /darwin1/
          IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
        when /linux/
          cores = {}  # unique physical ID / core ID combinations
          phy = 0
          IO.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 if not 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

17 entries across 17 versions & 3 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/parallel-1.17.0/lib/parallel/processor_count.rb
parallel-1.17.0 lib/parallel/processor_count.rb
parallel-1.16.2 lib/parallel/processor_count.rb
parallel-1.16.1 lib/parallel/processor_count.rb
parallel-1.16.0 lib/parallel/processor_count.rb
parallel-1.15.0 lib/parallel/processor_count.rb
parallel-1.14.0 lib/parallel/processor_count.rb