Skip to content

Commit 6d598df

Browse files
committed
Use exponential backoff
1 parent 309ea8f commit 6d598df

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ module Redis
1010

1111
class << self
1212
attr_accessor :requeue_offset
13+
attr_accessor :max_sleep_time
1314
end
1415
self.requeue_offset = 42
16+
self.max_sleep_time = 2
1517

1618
class Worker < Base
19+
DEFAULT_SLEEP_SECONDS = 0.5
1720
attr_reader :total
1821

1922
def initialize(redis, config)
@@ -81,8 +84,10 @@ def poll
8184
end
8285
idle_since = nil
8386
idle_state_printed = false
87+
attempt = 0
8488
until shutdown_required? || config.circuit_breakers.any?(&:open?) || exhausted? || max_test_failed?
8589
if id = reserve
90+
attempt = 0
8691
idle_since = nil
8792
executable = resolve_executable(id)
8893

@@ -111,7 +116,11 @@ def poll
111116
end
112117
idle_state_printed = true
113118
end
114-
sleep 0.05
119+
# Adding exponential backoff to avoid hammering Redis
120+
# we just stay online here in case a test gets retried or times out so we can afford to wait
121+
sleep_time = [DEFAULT_SLEEP_SECONDS * (2 ** attempt), Redis.max_sleep_time].min
122+
attempt += 1
123+
sleep sleep_time
115124
end
116125
end
117126
redis.pipelined do |pipeline|

0 commit comments

Comments
 (0)