From 624bea144523777c1830f307ecfd218fc927caeb Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Wed, 27 Jan 2016 13:23:23 +0000 Subject: Use the ceiling instead of the floor when calculating the desired number of jobs If the number of jobs is large enough, using the floor won't guarantee completion within the desired interval. Example: - interval: 3600 - average duration: 5 - number of nodes: 900 This gives 1.25 as the desired number of threads. Flooring it means that nodes will only be collected once every ~75 minutes. By using the ceiling and slightly over-estimating the desired interval is achieved --- lib/oxidized/jobs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index ff7f92b..60a83f4 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -26,7 +26,7 @@ module Oxidized end def new_count - @want = ((@nodes.size * @duration) / @interval).to_i + @want = ((@nodes.size * @duration) / @interval).ceil @want = 1 if @want < 1 @want = @nodes.size if @want > @nodes.size @want = @max if @want > @max -- cgit v1.2.1 From 8cef62390cdfbff723e2d6b99fd92157406e17d5 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Wed, 27 Jan 2016 14:42:58 +0000 Subject: If a reload operation changes the number of nodes, ensure @durations is updated Otherwise the average duration calculation will be wrong --- lib/oxidized/jobs.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/oxidized') diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index 60a83f4..2c656f6 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -20,6 +20,11 @@ module Oxidized end def duration last + if @durations.size > @nodes.size + @durations.slice! @nodes.size...@durations.size + elsif @durations.size < @nodes.size + @durations.fill AVERAGE_DURATION, @durations.size...@nodes.size + end @durations.push(last).shift @duration = @durations.inject(:+).to_f / @nodes.size #rolling average new_count -- cgit v1.2.1 From 071ba09110fccd845995a9eecdf35e544662daf1 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Wed, 27 Jan 2016 14:46:58 +0000 Subject: Sort the nodes by last update on reload Reloading sets the node queue to the original order. If Oxidized was restarted, collected a couple of nodes, and was then reloaded, the new queue would have a node with a recent last end time. Thus, no new nodes would be collected until the first one passed its interval. Here the nodes are sorted on reload, to maintain the queue invariant. --- lib/oxidized/nodes.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/oxidized') diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 0c02d7a..61d2d44 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -147,6 +147,7 @@ module Oxidized rescue Oxidized::NodeNotFound end end + sort_by! { |x| x.last.nil? ? Time.new(0) : x.last.end } end public -- cgit v1.2.1