pwrake 2.2.1 → 2.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 165b50b8450d65b495aefffe22cc3a8e02ae3828
4
- data.tar.gz: 210a2fcb2b42cb1b70696e84595e20dd71332c83
3
+ metadata.gz: 700155f122d51b4ae814349492054d336daa6dad
4
+ data.tar.gz: 8bd23134b9c79784b95670440c0e823f139b41e5
5
5
  SHA512:
6
- metadata.gz: ce57a49375d39fc42a4a785bb9e703fe4f90af8f5ec2db63c4a1d5fb7beb3c3d3f44b37742a1cbb8c9f40621cbc3d66a8c458cb17a6d530d9ad43374bda829e9
7
- data.tar.gz: fae5ad1e68b9b7f87ab12428e9826a50ed8809120c2f4a5a45215518ff7e590f82051d6e4fb7e63914222b81c6dbea762c8ef7cfaf8e88a4823f6e176d325df0
6
+ metadata.gz: ca62080f1e262829e1da0623c474d0415bdda728498bea11a25f8b17d2a3d60ecf8ebb701ab4eb160f8a894840e402477f2daf87335103aefa42bf89a021d1b5
7
+ data.tar.gz: ad190406c5a890f78e3691cac5bed219e537ac911617fe4cb1d68ce6d6cbd65c9963e0fa5bd8e328aad864e6303bef893bd5877afefcd2e85402d6864759f8ee
@@ -114,7 +114,7 @@ class Communicator
114
114
  return false if !common_line(s)
115
115
  end
116
116
  end
117
- raise ConnectError, "fail to connect #{cmd.inspect}"
117
+ raise ConnectError, "lost connection to #{@host} during setup"
118
118
  rescue => e
119
119
  dropout(e)
120
120
  end
@@ -229,6 +229,7 @@ module Pwrake
229
229
  task = Rake.application[task_name]
230
230
  @ncore = task.wrapper.n_used_cores
231
231
  begin
232
+ Rake.application.current_flow[Fiber.current] = task.property.subflow
232
233
  task.execute(task.arguments) if task.needed?
233
234
  result = "taskend:#{@id}:#{task.name}"
234
235
  rescue Exception=>e
@@ -237,6 +238,7 @@ module Pwrake
237
238
  result = "taskfail:#{@id}:#{task.name}"
238
239
  break if @exited
239
240
  ensure
241
+ Rake.application.current_flow[Fiber.current] = nil
240
242
  master_w.put_line result
241
243
  end
242
244
  end
@@ -17,6 +17,7 @@ module Pwrake
17
17
  @channel_by_hostid = {}
18
18
  @channels = []
19
19
  @hostinfo_by_id = {}
20
+ @current_flow = {}
20
21
  # init
21
22
  @option = Option.new
22
23
  Log.set_logger(@option)
@@ -31,6 +32,7 @@ module Pwrake
31
32
  attr_reader :task_queue
32
33
  attr_reader :option
33
34
  attr_reader :thread
35
+ attr_reader :current_flow # current_flow[Fiber.current] = task.property.subflow
34
36
 
35
37
  def setup_branch_handler(sub_host)
36
38
  ior,w0 = IO.pipe
@@ -331,7 +333,7 @@ module Pwrake
331
333
  Fiber.new do
332
334
  j = i
333
335
  while tw = pool.deq()
334
- Log.debug "postproc##{j} deq=#{tw.name}"
336
+ #Log.debug "postproc##{j} deq=#{tw.name}"
335
337
  tw.postprocess(postproc)
336
338
  pool.count_down
337
339
  @hostinfo_by_taskname.delete(tw.name)
@@ -339,7 +341,7 @@ module Pwrake
339
341
  break if yield(pool,j)
340
342
  end
341
343
  postproc.close
342
- Log.debug "postproc##{j} end"
344
+ #Log.debug "postproc##{j} end"
343
345
  end
344
346
  end
345
347
  end
@@ -13,6 +13,10 @@ module Pwrake
13
13
  @role.task_queue
14
14
  end
15
15
 
16
+ def current_flow
17
+ @role.current_flow
18
+ end
19
+
16
20
  # Run the Pwrake application.
17
21
  def run
18
22
  standard_exception_handling do
@@ -46,10 +50,33 @@ module Pwrake
46
50
  end
47
51
  end
48
52
 
