Skip to content

Commit 567b5db

Browse files
committed
[CI] slow down fast-duration converge
1 parent dbe8b01 commit 567b5db

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ module CI
44
module Queue
55
module Redis
66
class UpdateTestDurationMovingAverage
7-
def initialize(redis, key: "test_duration_moving_averages", smoothing_factor: 0.2)
7+
def initialize(redis, key: 'test_duration_moving_averages', smoothing_factor: 0.2, slow_smoothing_factor: 0.01)
88
@redis = redis
99
@key = key
1010
@smoothing_factor = smoothing_factor
11+
@slow_smoothing_factor = slow_smoothing_factor
1112
end
1213

1314
def update_batch(pairs)
@@ -20,10 +21,13 @@ def update_batch(pairs)
2021
pairs.each_with_index do |(test_id, duration), idx|
2122
current = current_values[idx]
2223
new_avg = if current
23-
@smoothing_factor * duration + (1 - @smoothing_factor) * current.to_f
24-
else
25-
duration
26-
end
24+
current_avg = current.to_f
25+
# Use slow smoothing if new duration is faster (shorter), fast smoothing if slower (longer)
26+
factor = duration < current_avg ? @slow_smoothing_factor : @smoothing_factor
27+
factor * duration + (1 - factor) * current_avg
28+
else
29+
duration
30+
end
2731
writes << [test_id, new_avg]
2832
end
2933

0 commit comments

Comments
 (0)