rodimus 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b41faf166609c0301fa56b7b675f3be73b4a986d
4
- data.tar.gz: dd8f0d1d9a73cb73c38dfea42e448cf36ab926ec
3
+ metadata.gz: 3db99d55f80c320e1e3502b90562d8c2791e4f21
4
+ data.tar.gz: 422f9092d2a028d66d1465665310e664077ee082
5
5
  SHA512:
6
- metadata.gz: cdf745cb5fb1645602df330d5f32dc1121932c288ea1ddc8e4b8e40095ad7a1a6928b69272688a61089a6a356a2e439846c35e8abbac90700d159664a137213a
7
- data.tar.gz: f7830584a6e02a39a3b82ebcd680762ff415ae7a971e832f5a5c805cf560a4b6a3f66179a50c4c2a27bc4a8d3374290dc2f1413993e5406bcda5ed7c44d00d59
6
+ metadata.gz: 483942b6d0d61c3904d03a8944492353f2e1702448639ac0b21cbf76637e5f111d7a37b3cd871bbd744f78544e5b3b0d6394580e2a157444e913cb6133b91953
7
+ data.tar.gz: 0fdfb929397cd4fb8db4a1cd038eb73b11e13e6367356ec284973893f9945aa7ce076bb87f6ef0b30ecc3d3006091897a0825f6c631fbaf3b8d1f8f759398d9c
data/.travis.yml CHANGED
@@ -4,3 +4,5 @@ rvm:
4
4
  - 2.0.0
5
5
  - 1.9.3
6
6
  - 1.9.2
7
+ - jruby-19mode
8
+ - rbx-2
data/README.md CHANGED
@@ -38,11 +38,12 @@ destination.
38
38
  In Rodimus, you create a transformation object, and then you add
39
39
  one or more steps to its array of steps. You typically create steps by writing
40
40
  your own classes that inherit from Rodimus::Step. When the transformation is
41
- subsequently run, a new process is forked for each step. All processes are
42
- connected together using pipes except for the first and last steps (those being the
43
- source and destination steps). Each step then consumes rows of data from its
44
- incoming pipe and performs some operation on it before writing it to the
45
- outgoing pipe.
41
+ subsequently run, a new process is forked for each step. On steps that support
42
+ native threads (JRuby, Rubinius), threads are used instead of forking processes.
43
+ All processes are connected together using pipes except for the first and last
44
+ steps (those being the source and destination steps). Each step then consumes
45
+ rows of data from its incoming pipe and performs some operation on it before
46
+ writing it to the outgoing pipe.
46
47
 
47
48
  There are several methods on the Rodimus::Step class that are able to be
48
49
  overridden for custom processing behavior before, during, or after the each
data/lib/rodimus.rb CHANGED
@@ -8,8 +8,6 @@ require 'rodimus/transformation'
8
8
  require 'rodimus/version'
9
9
 
10
10
  module Rodimus
11
- $SAFE = 1 # Because we're using DRb
12
-
13
11
  class << self
14
12
  attr_accessor :configuration
15
13
  end
@@ -22,4 +20,8 @@ module Rodimus
22
20
  def self.logger
23
21
  configuration.logger
24
22
  end
23
+
24
+ unless Rodimus.configuration.use_threads
25
+ $SAFE = 1 # Because we're using DRb
26
+ end
25
27
  end
@@ -3,11 +3,19 @@ require 'logger'
3
3
  module Rodimus
4
4
 
5
5
  class Configuration
6
- attr_accessor :logger, :benchmarking
6
+ attr_accessor :logger
7
+
8
+ # Set to true for extra output with step performance details
9
+ attr_accessor :benchmarking
10
+
11
+ # Use threads for concurrency instead of forking processes.
12
+ # Automatically set to true for JRuby and Rubinius
13
+ attr_accessor :use_threads
7
14
 
8
15
  def initialize
9
16
  @logger = Logger.new(STDOUT)
10
17
  @benchmarking = false
18
+ @use_threads = ['jruby', 'rbx'].include?(RUBY_ENGINE)
11
19
  end
12
20
  end
13
21
 
@@ -7,35 +7,37 @@ module Rodimus
7
7
  include Observing # Transformations observe themselves for run hooks
8
8
  include RuntimeLogging
9
9
 
10
- attr_reader :drb_server, :pids, :steps
10
+ attr_reader :drb_server, :steps
11
+
12
+ # Contains the thread or process identifiers currently in use
13
+ attr_reader :ids
11
14
 
12
15
  # User-data accessible across all running steps.
13
16
  attr_reader :shared_data
14
17
 
15
18
  def initialize
16
19
  @steps = []
17
- @pids = []
20
+ @ids = []
18
21
  @shared_data = {} # TODO: This needs to be thread safe
19
22
  observers << self
20
23
  end
21
24
 
25
+ # Run the transformation
22
26
  def run
23
27
  notify(self, :before_run)
24
- @drb_server = DRb.start_service(nil, shared_data)
25
- pids.clear
28
+ @drb_server = DRb.start_service(nil, shared_data) unless using_threads?
29
+ ids.clear
26
30
  prepare
27
31
 
28
32
  steps.each do |step|
29
- pids << fork do
30
- DRb.start_service # the parent DRb thread dies across the fork
31
- step.shared_data = DRbObject.new_with_uri(drb_server.uri)
33
+ ids << in_parallel do
34
+ step.shared_data = step_shared_data
32
35
  step.run
33
36
  end
34
- step.close_descriptors
37
+ step.close_descriptors unless using_threads?
35
38
  end
36
39
  ensure
37
- Process.waitall
38
- drb_server.stop_service
40
+ cleanup
39
41
  notify(self, :after_run)
40
42
  end
41
43
 
@@ -45,6 +47,23 @@ module Rodimus
45
47
 
46
48
  private
47
49
 
50
+ def cleanup
51
+ if using_threads?
52
+ ids.each { |t| t.join }
53
+ else
54
+ Process.waitall
55
+ drb_server.stop_service
56
+ end
57
+ end
58
+
59
+ def in_parallel
60
+ if using_threads?
61
+ Thread.start { yield }
62
+ else
63
+ fork { yield }
64
+ end
65
+ end
66
+
48
67
  def prepare
49
68
  # [1, 2, 3, 4] => [1, 2], [2, 3], [3, 4]
50
69
  steps.inject do |first, second|
@@ -54,6 +73,19 @@ module Rodimus
54
73
  second
55
74
  end
56
75
  end
76
+
77
+ def step_shared_data
78
+ if using_threads?
79
+ shared_data
80
+ else
81
+ DRb.start_service # service dies across forked process
82
+ DRbObject.new_with_uri(drb_server.uri)
83
+ end
84
+ end
85
+
86
+ def using_threads?
87
+ Rodimus.configuration.use_threads
88
+ end
57
89
  end
58
90
 
59
91
  end
@@ -1,3 +1,3 @@
1
1
  module Rodimus
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -8,7 +8,7 @@ module Rodimus
8
8
  config.logger = Logger.new(nil)
9
9
  end
10
10
 
11
- def test_forking_processes
11
+ def test_parallel_steps
12
12
  incoming = StringIO.new
13
13
  transformation = Transformation.new
14
14
  number_of_steps = 2 + rand(5)
@@ -17,7 +17,7 @@ module Rodimus
17
17
  end
18
18
  transformation.steps.first.incoming = incoming
19
19
  transformation.run
20
- assert_equal(transformation.steps.count, transformation.pids.count)
20
+ assert_equal(transformation.steps.count, transformation.ids.count)
21
21
  end
22
22
  end
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodimus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Rice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler