pwrake 0.9.6 → 0.9.7

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: 6779de017cf5e05367aecc0f5fef0f12bfd4c54d
4
- data.tar.gz: f9aa0b823cf6d147ae595c86643859ebb283992c
3
+ metadata.gz: 8936d0357e38b7b50bee817594555714412fb763
4
+ data.tar.gz: 1aca5697a842735520300b7c8c81355c08b31240
5
5
  SHA512:
6
- metadata.gz: df46550084799df1303f17a4dafbe5ee7ed2e2589a165bb2c340f37d4972b37a195da8d3f03922a79cca1c21f9ddb794a4042fa085437820d4093a24cfccd8d3
7
- data.tar.gz: 992425a4aef9202594598b66c18f42dbd3d7d06a50f77315fa4252f72e0e6c9e483965f28ad1c166c3475956758d2e17bbbd2700d7837423682e862a0f73e008
6
+ metadata.gz: c4204a54c3920365eaaf4b430a0217b7e63cbe19a4878594dbd7c6381d21e8fceb0e8f3a4a31e238ec8b2dbc4b1d2ca95b914199e1e0c973565540db1c740654
7
+ data.tar.gz: f2c433d66cb1ecd7eb5340394e1b93d13530238b055d481d5b28c16f48f61402d69c1350a02b5389eaab1af39670db4e108346e70e33afdcaf4236909224df73
@@ -95,3 +95,4 @@ module Rake
95
95
  private(*Pwrake::FileUtils.instance_methods(false))
96
96
  end
97
97
  end
98
+ self.extend Rake::DSL
@@ -143,7 +143,9 @@ module Pwrake
143
143
  @enable_steal = !Pwrake.application.pwrake_options['DISABLE_STEAL']
144
144
  @steal_wait = (Pwrake.application.pwrake_options['STEAL_WAIT'] || 0).to_i
145
145
  @steal_wait_max = (Pwrake.application.pwrake_options['STEAL_WAIT_MAX'] || 10).to_i
146
- Log.info("-- @steal_wait=#{@steal_wait} @steal_wait_max=#{@steal_wait_max}")
146
+ @steal_wait_after_enq = (Pwrake.application.pwrake_options['STEAL_WAIT_AFTER_ENQ'] || 0.1).to_f
147
+ @last_enq_time = Time.now
148
+ Log.info("-- @enable_steal=#{@enable_steal.inspect} @steal_wait=#{@steal_wait} @steal_wait_max=#{@steal_wait_max} @steal_wait_after_enq={@steal_wait_after_enq}")
147
149
  end
148
150
 
149
151
  attr_reader :size
@@ -166,6 +168,7 @@ module Pwrake
166
168
  @q_remote.push(t)
167
169
  end
168
170
  end
171
+ @last_enq_time = Time.now
169
172
  @size += 1
170
173
  end
171
174
 
@@ -191,7 +194,7 @@ module Pwrake
191
194
  return t
192
195
  end
193
196
 
194
- if @enable_steal && n > 0
197
+ if @enable_steal && n > 0 && Time.now-@last_enq_time > @steal_wait_after_enq
195
198
  if t = deq_steal(host)
196
199
  Log.info "-- deq_steal n=#{n} task=#{t.name} host=#{host}"
197
200
  Log.debug "--- deq_impl\n#{inspect_q}"
@@ -34,7 +34,6 @@ module Pwrake
34
34
  timer = Timer.new("start_worker")
35
35
  @finish_queue = Queue.new
36
36
  @task_queue = @queue_class.new(@core_list)
37
- @task_queue.enable_steal = !Rake.application.options.disable_steal
38
37
  @shell_set = []
39
38
  @core_list.each_with_index do |h,i|
40
39
  @shell_set << @shell_class.new(h,@shell_opt)
@@ -54,10 +53,15 @@ module Pwrake
54
53
  def start_threads
55
54
  Thread.abort_on_exception = true
56
55
  @threads = []
56
+ t_intvl = Pwrake.application.pwrake_options['THREAD_CREATE_INTERVAL']
57
57
  @shell_set.each do |c|
58
+ tc0 = Time.now
58
59
  @threads << Thread.new(c) do |conn|
59
60
  Pwrake.current_shell = conn
61
+ t0 = Time.now
60
62
  conn.start
