summaryrefslogtreecommitdiff
path: root/lib/oxidized/jobs.rb
diff options
context:
space:
mode:
authorFlorian Hibler <fhibler@users.noreply.github.com>2015-02-26 16:47:18 +0000
committerFlorian Hibler <fhibler@users.noreply.github.com>2015-02-26 16:47:18 +0000
commit1c85b3202033ed965abe16e15688f0b0025561ea (patch)
tree4ea9288b7a3dc774a60cdbd096761df4da147f8e /lib/oxidized/jobs.rb
parent19de2ac51cd765e1c7b7fe731759fb50086675b5 (diff)
parentdb165b5e1ebb3091a49029d739b68a913bc75db6 (diff)
Merge pull request #1 from ytti/master
Merge to latest
Diffstat (limited to 'lib/oxidized/jobs.rb')
-rw-r--r--lib/oxidized/jobs.rb32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb
index 6476744..ff7f92b 100644
--- a/lib/oxidized/jobs.rb
+++ b/lib/oxidized/jobs.rb
@@ -1,24 +1,46 @@
module Oxidized
class Jobs < Array
- attr_accessor :interval, :duration, :max, :want
+ AVERAGE_DURATION = 5 # initially presume nodes take 5s to complete
+ MAX_INTER_JOB_GAP = 300 # add job if more than X from last job started
+ attr_accessor :interval, :max, :want
+
def initialize max, interval, nodes
@max = max
- #@interval = interval * 60
@interval = interval
@nodes = nodes
- @duration = 4
- new_count
+ @last = Time.now.utc
+ @durations = Array.new @nodes.size, AVERAGE_DURATION
+ duration AVERAGE_DURATION
super()
end
+
+ def push arg
+ @last = Time.now.utc
+ super
+ end
+
def duration last
- @duration = (@duration + last) / 2
+ @durations.push(last).shift
+ @duration = @durations.inject(:+).to_f / @nodes.size #rolling average
new_count
end
+
def new_count
@want = ((@nodes.size * @duration) / @interval).to_i
@want = 1 if @want < 1
@want = @nodes.size if @want > @nodes.size
@want = @max if @want > @max
end
+
+ def work
+ # if a) we want less or same amount of threads as we now running
+ # and b) we want less threads running than the total amount of nodes
+ # and c) there is more than MAX_INTER_JOB_GAP since last one was started
+ # then we want one more thread (rationale is to fix hanging thread causing HOLB)
+ if @want <= size and @want < @nodes.size
+ @want +=1 if (Time.now.utc - @last) > MAX_INTER_JOB_GAP
+ end
+ end
+
end
end