-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* run cluster in parallel mode * add test cases for cluster parallel mode * additional test cases * prepare 1.0.0.beta1 * update readme Co-authored-by: Ryan <rmammina@gmail.com>
- Loading branch information
1 parent
e525eaa
commit 01dc73f
Showing
16 changed files
with
390 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
require 'etc' | ||
|
||
module Kanrisuru | ||
# https://github.com/grosser/parallel/blob/master/lib/parallel/processor_count.rb | ||
module ProcessorCount | ||
# Number of processors seen by the OS, used for process scheduling | ||
def self.processor_count | ||
@processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors) | ||
end | ||
|
||
# Number of physical processor cores on the current system. | ||
def self.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 | ||
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 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Kanrisuru | ||
VERSION = '0.20.0' | ||
VERSION = '1.0.0.beta1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Kanrisuru::ProcessorCount do | ||
it 'gets processor count' do | ||
expect(described_class.processor_count).to be > 0 | ||
end | ||
|
||
it 'gets physical processor count' do | ||
expect(described_class.physical_processor_count).to be > 0 | ||
end | ||
|
||
it "is even factor of logical cpus" do | ||
expect(described_class.processor_count % described_class.physical_processor_count).to be == 0 | ||
end | ||
end |
Oops, something went wrong.