xpool 0.9.0 → 0.9.0.1
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/ChangeLog.txt +4 -0
- data/README.md +5 -3
- data/lib/xpool.rb +2 -2
- data/lib/xpool/process.rb +5 -6
- data/lib/xpool/version.rb +1 -1
- data/test/support/io_writer.rb +4 -5
- data/test/xpool_process_test.rb +3 -6
- data/test/xpool_test.rb +4 -3
- metadata +4 -4
data/ChangeLog.txt
CHANGED
data/README.md
CHANGED
@@ -17,11 +17,12 @@ that are used when the pool is asked to dispatch a 'unit of work'. A
|
|
17
17
|
All subprocesses in the pool have their own message queue that the pool places
|
18
18
|
work onto according to a very simple algorithm: the subprocess who has scheduled
|
19
19
|
the least amount of work is the subprocess who is asked to put the work on its
|
20
|
-
queue.
|
21
|
-
|
20
|
+
queue. This helps ensure an even distribution of work among all subprocesses in
|
21
|
+
the pool. The message queue that each subprocess has is also what ensures
|
22
|
+
work can be queued when the pool becomes dry (all subprocesses are busy).
|
22
23
|
|
23
24
|
Incase a unit of work raises an exception that it does not handle xpool will
|
24
|
-
|
25
|
+
rescue the exception and mark the process as 'failed'. A failed process can be
|
25
26
|
restarted, and it is also possible to access the backtrace of a failed process
|
26
27
|
through `XPool` and `XPool::Process` objects. The exception is also re-raised
|
27
28
|
so that you can see a process has failed from the output ruby prints when an
|
@@ -76,6 +77,7 @@ end
|
|
76
77
|
pool = XPool.new 2
|
77
78
|
subprocess = pool.schedule Unit.new
|
78
79
|
p subprocess.busy? # => true
|
80
|
+
pool.shutdown
|
79
81
|
```
|
80
82
|
|
81
83
|
_3._
|
data/lib/xpool.rb
CHANGED
@@ -33,6 +33,7 @@ class XPool
|
|
33
33
|
#
|
34
34
|
# @param [Fixnum] size
|
35
35
|
# The number of subprocesses to spawn.
|
36
|
+
# Defaults to the number of cores on your CPU.
|
36
37
|
#
|
37
38
|
# @return [XPool]
|
38
39
|
#
|
@@ -54,6 +55,7 @@ class XPool
|
|
54
55
|
# @example
|
55
56
|
# pool = XPool.new 5
|
56
57
|
# pool.broadcast unit
|
58
|
+
# pool.shutdown
|
57
59
|
#
|
58
60
|
# @raise [RuntimeError]
|
59
61
|
# When a subprocess in the pool is dead.
|
@@ -77,8 +79,6 @@ class XPool
|
|
77
79
|
# An optional amount of seconds to wait before forcing a shutdown through
|
78
80
|
# {#shutdown!}.
|
79
81
|
#
|
80
|
-
# @see XPool::Process#spawn
|
81
|
-
#
|
82
82
|
# @return [void]
|
83
83
|
#
|
84
84
|
def shutdown(timeout=nil)
|
data/lib/xpool/process.rb
CHANGED
@@ -62,7 +62,7 @@ class XPool::Process
|
|
62
62
|
|
63
63
|
#
|
64
64
|
# @return [Boolean]
|
65
|
-
# Returns true when the process is executing work.
|
65
|
+
# Returns true when the process is executing a unit of work.
|
66
66
|
#
|
67
67
|
def busy?
|
68
68
|
synchronize!
|
@@ -79,8 +79,7 @@ class XPool::Process
|
|
79
79
|
|
80
80
|
#
|
81
81
|
# @return [Boolean]
|
82
|
-
# Returns true when
|
83
|
-
# exception.
|
82
|
+
# Returns true when the process has failed due to an unhandled exception.
|
84
83
|
#
|
85
84
|
def failed?
|
86
85
|
synchronize!
|
@@ -89,7 +88,7 @@ class XPool::Process
|
|
89
88
|
|
90
89
|
#
|
91
90
|
# @return [Boolean]
|
92
|
-
# Returns true when the process is
|
91
|
+
# Returns true when the process is still running.
|
93
92
|
#
|
94
93
|
def alive?
|
95
94
|
!dead?
|
@@ -97,7 +96,7 @@ class XPool::Process
|
|
97
96
|
|
98
97
|
#
|
99
98
|
# @return [Boolean]
|
100
|
-
# Returns true when the process
|
99
|
+
# Returns true when the process has shutdown.
|
101
100
|
#
|
102
101
|
def dead?
|
103
102
|
synchronize!
|
@@ -105,7 +104,7 @@ class XPool::Process
|
|
105
104
|
end
|
106
105
|
|
107
106
|
#
|
108
|
-
# If a process has failed (see #failed?) this method returns the backtrace of
|
107
|
+
# If a process has failed (see {#failed?}) this method returns the backtrace of
|
109
108
|
# the exception that caused the process to fail.
|
110
109
|
#
|
111
110
|
# @return [Array<String>]
|
data/lib/xpool/version.rb
CHANGED
data/test/support/io_writer.rb
CHANGED
@@ -9,14 +9,13 @@ class IOWriter
|
|
9
9
|
def run
|
10
10
|
File.open @path, 'w' do |f|
|
11
11
|
f.write 'true'
|
12
|
-
sleep 0.1
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
return @
|
18
|
-
@
|
15
|
+
def wrote_to_disk?
|
16
|
+
return @wrote_to_disk if defined?(@wrote_to_disk)
|
17
|
+
@wrote_to_disk = File.read(@path) == 'true'
|
19
18
|
FileUtils.rm_rf @path
|
20
|
-
@
|
19
|
+
@wrote_to_disk
|
21
20
|
end
|
22
21
|
end
|
data/test/xpool_process_test.rb
CHANGED
@@ -34,13 +34,10 @@ class XPoolProcessTest < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_queue
|
37
|
-
|
38
|
-
|
39
|
-
@process.schedule unit1
|
40
|
-
@process.schedule unit2
|
37
|
+
writers = Array.new(5) { IOWriter.new }
|
38
|
+
writers.each { |writer| @process.schedule writer }
|
41
39
|
@process.shutdown
|
42
|
-
assert
|
43
|
-
assert unit2.run?
|
40
|
+
writers.each { |writer| assert writer.wrote_to_disk? }
|
44
41
|
end
|
45
42
|
|
46
43
|
def test_failed_on_failed_process
|
data/test/xpool_test.rb
CHANGED
@@ -27,9 +27,10 @@ class XPoolTest < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
def test_queue
|
29
29
|
@pool.resize! 1..1
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
writers = Array.new(5) { IOWriter.new }
|
31
|
+
writers.each { |writer| @pool.schedule writer }
|
32
|
+
@pool.shutdown
|
33
|
+
writers.each { |writer| assert writer.wrote_to_disk? }
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_distribution_of_work
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xpool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0
|
4
|
+
version: 0.9.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ichannel
|
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
segments:
|
70
70
|
- 0
|
71
|
-
hash:
|
71
|
+
hash: 761478267261192258
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
segments:
|
79
79
|
- 0
|
80
|
-
hash:
|
80
|
+
hash: 761478267261192258
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
83
|
rubygems_version: 1.8.23
|