49
- def invoke_task(task_string)
50
- name, args = parse_task_string(task_string)
51
- t = self[name]
52
- @master.invoke(t,args)
53
+ # Find the rakefile and then load it and any pending imports.
54
+ def load_rakefile
55
+ if subdirs = pwrake_options['SUBDIR']
56
+ subdirs.each do |x|
57
+ begin
58
+ Rake.application.current_flow[Fiber.current] = x
59
+ super
60
+ ensure
61
+ Rake.application.current_flow[Fiber.current] = nil
62
+ end
63
+ end
64
+ else
65
+ super
66
+ end
67
+ end
68
+
69
+ def find_rakefile_location # :nodoc:
70
+ if subdir = Rake.application.current_flow[Fiber.current]
71
+ Dir.chdir(subdir)
72
+ if fn = have_rakefile
73
+ [File.join(subdir,fn), Rake.original_dir]
74
+ end
75
+ else
76
+ super
77
+ end
78
+ ensure
79
+ Dir.chdir(Rake.original_dir)
53
80
  end
54
81
 
55
82
  def invoke(t,*args)
@@ -138,6 +165,12 @@ module Pwrake
138
165
  "[Pw] Pwrake configuation file in YAML",
139
166
  lambda {|value| options.pwrake_conf = value}
140
167
  ],
