pmux 0.1.0
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/.gitignore +8 -0
- data/README.md +36 -0
- data/Rakefile +4 -0
- data/bin/pmux +5 -0
- data/lib/pmux/application.rb +166 -0
- data/lib/pmux/cleaner.rb +28 -0
- data/lib/pmux/fiber18.rb +64 -0
- data/lib/pmux/fixcmd.rb +25 -0
- data/lib/pmux/gatherer.rb +23 -0
- data/lib/pmux/handler.rb +262 -0
- data/lib/pmux/job.rb +101 -0
- data/lib/pmux/joblogger.rb +46 -0
- data/lib/pmux/mapper.rb +151 -0
- data/lib/pmux/mros.rb +207 -0
- data/lib/pmux/multi_session.rb +309 -0
- data/lib/pmux/pipeio.rb +19 -0
- data/lib/pmux/plugin.rb +23 -0
- data/lib/pmux/q.rb +3 -0
- data/lib/pmux/reducer.rb +90 -0
- data/lib/pmux/storage_adapter.rb +105 -0
- data/lib/pmux/task_dispatcher.rb +167 -0
- data/lib/pmux/task_queue.rb +11 -0
- data/lib/pmux/task_scheduler.rb +166 -0
- data/lib/pmux/util_daemon.rb +18 -0
- data/lib/pmux/util_logger.rb +137 -0
- data/lib/pmux/version.rb +3 -0
- data/lib/pmux/worker.rb +91 -0
- data/lib/pmux/writer.rb +19 -0
- data/lib/pmux.rb +27 -0
- data/pmux.gemspec +24 -0
- data/test/mock_mros.rb +284 -0
- data/test/mock_pipeio.rb +26 -0
- data/test/mock_world.rb +193 -0
- data/test/mock_xattr.rb +10 -0
- data/test/runner.rb +10 -0
- data/test/test_application.rb +13 -0
- data/test/test_fixcmd.rb +17 -0
- data/test/test_handler.rb +15 -0
- data/test/test_i_mapreduce.rb +169 -0
- data/test/test_i_mros.rb +28 -0
- data/test/test_i_msession.rb +27 -0
- data/test/test_job.rb +35 -0
- data/test/test_joblogger.rb +16 -0
- data/test/test_mapper.rb +60 -0
- data/test/test_pipeio.rb +24 -0
- data/test/test_storage_adapter.rb +63 -0
- data/test/test_task_queue.rb +87 -0
- data/test/test_task_scheduler.rb +39 -0
- data/test/txt/0.log +105 -0
- data/test/txt/1.log +105 -0
- data/test/txt/2.log +105 -0
- data/test/txt/3.log +105 -0
- data/test/txt/4.log +105 -0
- data/test/txt/5.log +105 -0
- data/test/txt/6.log +105 -0
- data/test/txt/7.log +105 -0
- data/test/txt/8.log +105 -0
- data/test/unittest_helper.rb +57 -0
- metadata +153 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
require 'mock_world'
|
6
|
+
require 'mock_mros'
|
7
|
+
require 'mock_pipeio'
|
8
|
+
|
9
|
+
Log.open('-') if __FILE__ == $0 and $show_log
|
10
|
+
|
11
|
+
class MockWorker < Pmux::Worker
|
12
|
+
def run
|
13
|
+
while true
|
14
|
+
future = @client.call_async :get_task
|
15
|
+
future.attach_callback {|f|
|
16
|
+
task = f.get
|
17
|
+
result = exec_task task
|
18
|
+
res = @client.call :put_result, result
|
19
|
+
}
|
20
|
+
Fiber.yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class MockHandler < Pmux::Handler
|
26
|
+
def fork_worker num_cpu, options
|
27
|
+
world = @server.loop.world
|
28
|
+
stransport = @server.listeners.detect {|c| c.kind_of? MR::MockTransport}
|
29
|
+
ctransport = world.new_connection MR::MockTransport
|
30
|
+
ctransport.mock_receiver = stransport
|
31
|
+
stransport.mock_receiver = ctransport
|
32
|
+
client = MR::Client.new ctransport, 'dummy', @server.loop
|
33
|
+
worker = MockWorker.new options, client
|
34
|
+
@fiber = Fiber.new {
|
35
|
+
worker.run
|
36
|
+
}
|
37
|
+
@fiber.resume
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class MockWriter < Pmux::Writer
|
42
|
+
attr_reader :lines
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@lines = []
|
46
|
+
end
|
47
|
+
|
48
|
+
def write path
|
49
|
+
@lines += File.readlines path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Pmux::Cleaner
|
54
|
+
def run lim_time=nil
|
55
|
+
lim_time = Time.now - 3600
|
56
|
+
clean @glob_pat, lim_time
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class TestIMapreduce < Test::Unit::TestCase
|
61
|
+
# gflocatorを生成し、そのサーバへのconnection(socket)を返す
|
62
|
+
def setup_gflocator world, host, port
|
63
|
+
#handler = GFL::Handler.new
|
64
|
+
#server = MRIO::MockServer.start world, host, port, handler
|
65
|
+
#c = MockTCPSocket.new host, port
|
66
|
+
end
|
67
|
+
|
68
|
+
def setup_world root_dir
|
69
|
+
MockWorld.cleanup root_dir
|
70
|
+
world = MockWorld.new
|
71
|
+
Coolio::Loop.default.world = world
|
72
|
+
Net::SSH::MockChannel.handler_class = MockHandler
|
73
|
+
world
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup_task_dispatcher addrs, options, files, writer=nil
|
77
|
+
setup_world options[:root_dir]
|
78
|
+
FileUtils.mkdir_p options[:tmp_dir]
|
79
|
+
sn = options[:storage_name] || 'local'
|
80
|
+
adapter = Pmux::StorageAdapter.create sn, addrs
|
81
|
+
msession = Pmux::MRSession.new addrs, options
|
82
|
+
msession.connect
|
83
|
+
gatherer = Pmux::Gatherer.new(writer || MockWriter.new)
|
84
|
+
dispatcher = Pmux::TaskDispatcher.new options, adapter, msession, gatherer
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_show_status
|
88
|
+
end
|
89
|
+
|
90
|
+
# mr test; num_r=0, 4 files
|
91
|
+
def test_run_mr0
|
92
|
+
root_dir = "#{$test_dir}/.t"
|
93
|
+
|
94
|
+
# 2 nodes, 4 files
|
95
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
96
|
+
options = {:root_dir=>root_dir, :tmp_dir=>(root_dir + '/localhost'),
|
97
|
+
:mapper=>'cat'}
|
98
|
+
files = Dir.glob($test_dir + '/txt/[0-3].log')
|
99
|
+
writer = MockWriter.new
|
100
|
+
dispatcher = setup_task_dispatcher addrs, options, files, writer
|
101
|
+
job = Pmux::Job.new options, files
|
102
|
+
dispatcher.run job
|
103
|
+
ae 420, writer.lines.size
|
104
|
+
end
|
105
|
+
|
106
|
+
# mr test; num_r=1, 4 files
|
107
|
+
def test_run_mr1
|
108
|
+
root_dir = "#{$test_dir}/.t"
|
109
|
+
world = setup_world root_dir
|
110
|
+
|
111
|
+
# 2 nodes, 4 files, 2 reducers
|
112
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
113
|
+
options = {:root_dir=>root_dir, :tmp_dir=>(root_dir + '/localhost'),
|
114
|
+
:mapper=>'cat', :num_r=>1}
|
115
|
+
files = Dir.glob($test_dir + '/txt/[0-3].log')
|
116
|
+
writer = MockWriter.new
|
117
|
+
dispatcher = setup_task_dispatcher addrs, options, files, writer
|
118
|
+
job = Pmux::Job.new options, files
|
119
|
+
job.mk_reducer_addrs addrs
|
120
|
+
dispatcher.run job
|
121
|
+
ae 420, writer.lines.size
|
122
|
+
end
|
123
|
+
|
124
|
+
# mr test; num_r=2, 4 files
|
125
|
+
def test_run_mr2
|
126
|
+
root_dir = "#{$test_dir}/.t"
|
127
|
+
world = setup_world root_dir
|
128
|
+
|
129
|
+
# 2 nodes, 4 files, 2 reducers
|
130
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
131
|
+
options = {:root_dir=>root_dir, :tmp_dir=>(root_dir + '/localhost'),
|
132
|
+
:mapper=>'cat', :num_r=>2, :separator=>' '}
|
133
|
+
files = Dir.glob($test_dir + '/txt/[0-3].log')
|
134
|
+
writer = MockWriter.new
|
135
|
+
dispatcher = setup_task_dispatcher addrs, options, files, writer
|
136
|
+
job = Pmux::Job.new options, files
|
137
|
+
job.mk_reducer_addrs addrs
|
138
|
+
dispatcher.run job
|
139
|
+
ae 420, writer.lines.size
|
140
|
+
|
141
|
+
# error check
|
142
|
+
files.push '/notexist'
|
143
|
+
writer = MockWriter.new
|
144
|
+
dispatcher = setup_task_dispatcher addrs, options, files, writer
|
145
|
+
er = nil
|
146
|
+
dispatcher.on_error {|r| er = r}
|
147
|
+
job = Pmux::Job.new options, files
|
148
|
+
job.mk_reducer_addrs addrs
|
149
|
+
dispatcher.run job
|
150
|
+
assert_match %r{/notexist: No such file or directory}, er['error_message']
|
151
|
+
ae 420, writer.lines.size
|
152
|
+
end
|
153
|
+
|
154
|
+
# mr test; num_r=0, 4 files, ff=2
|
155
|
+
def test_run_mr_f
|
156
|
+
root_dir = "#{$test_dir}/.t"
|
157
|
+
|
158
|
+
# 2 nodes, 9 files, ff=2
|
159
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
160
|
+
options = {:root_dir=>root_dir, :tmp_dir=>(root_dir + '/localhost'),
|
161
|
+
:mapper=>'cat', :ff=>2}
|
162
|
+
files = Dir.glob($test_dir + '/txt/*.log')
|
163
|
+
writer = MockWriter.new
|
164
|
+
dispatcher = setup_task_dispatcher addrs, options, files, writer
|
165
|
+
job = Pmux::Job.new options, files
|
166
|
+
dispatcher.run job
|
167
|
+
ae 945, writer.lines.size
|
168
|
+
end
|
169
|
+
end
|
data/test/test_i_mros.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'mock_world'
|
4
|
+
require 'mock_mros'
|
5
|
+
|
6
|
+
class TestIMros < Test::Unit::TestCase
|
7
|
+
def test_server
|
8
|
+
world = MockWorld.new
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
server = MR::Server.new
|
12
|
+
handler = Pmux::Handler.new server, options
|
13
|
+
transport = MR::MockPipeTransport.new
|
14
|
+
server.listen transport, handler
|
15
|
+
server.run
|
16
|
+
|
17
|
+
# get_status handler test
|
18
|
+
bin = [0, 0, 'get_status', []].to_msgpack
|
19
|
+
transport.receive_data bin
|
20
|
+
msg = MessagePack.unpack transport.data
|
21
|
+
# [1, 0, nil, [['key', value, :type], [], ...]
|
22
|
+
|
23
|
+
ae 1, msg[0]
|
24
|
+
ae 0, msg[1]
|
25
|
+
assert_nil msg[2]
|
26
|
+
assert_kind_of Array, msg[3]
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'mock_world'
|
4
|
+
require 'mock_mros'
|
5
|
+
|
6
|
+
class TestIMultiSession < Test::Unit::TestCase
|
7
|
+
def setup_loop
|
8
|
+
loop = Coolio::MockLoop.new
|
9
|
+
loop.world = MockWorld.new
|
10
|
+
loop
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_mr_multicast_call_async
|
14
|
+
loop = setup_loop
|
15
|
+
msession = Pmux::MRSession.new ['192.168.0.1', '192.168.0.2'], {}, loop
|
16
|
+
msession.connect
|
17
|
+
|
18
|
+
mf = msession.multicast_call_async :get_properties
|
19
|
+
mf.join_all
|
20
|
+
mf.all.each {|f|
|
21
|
+
assert_match /^192\.168\.0\.\d+$/, f.addr
|
22
|
+
res = f.get
|
23
|
+
assert_kind_of Hash, res
|
24
|
+
ae RUBY_VERSION, res['RUBY_VERSION']
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
data/test/test_job.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
class TestJob < Test::Unit::TestCase
|
4
|
+
def test_job_id
|
5
|
+
job = Pmux::Job.new({}, [])
|
6
|
+
assert_match /^\d+$/, job.id
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_mk_tasks
|
10
|
+
files = ['/tmp/f1', '/tmp/f2', '/tmp/f3']
|
11
|
+
params = {}
|
12
|
+
job = Pmux::Job.new params, files
|
13
|
+
ae files.size, job.tasks.size
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_mk_reducer_addrs
|
17
|
+
job = Pmux::Job.new({}, [])
|
18
|
+
|
19
|
+
# 1 node
|
20
|
+
addrs = ['192.168.0.1']
|
21
|
+
res = job.mk_reducer_addrs addrs, 1
|
22
|
+
ae ['192.168.0.1'], res
|
23
|
+
res = job.mk_reducer_addrs addrs, 3
|
24
|
+
ae ['192.168.0.1', '192.168.0.1', '192.168.0.1'], res
|
25
|
+
|
26
|
+
# 4 nodes
|
27
|
+
addrs = ['192.168.0.1', '192.168.0.2', '192.168.0.3', '192.168.0.4']
|
28
|
+
res = job.mk_reducer_addrs addrs, 1
|
29
|
+
ae ['192.168.0.1'], res
|
30
|
+
res = job.mk_reducer_addrs addrs, 2
|
31
|
+
ae ['192.168.0.1', '192.168.0.3'], res
|
32
|
+
res = job.mk_reducer_addrs addrs, 3
|
33
|
+
ae ['192.168.0.1', '192.168.0.2', '192.168.0.3'], res
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
class TestJoblogger < Test::Unit::TestCase
|
4
|
+
def test_j
|
5
|
+
jl = Pmux::Joblogger.new nil, nil
|
6
|
+
assert_nil jl.path
|
7
|
+
|
8
|
+
job = Pmux::Job.new({:job_name=>'unknown'}, [])
|
9
|
+
jl = Pmux::Joblogger.new '/var/tmp', job
|
10
|
+
jl.dump job.to_jlheader
|
11
|
+
assert_match %r{/var/tmp/\d+\.yml}, jl.path
|
12
|
+
jl.close
|
13
|
+
assert File.size?(jl.path)
|
14
|
+
File.unlink jl.path
|
15
|
+
end
|
16
|
+
end
|
data/test/test_mapper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class TestMapper < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@tmp_dir = $test_dir + '/.t'
|
8
|
+
FileUtils.mkdir_p @tmp_dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_r0_r1
|
12
|
+
task = {'task_id'=>1, 'mapper'=>'cat', 'path'=>"#{$test_dir}/txt/0.log"}
|
13
|
+
size = File.size task['path']
|
14
|
+
|
15
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
16
|
+
ifbase = mapper.do_map_task
|
17
|
+
ae size, File.size(ifbase+'-0')
|
18
|
+
ae 0, mapper.exitstatus
|
19
|
+
|
20
|
+
task['task_id'] = 2
|
21
|
+
task['num_r'] = 1
|
22
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
23
|
+
ifbase = mapper.do_map_task
|
24
|
+
ae size, File.size(ifbase+'-0')
|
25
|
+
ae 0, mapper.exitstatus
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_r2
|
29
|
+
task = {'task_id'=>1, 'mapper'=>'cat', 'path'=>"#{$test_dir}/txt/0.log"}
|
30
|
+
size = File.size task['path']
|
31
|
+
|
32
|
+
task['num_r'] = 2
|
33
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
34
|
+
ifbase = mapper.do_map_task
|
35
|
+
ae size, File.size(ifbase+'-0') + File.size(ifbase+'-1')
|
36
|
+
ae 0, mapper.exitstatus
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_err
|
40
|
+
task = {'task_id'=>1, 'mapper'=>'cat', 'path'=>"notexist"}
|
41
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
42
|
+
assert_raise(RuntimeError) {
|
43
|
+
ifbase = mapper.do_map_task
|
44
|
+
}
|
45
|
+
assert(mapper.exitstatus > 0)
|
46
|
+
|
47
|
+
task['mapper'] = 'notexist'
|
48
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
49
|
+
assert_raise(RuntimeError) {
|
50
|
+
ifbase = mapper.do_map_task
|
51
|
+
}
|
52
|
+
|
53
|
+
task['mapper'] = 'ruby -e "undefinedmethod()"'
|
54
|
+
mapper = Pmux::StreamingMapper.new task, @tmp_dir
|
55
|
+
assert_raise(RuntimeError) {
|
56
|
+
ifbase = mapper.do_map_task
|
57
|
+
}
|
58
|
+
assert(mapper.exitstatus > 0)
|
59
|
+
end
|
60
|
+
end
|
data/test/test_pipeio.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
require 'mock_pipeio'
|
3
|
+
|
4
|
+
class TestPipeio < Test::Unit::TestCase
|
5
|
+
def test_pipeio
|
6
|
+
loop = Coolio::MockLoop.new
|
7
|
+
loop.world = MockWorld.new
|
8
|
+
|
9
|
+
cmd = "cat #{$test_dir}/txt/0.log"
|
10
|
+
pipeio = Pmux::PipeIO.new cmd
|
11
|
+
loop.attach pipeio
|
12
|
+
str = nil
|
13
|
+
pipeio.on_receive {|data|
|
14
|
+
str = data
|
15
|
+
}
|
16
|
+
closed = false
|
17
|
+
pipeio.on_close {closed = true}
|
18
|
+
loop.world.run_once
|
19
|
+
assert_match /START: \w+ /, str
|
20
|
+
while !closed
|
21
|
+
loop.world.run_once
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
class TestStorageAdapter < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_create
|
8
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
9
|
+
|
10
|
+
adapter = Pmux::StorageAdapter.create 'local', addrs
|
11
|
+
assert_kind_of Pmux::LocalAdapter, adapter
|
12
|
+
ae addrs, adapter.addrs
|
13
|
+
assert_kind_of Hash, adapter['192.168.0.1']
|
14
|
+
assert adapter['192.168.0.1'].empty?
|
15
|
+
|
16
|
+
adapter = Pmux::StorageAdapter.create 'glusterfs', []
|
17
|
+
assert_kind_of Pmux::GlusterFSAdapter, adapter
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_local
|
21
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
22
|
+
adapter = Pmux::StorageAdapter.create 'local', addrs
|
23
|
+
|
24
|
+
args = ['/tmp/0.log', '/tmp/1.log', '/tmp/2.log', '/tmp/3.log']
|
25
|
+
files = adapter.get_files args
|
26
|
+
ae args.size, files.size
|
27
|
+
|
28
|
+
args = ["#{$test_dir}/txt/*.log"]
|
29
|
+
files = adapter.get_files args
|
30
|
+
ae args.size, files.size
|
31
|
+
|
32
|
+
files = ["#{$test_dir}/txt/*.log"]
|
33
|
+
files = adapter.get_files args, true
|
34
|
+
ae 9, files.size
|
35
|
+
end
|
36
|
+
|
37
|
+
def _test_pmuxfs
|
38
|
+
addrs = ['192.168.0.1', '192.168.0.2']
|
39
|
+
adapter = Pmux::StorageAdapter.create 'pmuxfs', addrs
|
40
|
+
|
41
|
+
# pmuxfs find test
|
42
|
+
adapter.scan_unit = 5
|
43
|
+
adapter.set_fs_dir "#{$test_dir}/txt"
|
44
|
+
res = adapter.find
|
45
|
+
ae 5, res.size
|
46
|
+
until (res = adapter.find).empty?; end
|
47
|
+
end
|
48
|
+
|
49
|
+
def _test_pmux_node_table
|
50
|
+
addrs = ['192.168.0.1', '192.168.0.2', '192.168.0.3']#, '192.168.0.4']
|
51
|
+
nt = Pmux::PmuxNodeTable.new
|
52
|
+
addrs.each {|addr| nt.push_node addr}
|
53
|
+
nt.reposition
|
54
|
+
|
55
|
+
counts = Hash.new 0
|
56
|
+
for i in 1..1000
|
57
|
+
s = i.to_s
|
58
|
+
h = Digest::SHA1.digest(s)
|
59
|
+
node_addr, = nt.lookup h
|
60
|
+
counts[node_addr] += 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
class TestTaskQueue < Test::Unit::TestCase
|
4
|
+
def test_task_queue
|
5
|
+
tq = Pmux::TaskQueue.new
|
6
|
+
|
7
|
+
# push
|
8
|
+
v = {:id=>0}
|
9
|
+
tq.push(v)
|
10
|
+
tq.push({:id=>1})
|
11
|
+
tq.push({:id=>2, :job_id=>99})
|
12
|
+
ae 3, tq.size
|
13
|
+
|
14
|
+
ae 2, tq.at(2)[:id]
|
15
|
+
assert_nil tq.at(3)
|
16
|
+
|
17
|
+
# inject_tasks, shift, delete_job
|
18
|
+
tq.inject_tasks [{:id=>3}, {:id=>4}, {:id=>5}, {:id=>6}, {:id=>7}]
|
19
|
+
#tq.each {|v| p v}
|
20
|
+
ae 8, tq.size
|
21
|
+
a = tq.shift
|
22
|
+
ae 0, a[:id]
|
23
|
+
ae 7, tq.size
|
24
|
+
a = tq.shift
|
25
|
+
ae 1, a[:id] # ae 3, a[:id]
|
26
|
+
ae 6, tq.size
|
27
|
+
tq.delete_job 99
|
28
|
+
ae 5, tq.size
|
29
|
+
|
30
|
+
# clear
|
31
|
+
tq.clear
|
32
|
+
ae 0, tq.size
|
33
|
+
|
34
|
+
# inject, shift
|
35
|
+
tasks = (0..9).map {|i|{:id=>i, :job_id=>99}}
|
36
|
+
tq.inject_tasks tasks
|
37
|
+
tmpq = Pmux::TaskQueue.new
|
38
|
+
while item = tq.shift
|
39
|
+
if item[:id] % 2 == 0
|
40
|
+
item.delete :_f #XXX
|
41
|
+
tmpq.push item
|
42
|
+
end
|
43
|
+
break if item[:id] == 6
|
44
|
+
end
|
45
|
+
|
46
|
+
# delete
|
47
|
+
tq.delete_job 99
|
48
|
+
ae 0, tq.size
|
49
|
+
|
50
|
+
# clear, inject
|
51
|
+
tmpq.clear
|
52
|
+
tmpq.inject_tasks [{:id=>0}, {:id=>1}]
|
53
|
+
ae 2, tmpq.size
|
54
|
+
end
|
55
|
+
|
56
|
+
# inject_tasks ĎņŹň
|
57
|
+
def test_inject_tasks
|
58
|
+
tq = Pmux::TaskQueue.new
|
59
|
+
ae 0, tq.size
|
60
|
+
|
61
|
+
tasks = []
|
62
|
+
tq.inject_tasks tasks
|
63
|
+
ae 0, tq.size
|
64
|
+
|
65
|
+
tasks = [{:id=>0}, {:id=>1}]
|
66
|
+
tq.inject_tasks tasks
|
67
|
+
ae 2, tq.size
|
68
|
+
ae 0, tq.at(0)[:id]
|
69
|
+
ae 1, tq.at(1)[:id]
|
70
|
+
|
71
|
+
tasks = [{:id=>2, :mapper_class=>true}, {:id=>3}, {:id=>4}]
|
72
|
+
tq.inject_tasks tasks
|
73
|
+
ae 5, tq.size
|
74
|
+
# TaskQueue#inject_tasks
|
75
|
+
ae 0, tq.at(0)[:id]
|
76
|
+
ae 1, tq.at(1)[:id]
|
77
|
+
ae 2, tq.at(2)[:id]
|
78
|
+
ae 3, tq.at(3)[:id]
|
79
|
+
ae 4, tq.at(4)[:id]
|
80
|
+
|
81
|
+
tasks = (5..6).map {|i|{:id=>i}}
|
82
|
+
tq.inject_tasks tasks
|
83
|
+
ae 7, tq.size
|
84
|
+
tasks = (7..14).map {|i|{:id=>i}}
|
85
|
+
tq.inject_tasks tasks
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
class TestTaskScheduler < Test::Unit::TestCase
|
4
|
+
def test_map_task
|
5
|
+
addrs = ['192.168.0.1', '192.168.0.2', '192.168.0.3',]
|
6
|
+
adapter = Pmux::StorageAdapter.create 'local', addrs
|
7
|
+
files = ['/tmp/f1', '/tmp/f2', '/tmp/f3', '/tmp/f4',]
|
8
|
+
job = Pmux::Job.new({}, files)
|
9
|
+
sch = Pmux::TaskScheduler.new adapter
|
10
|
+
sent_tasks = {}
|
11
|
+
sch.attach_flush_callback {|node_addr, task|
|
12
|
+
(sent_tasks[node_addr] ||= []).push task[:task_id]
|
13
|
+
}
|
14
|
+
addrs.each {|addr| sch.shipped[addr] = true}
|
15
|
+
sch.push_job job
|
16
|
+
sch.process_queue
|
17
|
+
ae [1, 4], sent_tasks['192.168.0.1']
|
18
|
+
ae [2], sent_tasks['192.168.0.2']
|
19
|
+
ae [3], sent_tasks['192.168.0.3']
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_task_fusion
|
23
|
+
addrs = ['192.168.0.1', '192.168.0.2', '192.168.0.3',]
|
24
|
+
adapter = Pmux::StorageAdapter.create 'local', addrs
|
25
|
+
files = (0..8).map {|n| "txt/#{n}.log"}
|
26
|
+
job = Pmux::Job.new({:ff=>3}, files)
|
27
|
+
sch = Pmux::TaskScheduler.new adapter
|
28
|
+
sent_tasks = {}
|
29
|
+
sch.attach_flush_callback {|node_addr, task|
|
30
|
+
(sent_tasks[node_addr] ||= []).push task[:task_id]
|
31
|
+
}
|
32
|
+
addrs.each {|addr| sch.shipped[addr] = true}
|
33
|
+
sch.push_job job
|
34
|
+
sch.process_queue
|
35
|
+
ae [1], sent_tasks['192.168.0.1']
|
36
|
+
ae [2], sent_tasks['192.168.0.2']
|
37
|
+
ae [3], sent_tasks['192.168.0.3']
|
38
|
+
end
|
39
|
+
end
|
data/test/txt/0.log
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
2000-12-31 21:01:01 START: foobarorController (pid 7904)
|
2
|
+
2000-12-31 21:01:01 lock_path: "/tmp/zzzfoobaror-lock" (pid 7904)
|
3
|
+
2000-12-31 21:01:01 sock_path: "/tmp/.foobarorsock.7904"
|
4
|
+
2000-12-31 21:01:02 #1: (7906) start
|
5
|
+
2000-12-31 21:01:02 foobar unknown iiiiiiiiii.example.com
|
6
|
+
2000-12-31 21:01:02 #2: (7907) start
|
7
|
+
2000-12-31 21:01:02 foobar unknown ssssssssss.example.com
|
8
|
+
2000-12-31 21:01:02 #3: (7908) start
|
9
|
+
2000-12-31 21:01:02 foobar unknown pppppppppp.example.com
|
10
|
+
2000-12-31 21:01:02 #4: (7909) start
|
11
|
+
2000-12-31 21:01:02 foobar unknown kkkkkkkkkk.example.com
|
12
|
+
2000-12-31 21:01:02 #5: (7910) start
|
13
|
+
2000-12-31 21:01:02 foobar unknown qqqqqqqqqq.example.com
|
14
|
+
2000-12-31 21:01:02 #6: (7911) start
|
15
|
+
2000-12-31 21:01:02 foobar unknown pppppppppp.example.com
|
16
|
+
2000-12-31 21:01:02 #7: (7912) start
|
17
|
+
2000-12-31 21:01:02 foobar unknown hhhhhhhhhh.example.com
|
18
|
+
2000-12-31 21:01:02 #8: (7913) start
|
19
|
+
2000-12-31 21:01:02 foobar unknown llllllllll.example.com
|
20
|
+
2000-12-31 21:01:03 foobar unknown kkkkkkkkkk.example.com
|
21
|
+
2000-12-31 21:01:03 #9: (7914) start
|
22
|
+
2000-12-31 21:01:03 foobar unknown qqqqqqqqqq.example.com
|
23
|
+
2000-12-31 21:01:03 #10: (7915) start
|
24
|
+
2000-12-31 21:01:03 foobar unknown iiiiiiiiii.example.com
|
25
|
+
2000-12-31 21:01:03 foobar unknown llllllllll.example.com
|
26
|
+
2000-12-31 21:01:03 foobar unknown router1.example.jp
|
27
|
+
2000-12-31 21:01:04 foobar unknown router0.example.jp
|
28
|
+
2000-12-31 21:01:04 #4: (7909) end
|
29
|
+
2000-12-31 21:01:04 #3: (7908) end
|
30
|
+
2000-12-31 21:01:04 #1: (7906) end
|
31
|
+
2000-12-31 21:01:04 #10: (7915) end
|
32
|
+
2000-12-31 21:01:04 #9: (7914) end
|
33
|
+
2000-12-31 21:01:05 #5: (7910) end
|
34
|
+
2000-12-31 21:01:05 #2: (7907) end
|
35
|
+
2000-12-31 21:01:05 #7: (7912) end
|
36
|
+
2000-12-31 21:01:05 #8: (7913) end
|
37
|
+
2000-12-31 21:01:06 #6: (7911) end
|
38
|
+
2000-12-31 21:01:06 waiting children, done (pid 7904)
|
39
|
+
2000-12-31 21:01:06 foobar unknown: elapsed 1.222222 sec
|
40
|
+
2000-12-31 21:01:06 sock_path: "/tmp/.foobarorsock.7904"
|
41
|
+
2000-12-31 21:01:07 #1: (7916) start
|
42
|
+
2000-12-31 21:01:07 foobar unknown ssssssssss.example.com
|
43
|
+
2000-12-31 21:01:07 #2: (7917) start
|
44
|
+
2000-12-31 21:01:07 foobar unknown cccccccccc.example.com
|
45
|
+
2000-12-31 21:01:11 ssssssssss.example.com: insert xxxxxxx: (99999 records in 1.222222 sec)
|
46
|
+
2000-12-31 21:01:11 qqqqqqqqqq.example.com: insert xxxxxxxxxx: 99 records
|
47
|
+
2000-12-31 21:01:11 qqqqqqqqqq.example.com: insert xxxxxxxxx: 9 records
|
48
|
+
2000-12-31 21:01:11 tttttttttt.example.com: insert xxxxxxxxxxxxx: 99 records
|
49
|
+
2000-12-31 21:01:11 tttttttttt.example.com: insert xxxxxxxxx: 9 records
|
50
|
+
2000-12-31 21:01:11 tttttttttt.example.com: insert xxxxxxxx: 9999 records
|
51
|
+
2000-12-31 21:01:11 rrrrrrrrrr.example.com: insert xxxxxxxxxxxx: 9 records
|
52
|
+
2000-12-31 21:01:12 foobar unknown 192.168.195.12
|
53
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxx: (9999 records in 1.222222 sec)
|
54
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxxxx: 99 records
|
55
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxxx: 9 records
|
56
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxxxxxxx: 99 records
|
57
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxxx: 9 records
|
58
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxx: 9 records
|
59
|
+
2000-12-31 21:01:13 192.168.195.12: insert xxxxxxxxxxxx: 9 records
|
60
|
+
2000-12-31 21:01:13 foobar unknown iiiiiiiiii.example.com
|
61
|
+
2000-12-31 21:01:16 eeeeeeeeee.example.com: insert xxxxxxx: (99999 records in 1.222222 sec)
|
62
|
+
2000-12-31 21:01:16 nnnnnnnnnn.example.com: insert xxxxxxxxxx: 99 records
|
63
|
+
2000-12-31 21:01:16 ssssssssss.example.com: insert xxxxxxxxx: 9 records
|
64
|
+
2000-12-31 21:01:16 kkkkkkkkkk.example.com: insert xxxxxxxxxxxxx: 99 records
|
65
|
+
2000-12-31 21:01:16 bbbbbbbbbb.example.com: insert xxxxxxxxx: 9 records
|
66
|
+
2000-12-31 21:01:16 tttttttttt.example.com: insert xxxxxxxx: 9999 records
|
67
|
+
2000-12-31 21:01:16 aaaaaaaaaa.example.com: insert xxxxxxxxxxxx: 9 records
|
68
|
+
2000-12-31 21:01:17 foobar unknown iiiiiiiiii.example.com
|
69
|
+
2000-12-31 21:01:23 gggggggggg.example.com: insert xxxxxxx: (99999 records in 1.22222 sec)
|
70
|
+
2000-12-31 21:01:23 gggggggggg.example.com: insert xxxxxxxxxx: 99 records
|
71
|
+
2000-12-31 21:01:23 mmmmmmmmmm.example.com: insert xxxxxxxxx: 9 records
|
72
|
+
2000-12-31 21:01:23 bbbbbbbbbb.example.com: insert xxxxxxxxxxxxx: 99 records
|
73
|
+
2000-12-31 21:01:23 ffffffffff.example.com: insert xxxxxxxxx: 9 records
|
74
|
+
2000-12-31 21:01:23 ffffffffff.example.com: insert xxxxxxxx: 9999 records
|
75
|
+
2000-12-31 21:01:23 kkkkkkkkkk.example.com: insert xxxxxxxxxxxx: 9 records
|
76
|
+
2000-12-31 21:01:24 foobar unknown rrrrrrrrrr.example.com
|
77
|
+
2000-12-31 21:01:24 foobar unknown router1.example.jp
|
78
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxx: (9999 records in 1.22222 sec)
|
79
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxxxx: 99 records
|
80
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxxx: 9 records
|
81
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxxxxxxx: 9 records
|
82
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxxx: 9 records
|
83
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxx: 9 records
|
84
|
+
2000-12-31 21:01:25 router1.example.jp: insert xxxxxxxxxxxx: 9 records
|
85
|
+
2000-12-31 21:01:25 foobar unknown router0.example.jp
|
86
|
+
2000-12-31 21:01:28 oooooooooo.example.com: insert xxxxxxx: (99999 records in 11.222222 sec)
|
87
|
+
2000-12-31 21:01:28 aaaaaaaaaa.example.com: insert xxxxxxxxxx: 99 records
|
88
|
+
2000-12-31 21:01:28 oooooooooo.example.com: insert xxxxxxxxx: 9 records
|
89
|
+
2000-12-31 21:01:28 rrrrrrrrrr.example.com: insert xxxxxxxxxxxxx: 99 records
|
90
|
+
2000-12-31 21:01:28 rrrrrrrrrr.example.com: insert xxxxxxxxx: 9 records
|
91
|
+
2000-12-31 21:01:28 hhhhhhhhhh.example.com: insert xxxxxxxx: 9999 records
|
92
|
+
2000-12-31 21:01:28 nnnnnnnnnn.example.com: insert xxxxxxxxxxxx: 9 records
|
93
|
+
2000-12-31 21:01:29 #2: (7917) end
|
94
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxx: (9999 records in 1.222222 sec)
|
95
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxxxx: 99 records
|
96
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxxx: 9 records
|
97
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxxxxxxx: 99 records
|
98
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxxx: 9 records
|
99
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxx: 9 records
|
100
|
+
2000-12-31 21:01:29 router0.example.jp: insert xxxxxxxxxxxx: 9 records
|
101
|
+
2000-12-31 21:01:30 #1: (7916) end
|
102
|
+
2000-12-31 21:01:30 waiting children, done (pid 7904)
|
103
|
+
2000-12-31 21:01:30 foobar unknown: elapsed 11.222222 sec
|
104
|
+
2000-12-31 21:01:30 unlocked: "/tmp/zzzfoobaror-lock" (pid 7904)
|
105
|
+
2000-12-31 21:01:30 END: foobarorController (pid 7904)
|