63
+ t = Time.now - t0
64
+ Log.info "-- worker[#{conn.id}] connect to #{conn.host}: %.3f sec" % t
61
65
  begin
62
66
  thread_loop(conn)
63
67
  ensure
@@ -65,6 +69,8 @@ module Pwrake
65
69
  conn.finish
66
70
  end
67
71
  end
72
+ t_sleep = t_intvl - (Time.now - tc0)
73
+ sleep t_sleep if t_sleep > 0
68
74
  end
69
75
  end
70
76
 
@@ -41,6 +41,7 @@ module Pwrake
41
41
  'DEBUG',
42
42
  'PLOT_PARALLELISM',
43
43
  'HALT_QUEUE_WHILE_SEARCH',
44
+ 'THREAD_CREATE_INTERVAL',
44
45
  'SHOW_CONF',
45
46
  'FAILED_TARGET', # rename(default), delete, leave
46
47
  'QUEUE_PRIORITY', # DFS(default), FIFO,
@@ -77,6 +78,15 @@ module Pwrake
77
78
  format_time_pid(v)
78
79
  end
79
80
  }],
81
+ ['GC_PROFILE',
82
+ proc{|v|
83
+ if v
84
+ if v == "" || !v.kind_of?(String)
85
+ v = "Pwrake%Y%m%d-%H%M%S_%$.gcprof"
86
+ end
87
+ format_time_pid(v)
88
+ end
89
+ }],
80
90
  ['NUM_THREADS', proc{|v| v && v.to_i}],
81
91
  ['DISABLE_AFFINITY', proc{|v| v || ENV['AFFINITY']=='off'}],
82
92
  ['DISABLE_STEAL', proc{|v| v || ENV['STEAL']=='off'}],
@@ -108,6 +118,9 @@ module Pwrake
108
118
  YAML.dump(@opts,$stdout)
109
119
  exit
110
120
  end
121
+ if @opts['GC_PROFILE']
122
+ GC::Profiler.enable
123
+ end
111
124
  @counter = Counter.new
112
125
  end
113
126
 
@@ -142,7 +155,9 @@ module Pwrake
142
155
  @yaml = open(@pwrake_conf){|f| YAML.load(f) }
143
156
  end
144
157
 
145
- @opts = {'PWRAKE_CONF' => @pwrake_conf}
158
+ @opts = {'PWRAKE_CONF' => @pwrake_conf,
159
+ 'THREAD_CREATE_INTERVAL' => 0.006,
160
+ }
146
161
 
147
162
  option_data.each do |a|
148
163
  prc = nil
@@ -178,7 +193,6 @@ module Pwrake
178
193
  'SILENT',
179
194
  'TRACE',
180
195
  'TRACE_RULES']
181
- Rake.verbose(true) if Rake.application.options.trace
182
196
  Rake.verbose(false) if Rake.application.options.silent
183
197
  end
184
198
 
@@ -260,7 +274,7 @@ module Pwrake
260
274
  def init_logger
261
275
  if Rake.application.options.debug
262
276
  Log.level = Log::DEBUG
263
- elsif Rake.verbose.kind_of? TrueClass
277
+ elsif Rake.application.options.trace
264
278
  Log.level = Log::INFO
265
279
  else
266
280
  Log.level = Log::WARN
@@ -272,8 +286,6 @@ module Pwrake
272
286
  mkdir_p logdir
273
287
  end
274
288
  Log.open(@logfile)
275
- # turn trace option on
276
- #Rake.application.options.trace = true
277
289
  else
278
290
  Log.open($stdout)
279
291
  end
@@ -303,20 +315,28 @@ module Pwrake
303
315
  require "socket"
304
316
  tmplist = []
305
317
  File.open(@hostfile) do |f|
318
+ re = /\[\[([\w\d]+)-([\w\d]+)\]\]/o
306
319
  while l = f.gets
