Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ module CI
module Queue
module Redis
class UpdateTestDurationMovingAverage
def initialize(redis, key: "test_duration_moving_averages", smoothing_factor: 0.2)
def initialize(redis, key: 'test_duration_moving_averages', smoothing_factor: 0.2, slow_smoothing_factor: 0.01)
@redis = redis
@key = key
@smoothing_factor = smoothing_factor
@slow_smoothing_factor = slow_smoothing_factor
end

def update_batch(pairs)
Expand All @@ -20,10 +21,13 @@ def update_batch(pairs)
pairs.each_with_index do |(test_id, duration), idx|
current = current_values[idx]
new_avg = if current
@smoothing_factor * duration + (1 - @smoothing_factor) * current.to_f
else
duration
end
current_avg = current.to_f
# Use slow smoothing if new duration is faster (shorter), fast smoothing if slower (longer)
factor = duration < current_avg ? @slow_smoothing_factor : @smoothing_factor
factor * duration + (1 - factor) * current_avg
else
duration
end
writes << [test_id, new_avg]
end

Expand Down