168
+ ['--subdir "dir1 dir2 ..."',
169
+ "[Pw] Join workflows in subdirectories",
170
+ lambda { |value|
171
+ options.subdir = value.split(/[\s,;:]+/)
172
+ }
173
+ ],
141
174
  ['--show-conf','--show-config',
142
175
  "[Pw] Show Pwrake configuration options",
143
176
  lambda {|value| options.show_conf = true }
@@ -86,6 +86,27 @@ module Pwrake
86
86
  end
87
87
  @continuous_fail
88
88
  end
89
+
90
+ def accept_core(task_name, use_cores)
91
+ if @reserved_task
92
+ if @reserved_task == task_name
93
+ if use_cores <= @idle_cores
94
+ Log.info "use reserved: #{@name} for #{task_name} (#{use_cores} cores)"
95
+ @reserved_task = nil
96
+ return :ok
97
+ end
98
+ end
99
+ else
100
+ if use_cores <= @idle_cores
101
+ return :ok
102
+ elsif use_cores > 1
103
+ @reserved_task = task_name
104
+ Log.info "reserve host: #{@name} for #{task_name} (#{use_cores} cores)"
105
+ return :reserve
106
+ end
107
+ end
108
+ :busy
109
+ end
89
110
  end
90
111
 
91
112
  class HostMap < Hash
@@ -1,5 +1,6 @@
1
1
  require "pathname"
2
2
  require "yaml"
3
+ require "socket"
3
4
  require "parallel"
4
5
  require "pwrake/option/host_map"
5
6
 
@@ -144,6 +145,19 @@ module Pwrake
144
145
  'DEBUG',
145
146
  'PLOT_PARALLELISM',
146
147
  'SHOW_CONF',
148
+ ['SUBDIR','SUBDIRS',
149
+ proc{|v|
150
+ if Array===v
151
+ v.each do |d|
152
+ if !File.directory?(d)
153
+ raise "directory #{d.inspect} does not exist"
154
+ end
155
+ end
156
+ elsif !v.nil?
157
+ raise "invalid argument for SUBDIR: #{v.inspect}"
158
+ end
159
+ }
160
+ ],
147
161
  ['REPORT_DIR','REPORT'],
148
162
  'REPORT_IMAGE',
149
163
  'FAILED_TARGET', # rename(default), delete, leave
@@ -207,7 +221,7 @@ module Pwrake
207
221
  ['SHELL_START_INTERVAL', proc{|v| (v || 0.012).to_f}],
208
222
  ['HEARTBEAT', proc{|v| (v || 240).to_i}],
209
223
  ['RETRY', proc{|v| (v || 1).to_i}],
210
- ['MASTER_HOSTNAME', proc{|v| (v || begin;`hostname -f`;rescue;end || '').chomp}],
224
+ ['MASTER_HOSTNAME', proc{|v| (v || Socket.gethostname).chomp}],
211
225
  ['WORK_DIR', proc{|v|
212
226
  v ||= '%CWD_RELATIVE_TO_HOME'
213
227
  v.sub('%CWD_RELATIVE_TO_HOME',cwd_relative_if_under_home)
@@ -68,18 +68,22 @@ module Pwrake
68
68
 
69
69
  def shift(host_info=nil)
70
70
  return super() unless host_info
71
- i_found = nil
71
+ i_tried = []
72
72
  (size-1).downto(0) do |i|
73
+ tw = at(i)
74
+ if tw.tried_host?(host_info)
75
+ i_tried << i
76
+ elsif tw.acceptable_for(host_info)
77
+ return delete_at(i)
78
+ end
79
+ end
80
+ i_tried.each do |i|
73
81
  tw = at(i)
74
82
  if tw.acceptable_for(host_info)
75
- if tw.untried_host?(host_info)
76
- return delete_at(i)
77
- else
78
- i_found ||= i
79
- end
83
+ return delete_at(i)
80
84
  end
81
85
  end
82
- (i_found) ? delete_at(i_found) : nil
86
+ nil
83
87
  end
84
88
  end
85
89
 
@@ -90,18 +94,22 @@ module Pwrake
90
94
 
91
95
  def shift(host_info=nil)
92
96
  return super() unless host_info
93
- i_found = nil
97
+ i_tried = []
94
98
  size.times do |i|
99
+ tw = at(i)
100
+ if tw.tried_host?(host_info)
101
+ i_tried << i
102
+ elsif tw.acceptable_for(host_info)
103
+ return delete_at(i)
104
+ end
105
+ end
106
+ i_tried.each do |i|
95
107
  tw = at(i)
96
108
  if tw.acceptable_for(host_info)
97
- if tw.untried_host?(host_info)
98
- return delete_at(i)
99
- else
100
- i_found ||= i
101
- end
109
+ return delete_at(i)
102
110
  end
103
111
  end
104
- (i_found) ? delete_at(i_found) : nil
112
+ nil
105
113
  end
106
114
  end
107
115
 
@@ -172,18 +180,24 @@ module Pwrake
172
180
  end
173
181
 
174
182
  def pop_last_rank(r,host_info)
175
- i_found = nil
183
+ i_tried = []
176
184
  (size-1).downto(0) do |i|
177
185
  tw = at(i)
178
- if tw.rank == r && tw.acceptable_for(host_info)
179
- if tw.untried_host?(host_info)
186
+ if tw.rank == r
187
+ if tw.tried_host?(host_info)
188
+ i_tried << i
189
+ elsif tw.acceptable_for(host_info)
180
190
  return delete_at(i)
181
- else
182
- i_found ||= i
183
191
  end
184
192
  end
185
193
  end
186
- (i_found) ? delete_at(i_found) : nil
194
+ i_tried.each do |i|
195
+ tw = at(i)
196
+ if tw.acceptable_for(host_info)
197
+ return delete_at(i)
198
+ end
199
+ end
200
+ nil
187
201
  end
188
202
 
189
203
  def hrf_delete(t)
@@ -70,15 +70,12 @@ module Pwrake
70
70
  end
71
71
 
72
72
  def deq_task(&block) # locality version
73
- Log.debug "deq_task:"+(empty? ? " (empty)" : "\n#{inspect_q}")
73
+ Log.debug "deq_task from:"+(empty? ? " (empty)" : "\n#{inspect_q}")
74
74
  queued = 0
75
75
  @n_turn.times do |turn|
76
76
  next if turn_empty?(turn)
77
77
  queued += deq_turn(turn,&block)
78
78
  end
79
- if queued>0
80
- Log.debug "deq_task: queued=#{queued}"
81
- end
82
79
  end
83
80
 
84
81
  def deq_turn(turn,&block)
@@ -100,7 +100,11 @@ module Pwrake
100
100
  end
101
101
 
102
102
  def pw_set_property(property)
103
- @property = property
103
+ if @property
104
+ @property.merge(property)
105
+ else
106
+ @property = property
107
+ end
104
108
  self
105
109
  end
106
110
 
@@ -21,7 +21,17 @@ module Pwrake
21
21
  prop = @last_property
22
22
  @last_property = TaskProperty.new
23
23
  end
24
- super.pw_set_property(prop)
24
+ if !@disable_subflow
25
+ @subflow_prefix = Rake.application.current_flow[Fiber.current]
26
+ end
27
+ task = super
28
+ task.pw_set_property(prop)
29
+ if !@disable_subflow
30
+ task.property.subflow = @subflow_prefix
31
+ end
32
+ task
33
+ ensure
34
+ @subflow_prefix = nil
25
35
  end
26
36
 
27
37
  def create_rule(*args, &block) # :nodoc:
@@ -30,5 +40,44 @@ module Pwrake
30
40
  super
31
41
  end
32
42
 
43
+ def resolve_args(args)
44
+ task_name, arg_names, deps = super(args)
45
+ if @subflow_prefix
46
+ # fix prerequisites
47
+ deps.map! do |task_name|
48
+ add_prefix(task_name)
49
+ end
50
+ end
51
+ [task_name, arg_names, deps]
52
+ end
53
+
54
+ def intern(task_class, task_name)
55
+ if @subflow_prefix
56
+ base_name = task_name
57
+ # fix task name
58
+ task_name = add_prefix(task_name)
59
+ if base_name != task_name && task_class == Rake::Task
60
+ sbfl = @subflow_prefix
61
+ begin
62
+ @subflow_prefix = nil
63
+ @disable_subflow = true
64
+ Rake::Task.define_task(base_name => task_name)
65
+ ensure
66
+ @subflow_prefix = sbfl
67
+ @disable_subflow = false
68
+ end
69
+ end
70
+ end
71
+ super(task_class, task_name)
72
+ end
73
+
74
+ def add_prefix(task_name)
75
+ task_name = task_name.to_s
76
+ if /^\.?\.?\// =~ task_name
77
+ task_name
78
+ else
79
+ File.join(@subflow_prefix, task_name)
80
+ end
81
+ end
33
82
  end
34
83
  end
@@ -4,6 +4,7 @@ module Pwrake
4
4
 
5
5
  attr_reader :ncore, :exclusive, :allow, :deny, :order_allow_deny,
6
6
  :retry, :disable_steal
7
+ attr_accessor :subflow
7
8
 
8
9
  def parse_description(description)
9
10
  if /\bn_?cores?[=:]\s*([+-]?\d+)/i =~ description
@@ -38,19 +39,31 @@ module Pwrake
38
39
  end
39
40
  end
40
41
 
41
- def acceptable_for(host_info)
42
+ def merge(prop)
43
+ @ncore = prop.ncore if prop.ncore
44
+ @exclusive = prop.exclusive if prop.exclusive
45
+ @allow = prop.allow if prop.allow
46
+ @deny = prop.deny if prop.deny
47
+ @order_allow_deny = prop.order_allow_deny if prop.order_allow_deny
48
+ @retry = prop.retry if prop.retry
49
+ @disable_steal = prop.disable_steal if prop.disable_steal
50
+ @subflow = prop.subflow if prop.subflow
51
+ end
52
+
53
+ def use_cores(host_info)
54
+ nc = (@exclusive) ? 0 : (@ncore || 1)
55
+ if nc < 1
56
+ nc += host_info.ncore
57
+ end
58
+ return nc
59
+ end
60
+
61
+ def accept_host(host_info)
42
62
  return true unless host_info
43
63
  if @disable_steal && host_info.steal_flag
44
64
  #Log.debug("@disable_steal && host_info.steal_flag")
45
65
  return false
46
66
  end
47
- ncore = (@exclusive) ? 0 : (@ncore || 1)
48
- if ncore > 0
49
- return false if ncore > host_info.idle_cores
50
- else
51
- n = host_info.ncore + ncore
52
- return false if n < 1 || n > host_info.idle_cores
53
- end
54
67
  hn = host_info.name
55
68
  if @allow
56
69
  if @deny
@@ -29,12 +29,11 @@ module Pwrake
29
29
  @assigned = []
30
30
  @exec_host = nil
31
31
  @exec_host_id = nil
32
- @tried_hosts = []
32
+ @tried_hosts = {}
33
33
  @n_retry = @property.retry || Rake.application.pwrake_options["RETRY"] || 1
34
34
  end
35
35
 
36
36
  def_delegators :@task, :name, :actions, :prerequisites, :subsequents
37
- def_delegators :@property, :acceptable_for
38
37
 
39
38
  attr_reader :task, :task_id, :group, :group_id, :file_stat
40
39
  attr_reader :location
@@ -91,7 +90,7 @@ module Pwrake
91
90
  end
92
91
 
93
92
  def retry_or_subsequent
94
- @tried_hosts << @exec_host
93
+ @tried_hosts[@exec_host] = true
95
94
  if @status=="end"
96
95
  @task.pw_enq_subsequents
97
96
  elsif @n_retry > 0
@@ -102,7 +101,7 @@ module Pwrake
102
101
  @n_retry -= 1
103
102
  Rake.application.task_queue.enq(self)
104
103
  else
105
- s="give up retry (retry_count=0): #{name}"
104
+ s="give up retry (retry_count=#{@n_retry}): #{name}"
106
105
  Log.error(s)
107
106
  $stderr.puts(s)
108
107
  end
@@ -171,7 +170,7 @@ module Pwrake
171
170
  @@task_logger << row
172
171
  #
173
172
  clsname = @task.class.to_s.sub(/^(Rake|Pwrake)::/o,"")
174
- msg = '%s:"%s" %s: id=%d elap=%.6f exec_host=%s' %
173
+ msg = '%s[%s] status=%s id=%d elap=%.6f exec_host=%s' %
175
174
  [clsname,name,@status,@task_id,elap,@exec_host]
176
175
  if @status=="end"
177
176
  Log.info msg
@@ -266,7 +265,7 @@ module Pwrake
266
265
  end
267
266
  @rank = max_rank + step
268
267
  end
269
- Log.debug "Task[#{name}] rank=#{@rank.inspect}"
268
+ #Log.debug "Task[#{name}] rank=#{@rank.inspect}"
270
269
  end
271
270
  @rank
272
271
  end
@@ -343,9 +342,25 @@ module Pwrake
343
342
  @n_used_cores ||= @property.n_used_cores(host_info)
344
343
  end
345
344
 
346
- def untried_host?(host_info)
347
- return true unless host_info
348
- !@tried_hosts.include?(host_info.name)
345
+ def acceptable_for(host_info)
346
+ unless @property.accept_host(host_info)
347
+ return false
348
+ end
349
+ use_cores = @property.use_cores(host_info)
350
+ if @reserved_host.nil? || @reserved_host == host_info
351
+ case host_info.accept_core(name,use_cores)
352
+ when :ok
353
+ @reserved_host = nil
354
+ return true
355
+ when :reserve
356
+ @reserved_host = host_info
357
+ end
358
+ end
359
+ false
360
+ end
361
+
362
+ def tried_host?(host_info)
363
+ host_info && @tried_hosts[host_info.name]
349
364
  end
350
365
 
351
366
  end
@@ -1,3 +1,3 @@
1
1
  module Pwrake
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "socket"
2
+
1
3
  module Pwrake
2
4
 
3
5
  class GfarmDirectory < SharedDirectory
@@ -8,7 +10,7 @@ module Pwrake
8
10
  @@gfarm2fs_debug = nil
9
11
  @@gfarm2fs_debug_wait = 1
10
12
  @@current_id = 0
11
- @@hostname = `hostname`.chomp
13
+ @@hostname = Socket.gethostname
12
14
 
13
15
  def self.init(opts)
14
16
  @@prefix = opts[:base_dir]
@@ -57,7 +59,7 @@ module Pwrake
57
59
  path = @log.path
58
60
  begin
59
61
  if @@gfarm2fs_debug && path
60
- f = path+("gfarm2fs-"+`hostname`.chomp+"-"+@suffix)
62
+ f = path+("gfarm2fs-"+@@hostname+"-"+@suffix)
61
63
  spawn_cmd "gfarm2fs #{@@gfarm2fs_option} -d #{@gfarm_mountpoint} > #{f} 2>&1 & sleep #{@@gfarm2fs_debug_wait}"
62
64
  else
63
65
  spawn_cmd "gfarm2fs #{@@gfarm2fs_option} #{@gfarm_mountpoint}"
@@ -1,6 +1,7 @@
1
1
  require "singleton"
2
2
  require "forwardable"
3
3
  require "logger"
4
+ require "socket"
4
5
 
5
6
  module Pwrake
6
7
 
@@ -46,7 +47,7 @@ module Pwrake
46
47
  @dir = dir_class.new
47
48
  @dir.open
48
49
  @path = @dir.log_path
49
- fn = "worker-#{`hostname`.chomp}-#{Process.pid}.log"
50
+ fn = "worker-#{Socket.gethostname}-#{Process.pid}.log"
50
51
  @logfile = (@path + fn).to_s
51
52
  ::FileUtils.mkdir_p(@path.to_s)
52
53
  @logger = @logger_file = ::Logger.new(@logfile)
@@ -1,6 +1,7 @@
1
1
  require "thread"
2
2
  require "fileutils"
3
3
  require "timeout"
4
+ require "socket"
4
5
 
5
6
  begin
6
7
  Pwrake::Invoker.new.run
@@ -8,7 +9,7 @@ rescue => exc
8
9
  log = Pwrake::LogExecutor.instance
9
10
  log.error exc
10
11
  log.error exc.backtrace.join("\n")
11
- open("pwrake_worker_err-#{ENV['USER']}-#{Process.pid}","w") do |f|
12
+ open("pwrake_worker_err-#{Socket.gethostname}-#{Process.pid}","w") do |f|
12
13
  f.puts exc
13
14
  f.puts exc.backtrace.join("\n")
14
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwrake
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel