pwrake 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -9
- data/bin/gfwhere-pipe +33 -9
- data/bin/pwrake +5 -2
- data/bin/pwrake_branch +5 -3
- data/lib/pwrake/branch/branch.rb +95 -86
- data/lib/pwrake/branch/branch_application.rb +4 -0
- data/lib/pwrake/branch/communicator.rb +173 -0
- data/lib/pwrake/branch/communicator_set.rb +100 -0
- data/lib/pwrake/branch/fiber_queue.rb +10 -0
- data/lib/pwrake/branch/shell.rb +68 -24
- data/lib/pwrake/branch/shell_profiler.rb +2 -0
- data/lib/pwrake/gfarm/gfarm_postprocess.rb +8 -7
- data/lib/pwrake/logger.rb +5 -0
- data/lib/pwrake/master/master.rb +190 -87
- data/lib/pwrake/master/master_application.rb +8 -0
- data/lib/pwrake/nbio.rb +525 -0
- data/lib/pwrake/option/host_map.rb +36 -4
- data/lib/pwrake/option/option.rb +7 -1
- data/lib/pwrake/option/option_filesystem.rb +13 -3
- data/lib/pwrake/queue/locality_aware_queue.rb +41 -6
- data/lib/pwrake/queue/queue_array.rb +31 -11
- data/lib/pwrake/queue/task_queue.rb +15 -18
- data/lib/pwrake/report/report.rb +2 -0
- data/lib/pwrake/task/task_algorithm.rb +4 -1
- data/lib/pwrake/task/task_manager.rb +2 -0
- data/lib/pwrake/task/task_property.rb +1 -0
- data/lib/pwrake/task/task_wrapper.rb +40 -21
- data/lib/pwrake/version.rb +1 -1
- data/lib/pwrake/worker/invoker.rb +4 -29
- data/pwrake.gemspec +3 -2
- metadata +24 -12
- data/lib/pwrake/branch.rb +0 -22
- data/lib/pwrake/branch/worker_communicator.rb +0 -104
- data/lib/pwrake/iomux/channel.rb +0 -70
- data/lib/pwrake/iomux/handler.rb +0 -124
- data/lib/pwrake/iomux/handler_set.rb +0 -35
- data/lib/pwrake/iomux/runner.rb +0 -62
- data/lib/pwrake/master.rb +0 -30
data/lib/pwrake/version.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Pwrake
|
2
2
|
|
3
3
|
class Invoker
|
4
|
+
# using Michael Grosser's parallel
|
5
|
+
# https://github.com/grosser/parallel
|
6
|
+
include Parallel::ProcessorCount
|
4
7
|
|
5
8
|
def initialize(dir_class, ncore, option)
|
6
9
|
@dir_class = dir_class
|
@@ -161,37 +164,9 @@ module Pwrake
|
|
161
164
|
$stdout.puts e
|
162
165
|
$stdout.puts e.backtrace.join("\n")
|
163
166
|
end
|
167
|
+
ensure
|
164
168
|
@out.puts "exited"
|
165
169
|
end
|
166
170
|
|
167
|
-
# from Michael Grosser's parallel
|
168
|
-
# https://github.com/grosser/parallel
|
169
|
-
def processor_count
|
170
|
-
host_os = RbConfig::CONFIG['host_os']
|
171
|
-
case host_os
|
172
|
-
when /linux|cygwin/
|
173
|
-
ncpu = 0
|
174
|
-
open("/proc/cpuinfo").each do |l|
|
175
|
-
ncpu += 1 if /^processor\s+: \d+/=~l
|
176
|
-
end
|
177
|
-
ncpu
|
178
|
-
when /darwin9/
|
179
|
-
`hwprefs cpu_count`.to_i
|
180
|
-
when /darwin/
|
181
|
-
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
|
182
|
-
when /(open|free)bsd/
|
183
|
-
`sysctl -n hw.ncpu`.to_i
|
184
|
-
when /mswin|mingw/
|
185
|
-
require 'win32ole'
|
186
|
-
wmi = WIN32OLE.connect("winmgmts://")
|
187
|
-
cpu = wmi.ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
|
188
|
-
cpu.to_enum.first.NumberOfLogicalProcessors
|
189
|
-
when /solaris2/
|
190
|
-
`psrinfo -p`.to_i # physical cpus
|
191
|
-
else
|
192
|
-
raise "Unknown architecture: #{host_os}"
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
171
|
end
|
197
172
|
end
|
data/pwrake.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Pwrake::VERSION
|
9
9
|
gem.authors = ["Masahiro TANAKA"]
|
10
10
|
gem.email = ["masa16.tanaka@gmail.com"]
|
11
|
-
gem.
|
12
|
-
gem.
|
11
|
+
gem.summary = %q{Parallel Workflow engine based on Rake}
|
12
|
+
gem.description = %q{Parallel Workflow engine based on Rake, runs on multicores, clusters, clouds}
|
13
13
|
gem.homepage = "http://masa16.github.com/pwrake"
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
|
+
gem.add_runtime_dependency 'parallel', '>= 1.2.4'
|
20
21
|
end
|
metadata
CHANGED
@@ -1,16 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwrake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: parallel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.4
|
27
|
+
description: Parallel Workflow engine based on Rake, runs on multicores, clusters,
|
28
|
+
clouds
|
14
29
|
email:
|
15
30
|
- masa16.tanaka@gmail.com
|
16
31
|
executables:
|
@@ -29,22 +44,17 @@ files:
|
|
29
44
|
- bin/gfwhere-pipe
|
30
45
|
- bin/pwrake
|
31
46
|
- bin/pwrake_branch
|
32
|
-
- lib/pwrake/branch.rb
|
33
47
|
- lib/pwrake/branch/branch.rb
|
34
48
|
- lib/pwrake/branch/branch_application.rb
|
49
|
+
- lib/pwrake/branch/communicator.rb
|
50
|
+
- lib/pwrake/branch/communicator_set.rb
|
35
51
|
- lib/pwrake/branch/fiber_queue.rb
|
36
52
|
- lib/pwrake/branch/file_utils.rb
|
37
53
|
- lib/pwrake/branch/shell.rb
|
38
54
|
- lib/pwrake/branch/shell_profiler.rb
|
39
|
-
- lib/pwrake/branch/worker_communicator.rb
|
40
55
|
- lib/pwrake/gfarm/gfarm_path.rb
|
41
56
|
- lib/pwrake/gfarm/gfarm_postprocess.rb
|
42
|
-
- lib/pwrake/iomux/channel.rb
|
43
|
-
- lib/pwrake/iomux/handler.rb
|
44
|
-
- lib/pwrake/iomux/handler_set.rb
|
45
|
-
- lib/pwrake/iomux/runner.rb
|
46
57
|
- lib/pwrake/logger.rb
|
47
|
-
- lib/pwrake/master.rb
|
48
58
|
- lib/pwrake/master/fiber_pool.rb
|
49
59
|
- lib/pwrake/master/idle_cores.rb
|
50
60
|
- lib/pwrake/master/master.rb
|
@@ -52,6 +62,7 @@ files:
|
|
52
62
|
- lib/pwrake/master/postprocess.rb
|
53
63
|
- lib/pwrake/misc/graphviz.rb
|
54
64
|
- lib/pwrake/misc/mcgp.rb
|
65
|
+
- lib/pwrake/nbio.rb
|
55
66
|
- lib/pwrake/option/host_map.rb
|
56
67
|
- lib/pwrake/option/option.rb
|
57
68
|
- lib/pwrake/option/option_filesystem.rb
|
@@ -121,7 +132,7 @@ rubyforge_project:
|
|
121
132
|
rubygems_version: 2.5.1
|
122
133
|
signing_key:
|
123
134
|
specification_version: 4
|
124
|
-
summary:
|
135
|
+
summary: Parallel Workflow engine based on Rake
|
125
136
|
test_files:
|
126
137
|
- spec/001/Rakefile
|
127
138
|
- spec/002/Rakefile
|
@@ -140,3 +151,4 @@ test_files:
|
|
140
151
|
- spec/helper.rb
|
141
152
|
- spec/hosts
|
142
153
|
- spec/pwrake_spec.rb
|
154
|
+
has_rdoc:
|
data/lib/pwrake/branch.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "logger"
|
2
|
-
require 'csv'
|
3
|
-
|
4
|
-
require "pwrake/logger"
|
5
|
-
|
6
|
-
require "pwrake/iomux/channel"
|
7
|
-
require "pwrake/iomux/handler"
|
8
|
-
require "pwrake/iomux/handler_set"
|
9
|
-
require "pwrake/iomux/runner"
|
10
|
-
|
11
|
-
require "pwrake/branch/branch_application"
|
12
|
-
require "pwrake/branch/branch"
|
13
|
-
require "pwrake/branch/fiber_queue"
|
14
|
-
require "pwrake/branch/file_utils"
|
15
|
-
|
16
|
-
require 'pwrake/branch/shell_profiler'
|
17
|
-
require "pwrake/branch/shell"
|
18
|
-
require "pwrake/branch/worker_communicator"
|
19
|
-
|
20
|
-
require "pwrake/option/option"
|
21
|
-
require "pwrake/option/option_filesystem"
|
22
|
-
require "pwrake/option/host_map"
|
@@ -1,104 +0,0 @@
|
|
1
|
-
module Pwrake
|
2
|
-
|
3
|
-
class WorkerCommunicator
|
4
|
-
|
5
|
-
HOST2ID = {}
|
6
|
-
RE_ID='\d+'
|
7
|
-
attr_reader :id, :host, :ncore, :handler, :channel
|
8
|
-
|
9
|
-
def self.read_worker_progs(option)
|
10
|
-
d = File.dirname(__FILE__)+'/../worker/'
|
11
|
-
code = ""
|
12
|
-
option.worker_progs.each do |f|
|
13
|
-
code << IO.read(d+f+'.rb')
|
14
|
-
end
|
15
|
-
code
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(id,host,ncore,runner,option)
|
19
|
-
@id = id
|
20
|
-
@host = host
|
21
|
-
HOST2ID[@host] = @id
|
22
|
-
@ncore = @n_total_core = ncore
|
23
|
-
#
|
24
|
-
@runner = runner
|
25
|
-
@worker_progs = option.worker_progs
|
26
|
-
@option = option.worker_option
|
27
|
-
if hb = @option[:heartbeat]
|
28
|
-
@heartbeat_timeout = hb + 15
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def setup_connection(worker_code)
|
33
|
-
rb_cmd = "ruby -e 'eval ARGF.read(#{worker_code.size})'"
|
34
|
-
if ['localhost','localhost.localdomain','127.0.0.1'].include? @host
|
35
|
-
cmd = "cd; #{rb_cmd}"
|
36
|
-
else
|
37
|
-
cmd = "ssh -x -T -q #{@option[:ssh_option]} #{@host} \"#{rb_cmd}\""
|
38
|
-
end
|
39
|
-
Log.debug cmd
|
40
|
-
@handler = Handler.new(@runner) do |w0,w1,r2|
|
41
|
-
@pid = spawn(cmd,:pgroup=>true,:out=>w0,:err=>w1,:in=>r2)
|
42
|
-
w0.close
|
43
|
-
w1.close
|
44
|
-
r2.close
|
45
|
-
end
|
46
|
-
@handler.host = @host
|
47
|
-
iow = @handler.iow
|
48
|
-
iow.write(worker_code)
|
49
|
-
Marshal.dump(@ncore,iow)
|
50
|
-
Marshal.dump(@option,iow)
|
51
|
-
@channel = Channel.new(@handler)
|
52
|
-
end
|
53
|
-
|
54
|
-
def close
|
55
|
-
if !@closed
|
56
|
-
@closed = true
|
57
|
-
@handler.close
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def set_ncore(ncore)
|
62
|
-
@ncore = ncore
|
63
|
-
end
|
64
|
-
|
65
|
-
def ncore_proc(s)
|
66
|
-
if /^ncore:(.*)$/ =~ s
|
67
|
-
a = $1
|
68
|
-
Log.debug "#{a} @#{@host}"
|
69
|
-
if /^(\d+)$/ =~ a
|
70
|
-
set_ncore($1.to_i)
|
71
|
-
return false
|
72
|
-
else
|
73
|
-
raise ArgumentError,"WorkerCommunicator#ncore_proc: s=#{s.inspect}"
|
74
|
-
end
|
75
|
-
else
|
76
|
-
return common_line(s)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def common_line(s)
|
81
|
-
Log.debug "WorkerCommunicator#common_line(#{s.inspect}) id=#{@id} host=#{@host}"
|
82
|
-
case s
|
83
|
-
when /^heartbeat$/
|
84
|
-
@runner.heartbeat(@handler.ior)
|
85
|
-
when /^exited$/
|
86
|
-
return false
|
87
|
-
when /^log:(.*)$/
|
88
|
-
Log.info "worker(#{host})>#{$1}"
|
89
|
-
else
|
90
|
-
Log.warn "worker(#{host}) out> #{s.inspect}"
|
91
|
-
end
|
92
|
-
true
|
93
|
-
end
|
94
|
-
|
95
|
-
def start_default_fiber
|
96
|
-
Fiber.new do
|
97
|
-
while common_line(@channel.get_line)
|
98
|
-
end
|
99
|
-
Log.debug "WorkerCommunicator: end of default fiber"
|
100
|
-
end.resume
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
end
|
data/lib/pwrake/iomux/channel.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module Pwrake
|
2
|
-
|
3
|
-
class Channel
|
4
|
-
|
5
|
-
def initialize(handler,id=nil)
|
6
|
-
if @id = id
|
7
|
-
@pre = "#{@id}:"
|
8
|
-
else
|
9
|
-
@pre = ""
|
10
|
-
end
|
11
|
-
if !handler.kind_of?(Handler)
|
12
|
-
raise TypeError, "Argument must be Handler but #{handler.class}"
|
13
|
-
end
|
14
|
-
@handler = handler
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :id, :handler, :fiber
|
18
|
-
|
19
|
-
def ior
|
20
|
-
@handler.ior
|
21
|
-
end
|
22
|
-
|
23
|
-
def run_fiber(*args)
|
24
|
-
if @fiber.nil?
|
25
|
-
m = "Channel#run_fiber: @fiber is nil,"+
|
26
|
-
" args=#{args.inspect} @id=#{@id}"
|
27
|
-
$stderr.puts m
|
28
|
-
Log.debug m
|
29
|
-
else
|
30
|
-
@fiber.resume(*args)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def finish
|
35
|
-
if !@fiber.nil?
|
36
|
-
@fiber.resume(nil)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_line
|
41
|
-
@handler.add_channel(self)
|
42
|
-
@fiber = Fiber.current
|
43
|
-
line = Fiber.yield
|
44
|
-
@fiber = nil
|
45
|
-
@handler.delete_channel(self)
|
46
|
-
return line
|
47
|
-
end
|
48
|
-
|
49
|
-
def put_line(line)
|
50
|
-
@handler.put_line "#{@pre}#{line}"
|
51
|
-
end
|
52
|
-
|
53
|
-
def puts(line)
|
54
|
-
@handler.puts "#{@pre}#{line}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def gets
|
58
|
-
if @id
|
59
|
-
raise RuntimeError,"gets is invalid when @id is non-nil"
|
60
|
-
else
|
61
|
-
@handler.gets
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def inspect
|
66
|
-
"#<#{self.class} io=#{ior.inspect} id=#{id.inspect}>"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
data/lib/pwrake/iomux/handler.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
module Pwrake
|
2
|
-
|
3
|
-
class Handler
|
4
|
-
|
5
|
-
def initialize(runner,*io,&blk)
|
6
|
-
if !runner.kind_of?(Runner)
|
7
|
-
raise TypeError, "Argument must be Runner but #{runner.class}"
|
8
|
-
end
|
9
|
-
@runner = runner
|
10
|
-
@channel = {}
|
11
|
-
if !io.empty?
|
12
|
-
if !block_given?
|
13
|
-
@ior,@iow,@ioe = *io
|
14
|
-
end
|
15
|
-
else
|
16
|
-
if block_given?
|
17
|
-
@ior,w0 = IO.pipe
|
18
|
-
@ioe,w1 = IO.pipe
|
19
|
-
r2,@iow = IO.pipe
|
20
|
-
yield(w0,w1,r2)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
if @ior.nil? && @iow.nil?
|
24
|
-
raise "fail to initialize IO"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_reader :runner, :ior, :iow, :ioe
|
29
|
-
attr_accessor :host
|
30
|
-
|
31
|
-
def add_channel(chan)
|
32
|
-
if !chan.kind_of?(Channel)
|
33
|
-
raise TypeError, "Argument must be Channel but #{chan.class}"
|
34
|
-
end
|
35
|
-
@channel[chan.id] = chan
|
36
|
-
@runner.add_handler(self)
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete_channel(chan)
|
40
|
-
if !chan.kind_of?(Channel)
|
41
|
-
raise TypeError, "Argument must be Channel but #{chan.class}"
|
42
|
-
end
|
43
|
-
@channel.delete(chan.id)
|
44
|
-
if @channel.empty?
|
45
|
-
@runner.delete_handler(self)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def process_line
|
50
|
-
if s = (@ior.eof?) ? nil : @ior.gets
|
51
|
-
default_channel = @channel[nil]
|
52
|
-
if @channel.size > ((default_channel) ? 1 : 0)
|
53
|
-
if /^(\d+):(.*)$/ =~ s
|
54
|
-
ch,line = $1,$2
|
55
|
-
if chan = @channel[ch.to_i]
|
56
|
-
return chan.run_fiber(line)
|
57
|
-
else
|
58
|
-
raise "No channel##{ch}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
if default_channel
|
63
|
-
return default_channel.run_fiber(s.chomp)
|
64
|
-
else
|
65
|
-
raise "No default_channel, received: #{s.chomp}"
|
66
|
-
end
|
67
|
-
else
|
68
|
-
# End of IO
|
69
|
-
@channel.values.each do |chan|
|
70
|
-
if chan.fiber
|
71
|
-
chan.run_fiber(nil)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def finish
|
78
|
-
@channel.values.each do |chan|
|
79
|
-
chan.finish
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# -- writer
|
84
|
-
|
85
|
-
def put_line(line)
|
86
|
-
begin
|
87
|
-
@iow.print line.to_str+"\n"
|
88
|
-
@iow.flush
|
89
|
-
#Log.debug "Handler#put_line #{line.inspect} @iow=#{@iow.inspect}"
|
90
|
-
rescue Errno::EPIPE => e
|
91
|
-
if Rake.application.options.debug
|
92
|
-
$stderr.puts "Errno::EPIPE in #{self.class}.put_line '#{line.chomp}'"
|
93
|
-
$stderr.puts e.backtrace.join("\n")
|
94
|
-
end
|
95
|
-
Log.error "Errno::EPIPE in #{self.class}.put_line '#{line.chomp}'\n"+
|
96
|
-
e.backtrace.join("\n")
|
97
|
-
#raise e
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def puts(line)
|
102
|
-
@iow.puts(line)
|
103
|
-
end
|
104
|
-
|
105
|
-
def gets
|
106
|
-
@ior.gets
|
107
|
-
end
|
108
|
-
|
109
|
-
def wait_message(end_msg)
|
110
|
-
if line = @ior.gets
|
111
|
-
line.chomp!
|
112
|
-
m = "Handler#wait_message: #{line} host=#{@host}"
|
113
|
-
if line == end_msg
|
114
|
-
Log.debug m
|
115
|
-
else
|
116
|
-
Log.error m
|
117
|
-
end
|
118
|
-
else
|
119
|
-
Log.error "Handler#wait_message: fail to read @ior"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|