deadly_serious 2.0.0.pre.rc3 → 2.0.0.pre.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deadly_serious/engine/channel/socket/socket_vent_recvr.rb +1 -1
- data/lib/deadly_serious/engine/commands.rb +6 -5
- data/lib/deadly_serious/processes/{converter.rb → identity.rb} +1 -1
- data/lib/deadly_serious/processes/lambda.rb +14 -7
- data/lib/deadly_serious/version.rb +1 -1
- data/spec/lib/deadly_serious/engine/channel/socket_channel_spec.rb +10 -3
- data/spec/lib/deadly_serious/engine/pipeline_spec.rb +2 -2
- metadata +3 -5
- data/lib/deadly_serious/processes/resilient_splitter.rb +0 -34
- data/lib/deadly_serious/processes/splitter.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79958414a4debbba95a15706cede69f4dfce039f
|
4
|
+
data.tar.gz: db4c929449d7ac7b6ae0bf031d22f1fa93155e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 325a5926e3633b2b7a6de58daa669d8c27fad79bb76e547ebcf86bd19f8974a2b8d77f96cbcdd628782bb5305d1b7c4feb15272345912d058959740e8bd103dc
|
7
|
+
data.tar.gz: e9f77696f7feb5f5e088fa6dca2ccddeeba51b99a27cf91deb76280d39dd4386fb3a07ef90951593bbe0a7aed295a4e159e4c9bcfe01fef1d6b50ee71e85653c
|
@@ -39,7 +39,7 @@ module DeadlySerious
|
|
39
39
|
# This is useful after a {#spawn_tee}, sometimes.
|
40
40
|
def from_pipe(pipe_name, writer: next_pipe)
|
41
41
|
pipe = pipe_name.sub(/^>?/, '')
|
42
|
-
spawn_command('cat', readers: [pipe], writers: [writer])
|
42
|
+
spawn_command('cat ((<))', readers: [pipe], writers: [writer])
|
43
43
|
end
|
44
44
|
|
45
45
|
# Write the output of the last component to
|
@@ -59,6 +59,7 @@ module DeadlySerious
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# Spawn a class connected to the last and next components
|
62
|
+
# @deprecated use #spawn
|
62
63
|
def spawn_class(a_class, *args, reader: last_pipe, writer: next_pipe)
|
63
64
|
spawn_process(a_class, *args, readers: [reader], writers: [writer])
|
64
65
|
end
|
@@ -66,7 +67,7 @@ module DeadlySerious
|
|
66
67
|
# Spawn {number_of_processes} classes, one process for each of them.
|
67
68
|
# Also, it divides the previous pipe in {number_of_processes} pipes,
|
68
69
|
# an routes data through them.
|
69
|
-
# @deprecated
|
70
|
+
# @deprecated use #parallel
|
70
71
|
def spawn_class_parallel(number_of_processes, class_name, *args, reader: last_pipe, writer: next_pipe)
|
71
72
|
connect_a = (1..number_of_processes).map { |i| sprintf('%s.%da.splitter', class_name.to_s.downcase.gsub(/\W+/, '_'), i) }
|
72
73
|
connect_b = (1..number_of_processes).map { |i| sprintf('%s.%db.splitter', class_name.to_s.downcase.gsub(/\W+/, '_'), i) }
|
@@ -78,7 +79,7 @@ module DeadlySerious
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def spawn_lambda(name: 'Lambda',reader: last_pipe, writer: next_pipe, &block)
|
81
|
-
|
82
|
+
spawn(DeadlySerious::Processes::Lambda.new(block, name: name), reader: reader, writer: writer)
|
82
83
|
end
|
83
84
|
|
84
85
|
# Pipe from the last component to a intermediate
|
@@ -129,8 +130,8 @@ module DeadlySerious
|
|
129
130
|
output = format('>}localhost:%d', @port)
|
130
131
|
@port += 1
|
131
132
|
|
132
|
-
|
133
|
-
|
133
|
+
spawn_process(Processes::Identity.new, process_name: 'Ventilator', readers: [reader], writers: [ventilator])
|
134
|
+
spawn_process(Processes::Identity.new, process_name: 'Sink', readers: [sink], writers: [writer])
|
134
135
|
on_subnet do
|
135
136
|
number_of_lanes.times { yield input, output }
|
136
137
|
end
|
@@ -1,8 +1,15 @@
|
|
1
1
|
module DeadlySerious
|
2
2
|
module Processes
|
3
3
|
class Lambda
|
4
|
-
|
5
|
-
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(block, name: 'Lambda')
|
7
|
+
@name = name
|
8
|
+
@block = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(readers:, writers:)
|
12
|
+
params = @block.parameters
|
6
13
|
writer_param = params.any? { |(k, n)| k == :keyreq && n == :writer }
|
7
14
|
reader_param = params.any? { |(k, n)| k == :keyreq && n == :reader }
|
8
15
|
|
@@ -13,18 +20,18 @@ module DeadlySerious
|
|
13
20
|
unless reader
|
14
21
|
fail %(Missing "#{readers.first.filename}", did you provide a reader to lambda?)
|
15
22
|
end
|
16
|
-
block.call(reader: reader, writer: writer)
|
23
|
+
@block.call(reader: reader, writer: writer)
|
17
24
|
elsif writer_param && reader
|
18
25
|
reader.each do |data|
|
19
|
-
block.call(*data, writer: writer)
|
26
|
+
@block.call(*data, writer: writer)
|
20
27
|
end
|
21
28
|
elsif writer_param && !reader
|
22
|
-
block.call(writer: writer)
|
29
|
+
@block.call(writer: writer)
|
23
30
|
elsif reader
|
24
31
|
# This is a little "too smarty" for my taste,
|
25
32
|
# however, it's awesomely useful. =\
|
26
33
|
reader.each do |data|
|
27
|
-
result = block.call(*data)
|
34
|
+
result = @block.call(*data)
|
28
35
|
|
29
36
|
# noinspection RubySimplifyBooleanInspection
|
30
37
|
if result == true # really TRUE, not thruthy
|
@@ -39,7 +46,7 @@ module DeadlySerious
|
|
39
46
|
end
|
40
47
|
end
|
41
48
|
else
|
42
|
-
block.call
|
49
|
+
@block.call
|
43
50
|
end
|
44
51
|
end
|
45
52
|
end
|
@@ -142,16 +142,23 @@ describe SocketChannel do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'does load balancing' do
|
145
|
-
send_msg(1, 2, 3)
|
145
|
+
send_msg(1, 2, 3, 4, 5)
|
146
146
|
channel1 = Channel.new("#{rcv}localhost:5555", nil)
|
147
147
|
channel2 = Channel.new("#{rcv}localhost:5555", nil)
|
148
148
|
|
149
149
|
c1 = channel1.each
|
150
150
|
c2 = channel2.each
|
151
151
|
|
152
|
+
# Load balancing is tuned to fast round trip.
|
153
|
+
# That means as soon I get a line, before I
|
154
|
+
# starting process it, I ask for another one.
|
155
|
+
# This optimizes ZMQ, but the message order is
|
156
|
+
# a bit strange, as you can check below:
|
152
157
|
expect(c1.next).to eq '1'
|
153
|
-
expect(c2.next).to eq '
|
154
|
-
expect(c1.next).to eq '
|
158
|
+
expect(c2.next).to eq '3'
|
159
|
+
expect(c1.next).to eq '2'
|
160
|
+
expect(c2.next).to eq '4'
|
161
|
+
expect(c1.next).to eq '5'
|
155
162
|
|
156
163
|
channel1.close
|
157
164
|
channel2.close
|
@@ -137,11 +137,11 @@ describe Pipeline do
|
|
137
137
|
create_file(test_file, (1..10_000).map { |i| [i] })
|
138
138
|
pipeline = Pipeline.new do |p|
|
139
139
|
p.from_file(test_file)
|
140
|
-
p.spawn_process(
|
140
|
+
p.spawn_process(Identity.new, writers: ['>{localhost:5555'])
|
141
141
|
p.spawn_process(TestComponentMultiplier.new(10), readers: ['<{localhost:5555'], writers: ['>}localhost:5556'])
|
142
142
|
p.spawn_process(TestComponentMultiplier.new(100), readers: ['<{localhost:5555'], writers: ['>}localhost:5556'])
|
143
143
|
p.spawn_process(TestComponentMultiplier.new(1000), readers: ['<{localhost:5555'], writers: ['>}localhost:5556'])
|
144
|
-
p.spawn_process(
|
144
|
+
p.spawn_process(Identity.new, readers: ['<}localhost:5556'])
|
145
145
|
p.to_file(result_file)
|
146
146
|
end
|
147
147
|
pipeline.run
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deadly_serious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.
|
4
|
+
version: 2.0.0.pre.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronie Uliana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -155,10 +155,8 @@ files:
|
|
155
155
|
- lib/deadly_serious/engine/pipeline.rb
|
156
156
|
- lib/deadly_serious/engine/ruby_object_container.rb
|
157
157
|
- lib/deadly_serious/engine/so_command_container.rb
|
158
|
-
- lib/deadly_serious/processes/
|
158
|
+
- lib/deadly_serious/processes/identity.rb
|
159
159
|
- lib/deadly_serious/processes/lambda.rb
|
160
|
-
- lib/deadly_serious/processes/resilient_splitter.rb
|
161
|
-
- lib/deadly_serious/processes/splitter.rb
|
162
160
|
- lib/deadly_serious/version.rb
|
163
161
|
- spec/lib/deadly_serious/engine/auto_pipe_spec.rb
|
164
162
|
- spec/lib/deadly_serious/engine/channel/socket_channel_spec.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module DeadlySerious
|
2
|
-
module Processes
|
3
|
-
class ResilientSplitter
|
4
|
-
def initialize
|
5
|
-
@reallocate = false
|
6
|
-
Signal.trap('USR1') do
|
7
|
-
@reallocate = true
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def run(readers: [], writers: [])
|
12
|
-
reader = readers.first
|
13
|
-
outputs = writers.dup
|
14
|
-
current = nil
|
15
|
-
reader.each do |line|
|
16
|
-
begin
|
17
|
-
if @reallocate
|
18
|
-
@reallocate = false
|
19
|
-
outputs = writers.dup
|
20
|
-
end
|
21
|
-
current = outputs.first
|
22
|
-
current << line << "\n"
|
23
|
-
outputs.rotate!
|
24
|
-
rescue Errno::EPIPE => e
|
25
|
-
puts e.inspect
|
26
|
-
outputs.delete(current)
|
27
|
-
raise e if outputs.empty?
|
28
|
-
redo
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module DeadlySerious
|
2
|
-
module Processes
|
3
|
-
class Splitter
|
4
|
-
def initialize
|
5
|
-
Signal.trap('USR1') { @outputs = @writers.dup }
|
6
|
-
end
|
7
|
-
def run(readers: [], writers: [])
|
8
|
-
@writers ||= writers
|
9
|
-
reader = readers.first
|
10
|
-
@outputs = @writers.dup
|
11
|
-
begin
|
12
|
-
reader.each do |line|
|
13
|
-
@current = @outputs.first
|
14
|
-
@current << line
|
15
|
-
@outputs.rotate!
|
16
|
-
end
|
17
|
-
rescue => e
|
18
|
-
puts e.inspect
|
19
|
-
@outputs.delete(@current)
|
20
|
-
raise e if @outputs.empty?
|
21
|
-
retry
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|