From 567b5db197d67ace6ed83057ebaee0acd5bd9394 Mon Sep 17 00:00:00 2001 From: Lihao He Date: Mon, 1 Dec 2025 17:40:00 -0800 Subject: [PATCH] [CI] slow down fast-duration converge --- .../redis/update_test_duration_moving_average.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb b/ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb index 7a472f2..a37822f 100644 --- a/ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb +++ b/ruby/lib/ci/queue/redis/update_test_duration_moving_average.rb @@ -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) @@ -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