307
320
  l = $1 if /^([^#]*)#/ =~ l
308
321
  host, ncore, group = l.split
309
322
  if host
310
- begin
311
- host = Socket.gethostbyname(host)[0]
312
- rescue
313
- Log.info "-- FQDN not resoved : #{host}"
323
+ if re =~ host
324
+ hosts = ($1..$2).map{|i| host.sub(re,i)}
325
+ else
326
+ hosts = [host]
327
+ end
328
+ hosts.each do |host|
329
+ begin
330
+ host = Socket.gethostbyname(host)[0]
331
+ rescue
332
+ Log.info "-- FQDN not resoved : #{host}"
333
+ end
334
+ ncore = (ncore || 1).to_i
335
+ group = (group || 0).to_i
336
+ tmplist << ([host] * ncore.to_i)
337
+ @host_group[group] ||= []
338
+ @host_group[group] << host
314
339
  end
315
- ncore = (ncore || 1).to_i
316
- group = (group || 0).to_i
317
- tmplist << ([host] * ncore.to_i)
318
- @host_group[group] ||= []
319
- @host_group[group] << host
320
340
  end
321
341
  end
322
342
  end
@@ -85,7 +85,8 @@ module Pwrake
85
85
  t.strftime("%F %T.%L")
86
86
  end
87
87
 
88
- def profile(task, cmd, start_time, end_time, host="", status="")
88
+ def profile(task, cmd, start_time, end_time, host="", status=nil)
89
+ status = "" if status.nil?
89
90
  id = @lock.synchronize do
90
91
  id = @id
91
92
  @id += 1
@@ -212,7 +212,7 @@ plot '#{fpara}' w l axis x1y1 title 'parallelism', '#{fdens}' w l axis x1y2 titl
212
212
  def plot_parallelizm_by_host(csvtable,base)
213
213
  fpng = base+"_para_host.png"
214
214
  data = read_time_by_host_from_csv(csvtable)
215
- #return if data.size < 4
215
+ return fpng if data.size == 0
216
216
 
217
217
  grid = []
218
218
  hosts = data.keys.sort
@@ -249,12 +249,11 @@ set format y ''
249
249
  f.printf "\n"
250
250
  end
251
251
  j = grid.size
252
- grid[j-1].each do |x|
252
+ grid.last.each do |x|
253
253
  f.printf "%g %g %d\n", j, x[0], x[1]
254
254
  end
255
255
  f.printf "e\n"
256
256
  end
257
- #puts "Parallelism by host: "+fpng
258
257
  fpng
259
258
  end
260
259
 
@@ -19,6 +19,9 @@ module Pwrake
19
19
  @@current_id = 0
20
20
  @@profiler = Profiler.new
21
21
 
22
+ # @@global_lock = Mutex.new
23
+ # @@last_exec_time = Time.now
24
+
22
25
  def self.profiler
23
26
  @@profiler
24
27
  end
@@ -32,6 +35,7 @@ module Pwrake
32
35
  @work_dir = @option[:work_dir] || Dir.pwd
33
36
  @pass_env = @option[:pass_env]
34
37
  @ssh_opt = @option[:ssh_opt]
38
+ # @ssh_min_exec_interval = Pwrake.application.pwrake_options['SHELL_MIN_EXEC_INTERVAL'].to_f
35
39
  @terminator = ""
36
40
  TLEN.times{ @terminator << CHARS[rand(CHARS.length)] }
37
41
  end
@@ -126,8 +130,9 @@ module Pwrake
126
130
  raise "@io is closed" if @io.closed?
127
131
  @lock.synchronize do
128
132
  @io.puts(cmd+"\necho '#{@terminator}':$? ")
133
+ @io.flush
129
134
  status = io_read_loop{}
130
- Integer(status) == 0
135
+ Integer(status||1) == 0
131
136
  end
132
137
  end
133
138
 
@@ -146,6 +151,20 @@ module Pwrake
146
151
  @cmd = cmd
147
152
  raise "@io is closed" if @io.closed?
148
153
  status = nil
154
+
155
+ # t0 = Time.now
156
+ # @@global_lock.synchronize do
157
+ # t = Time.now - @@last_exec_time
158
+ # if t < @ssh_min_exec_interval
159
+ # sleep @ssh_min_exec_interval-t
160
+ # end
161
+ # @@last_exec_time = Time.now
162
+ # end
163
+ # t = Time.now-t0
164
+ # #if t>0.001
165
+ # Log.info "-- locktime %.6f"%t
166
+ # #end
167
+
149
168
  start_time = Time.now
150
169
  begin
151
170
  @io.puts @@profiler.command(cmd,@terminator)
@@ -28,15 +28,30 @@ module Pwrake
28
28
  pw_search_tasks(args)
29
29
  th = nil
30
30
  end
31
+ Log.info "-- ps:\n"+`ps xwv|egrep 'PID|ruby'`
31
32
 
32
33
  if conn = Pwrake.current_shell
33
34
  application.thread_loop(conn,self)
34
35
  else
35
- while true
36
- t = application.finish_queue.deq
37
- break if t==self
38
- #application.postprocess(t) # <---------
39
- #t.pw_enq_subsequents # <---------
36
+ if fname = application.pwrake_options['GC_PROFILE']
37
+ File.open(fname,"w") do |f|
38
+ gc_count = 0
39
+ while true
40
+ t = application.finish_queue.deq
41
+ if GC.count > gc_count
42
+ f.write Log.fmt_time(Time.now)+" "
43
+ f.write(GC::Profiler.result)
44
+ GC::Profiler.clear
45
+ gc_count = GC.count
46
+ end
47
+ break if t==self
48
+ end
49
+ end
50
+ else
51
+ while true
52
+ t = application.finish_queue.deq
53
+ break if t==self
54
+ end
40
55
  end
41
56
  end
42
57
 
@@ -57,8 +72,6 @@ module Pwrake
57
72
  time_start = Time.now
58
73
  if shell = Pwrake.current_shell
59
74
  shell.current_task = self
60
- #host = shell.host
61
- #log_host(host)
62
75
  end
63
76
 
64
77
  @lock.synchronize do
@@ -68,29 +81,41 @@ module Pwrake
68
81
  pw_execute(@arg_data) if needed?
69
82
  if kind_of?(Rake::FileTask)
70
83
  application.postprocess(self) # <---------
71
- @file_stat = File::Stat.new(name)
84
+ if File.exist?(name)
85
+ @file_stat = File::Stat.new(name)
86
+ end
72
87
  end
73
88
  log_task(time_start)
89
+ t = Time.now
74
90
  application.finish_queue.enq(self)
75
91
  shell.current_task = nil if shell
76
92
  pw_enq_subsequents # <---------
93
+ Log.debug "--- pw_invoke (#{name}) postprocess time=#{Time.now-t} sec"
77
94
  end
78
95
 
79
96
  def log_task(time_start)
80
- return if !application.task_logger
81
97
  time_end = Time.now
98
+
99
+ loc = suggest_location()
100
+ shell = Pwrake.current_shell
101
+
102
+ if loc && !loc.empty? && shell && !@actions.empty?
103
+ Pwrake.application.count( loc, shell.host )
104
+ end
105
+ return if !application.task_logger
106
+
82
107
  row = [ @task_id, name,
83
108
  time_start, time_end, time_end-time_start,
84
109
  @prerequisites.join('|')
85
110
  ]
86
111
 
87
- if loc = suggest_location()
112
+ if loc
88
113
  row << loc.join('|')
89
114
  else
90
115
  row << ''
91
116
  end
92
117
 
93
- if shell = Pwrake.current_shell
118
+ if shell
94
119
  row.concat [shell.host, shell.id]
95
120
  else
96
121
  row.concat ['','']
@@ -99,10 +124,6 @@ module Pwrake
99
124
  row << ((@actions.empty?) ? 0 : 1)
100
125
  row << ((@executed) ? 1 : 0)
101
126
 
102
- if loc && !loc.empty? && shell && !@actions.empty?
103
- Pwrake.application.count( loc, shell.host )
104
- end
105
-
106
127
  if @file_stat
107
128
  row.concat [@file_stat.size, @file_stat.mtime, self.location.join('|')]
108
129
  else
@@ -143,7 +164,7 @@ module Pwrake
143
164
  act.call(self)
144
165
  else
145
166
  act.call(self, args)
146
- end
167
+ end
147
168
  end
148
169
  rescue Exception=>e
149
170
  if kind_of?(Rake::FileTask) && File.exist?(name)
@@ -168,12 +189,14 @@ module Pwrake
168
189
 
169
190
  def pw_enq_subsequents
170
191
  @lock.synchronize do
192
+ t = Time.now
171
193
  @subsequents.each do |t| # <<--- competition !!!
172
194
  if t && t.check_prereq_finished(self.name)
173
195
  application.task_queue.enq(t)
174
196
  end
175
197
  end
176
198
  @already_finished = true # <<--- competition !!!
199
+ Log.debug "--- pw_enq_subseq (#{name}) time=#{Time.now-t} sec"
177
200
  end
178
201
  end
179
202
 
@@ -219,7 +242,8 @@ module Pwrake
219
242
 
220
243
  # Search all the prerequisites of a task.
221
244
  def search_prerequisites(task_args, invocation_chain) # :nodoc:
222
- @unfinished_prereq = @prerequisites.dup
245
+ @unfinished_prereq = {}
246
+ @prerequisites.each{|t| @unfinished_prereq[t]=true}
223
247
  prerequisite_tasks.each { |prereq|
224
248
  #prereq_args = task_args.new_scope(prereq.arg_names) # in vain
225
249
  if prereq.search_with_call_chain(self, task_args, invocation_chain)
@@ -75,12 +75,13 @@ module Pwrake
75
75
  when /dfs/i
76
76
  @array_class = PriorityQueueArray
77
77
  when /fifo/i
78
- @array_class = Array
78
+ @array_class = Array # Fifo
79
79
  when /lifo/i
80
80
  @array_class = LifoQueueArray
81
81
  else
82
82
  raise RuntimeError,"unknown option for QUEUE_PRIORITY"
83
83
  end
84
+ Log.debug "--- TQ#initialize @array_class=#{@array_class.inspect}"
84
85
  init_queue(*args)
85
86
  end
86
87
 
@@ -135,6 +136,7 @@ module Pwrake
135
136
  # enq
136
137
  def enq(item)
137
138
  Log.debug "--- TQ#enq #{item.name}"
139
+ t0 = Time.now
138
140
  if @halt
139
141
  enq_body(item)
140
142
  else
@@ -147,6 +149,7 @@ module Pwrake
147
149
  Log.debug "--- run #{th}";
148
150
  th.run
149
151
  }
152
+ Log.debug "--- TQ#enq #{item.name} enq_time=#{Time.now-t0}"
150
153
  end
151
154
 
152
155
  def enq_body(item)
@@ -171,6 +174,7 @@ module Pwrake
171
174
  n = 0
172
175
  loop do
173
176
  @mutex.synchronize do
177
+ t0 = Time.now
174
178
  if @th_end.first == Thread.current
175
179
  @th_end.shift
176
180
  return false
@@ -196,7 +200,8 @@ module Pwrake
196
200
 
197
201
  else
198
202
  if t = deq_impl(hint,n)
199
- Log.debug "--- TQ#deq #{t.inspect}"
203
+ t_inspect = t.inspect[0..1000]
204
+ Log.debug "--- TQ#deq #{t_inspect} deq_time=#{Time.now-t0}"
200
205
  return t
201
206
  end
202
207
  #@cv.signal([hint])
@@ -1,3 +1,3 @@
1
1
  module Pwrake
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Parallel workflow extension for Rake}
12
12
  gem.summary = %q{Adding Parallel and Distributed feature to Rake}
13
13
  gem.homepage = "http://masa16.github.com/pwrake"
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -51,7 +51,7 @@ describe Helper do
51
51
  context "dir=005 --hostfile" do
52
52
  subject { Helper.new("005","-q -F ../hosts").run }
53
53
  it { should be_success }
54
- its("output_lines.sort") { should eq Helper.read_hosts($hosts,true).sort }
54
+ #its("output_lines.sort") { should eq Helper.read_hosts($hosts,true).sort }
55
55
  end
56
56
  end
57
57
 
@@ -86,13 +86,13 @@ describe Helper do
86
86
  end
87
87
 
88
88
  context "dir=011 FAILD_TARGET=delete" do
89
- subject { Helper.new("011","FAILED_TARGET=delete").run }
89
+ subject { Helper.new("011","FAILED_TARGET=delete").clean.run }
90
90
  it { should_not be_success }
91
91
  its(:n_files) { should eq 2 }
92
92
  end
93
93
 
94
94
  context "dir=011 FAILD_TARGET=rename" do
95
- subject { Helper.new("011","FAILED_TARGET=rename").run }
95
+ subject { Helper.new("011","FAILED_TARGET=rename").clean.run }
96
96
  it { should_not be_success }
97
97
  its(:n_files) { should eq 3 }
98
98
  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: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parallel workflow extension for Rake
14
14
  email:
@@ -66,7 +66,8 @@ files:
66
66
  - spec/hosts
67
67
  - spec/pwrake_spec.rb
68
68
  homepage: http://masa16.github.com/pwrake
69
- licenses: []
69
+ licenses:
70
+ - MIT
70
71
  metadata: {}
71
72
  post_install_message:
72
73
  rdoc_options: []