xpool 0.9.0 → 0.9.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == v0.9.0.1
2
+ - doc improvements
3
+ revised & improved the README & API documentation.
4
+
1
5
  == v0.9.0
2
6
  - upgrade to ichannel v5.1.1
3
7
  Which in turn fixes a performance bug in XPool#schedule. With ichannel v5.0.1
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. The message queue that each subprocess has is also what ensures work
21
- can be queued when the pool becomes dry (all subprocesses are busy).
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
- catch the exception and mark the process as 'failed'. A failed process can be
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._
@@ -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)
@@ -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 a subprocess has failed due to an unhandled
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 alive.
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 is no longer running.
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>]
@@ -1,3 +1,3 @@
1
1
  class XPool
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.0.1"
3
3
  end
@@ -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 run?
17
- return @run if defined?(@run)
18
- @run = File.read(@path) == 'true'
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
- @run
19
+ @wrote_to_disk
21
20
  end
22
21
  end
@@ -34,13 +34,10 @@ class XPoolProcessTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_queue
37
- unit1 = IOWriter.new
38
- unit2 = IOWriter.new
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 unit1.run?
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
@@ -27,9 +27,10 @@ class XPoolTest < Test::Unit::TestCase
27
27
 
28
28
  def test_queue
29
29
  @pool.resize! 1..1
30
- subprocesses = Array.new(5) { @pool.schedule Sleeper.new(0.1) }.uniq!
31
- assert_equal 1, subprocesses.size
32
- assert_equal 5, subprocesses[0].frequency
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-18 00:00:00.000000000 Z
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: -372428872314676490
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: -372428872314676490
80
+ hash: 761478267261192258
81
81
  requirements: []
82
82
  rubyforge_project:
83
83
  rubygems_version: 1.8.23