parallel 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme.md +1 -0
- data/VERSION +1 -1
- data/lib/parallel.rb +11 -1
- data/parallel.gemspec +2 -2
- data/spec/parallel_spec.rb +20 -0
- metadata +4 -4
data/Readme.md
CHANGED
@@ -40,6 +40,7 @@ Processes/Threads are workers, they grab the next piece of work when they finish
|
|
40
40
|
Tips
|
41
41
|
====
|
42
42
|
- [ActiveRecord] `ActiveRecord::Base.connection.reconnect!` inside the parallel block prevents errors
|
43
|
+
- [Benchmark/Test] Disable threading/forking with `:in_threads => 0` or `:in_processes => 0`, great to test performance or to debug parallel issues
|
43
44
|
|
44
45
|
TODO
|
45
46
|
====
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.7
|
data/lib/parallel.rb
CHANGED
@@ -49,6 +49,8 @@ class Parallel
|
|
49
49
|
end
|
50
50
|
size = [array.size, size].min
|
51
51
|
|
52
|
+
return work_direct(array, options, &block) if size == 0
|
53
|
+
|
52
54
|
if method == :in_threads
|
53
55
|
work_in_threads(array, options.merge(:count => size), &block)
|
54
56
|
else
|
@@ -67,7 +69,7 @@ class Parallel
|
|
67
69
|
when /darwin/
|
68
70
|
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
|
69
71
|
when /linux/
|
70
|
-
`
|
72
|
+
`grep -c processor /proc/cpuinfo`.to_i
|
71
73
|
when /freebsd/
|
72
74
|
`sysctl -n hw.ncpu`.to_i
|
73
75
|
when /mswin|mingw/
|
@@ -80,6 +82,14 @@ class Parallel
|
|
80
82
|
|
81
83
|
private
|
82
84
|
|
85
|
+
def self.work_direct(array, options)
|
86
|
+
results = []
|
87
|
+
array.each_with_index do |e,i|
|
88
|
+
results << (options[:with_index] ? yield(e,i) : yield(e))
|
89
|
+
end
|
90
|
+
results
|
91
|
+
end
|
92
|
+
|
83
93
|
def self.hwprefs_available?
|
84
94
|
`which hwprefs` != ''
|
85
95
|
end
|
data/parallel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{parallel}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-08}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.files = [
|
15
15
|
"Gemfile",
|
data/spec/parallel_spec.rb
CHANGED
@@ -131,6 +131,16 @@ describe Parallel do
|
|
131
131
|
it 'joins all workers, when one fails in thread' do
|
132
132
|
`ruby spec/cases/map_with_threads_and_exceptions.rb 2>&1`.should =~ /^\d{0,4} all joined raised$/
|
133
133
|
end
|
134
|
+
|
135
|
+
it "can run with 0 threads" do
|
136
|
+
Thread.should_not_receive(:exclusive)
|
137
|
+
Parallel.map([1,2,3,4,5,6,7,8,9], :in_threads => 0){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "can run with 0 processes" do
|
141
|
+
Process.should_not_receive(:fork)
|
142
|
+
Parallel.map([1,2,3,4,5,6,7,8,9], :in_processes => 0){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
|
143
|
+
end
|
134
144
|
end
|
135
145
|
|
136
146
|
describe :map_with_index do
|
@@ -141,6 +151,16 @@ describe Parallel do
|
|
141
151
|
it "does not crash with empty set" do
|
142
152
|
`ruby spec/cases/map_with_index_empty.rb 2>&1`.should == ''
|
143
153
|
end
|
154
|
+
|
155
|
+
it "can run with 0 threads" do
|
156
|
+
Thread.should_not_receive(:exclusive)
|
157
|
+
Parallel.map_with_index([1,2,3,4,5,6,7,8,9], :in_threads => 0){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
|
158
|
+
end
|
159
|
+
|
160
|
+
it "can run with 0 processes" do
|
161
|
+
Process.should_not_receive(:fork)
|
162
|
+
Parallel.map_with_index([1,2,3,4,5,6,7,8,9], :in_processes => 0){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
|
163
|
+
end
|
144
164
|
end
|
145
165
|
|
146
166
|
describe :each do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 7
|
10
|
+
version: 0.5.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|