From 7482dfd8335f6d8a5f978c365cf16ed0c5b2728d Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Wed, 14 Feb 2024 11:05:09 -0500 Subject: [PATCH 1/2] Set minimum interval to 10 --- lib/flipper/poller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/flipper/poller.rb b/lib/flipper/poller.rb index 29bdaef44..f845310e5 100644 --- a/lib/flipper/poller.rb +++ b/lib/flipper/poller.rb @@ -20,6 +20,8 @@ def self.reset instances.each {|_, instance| instance.stop }.clear end + MINIMUM_POLL_INTERVAL = 10 + def initialize(options = {}) @thread = nil @pid = Process.pid @@ -30,9 +32,9 @@ def initialize(options = {}) @last_synced_at = Concurrent::AtomicFixnum.new(0) @adapter = Adapters::Memory.new(nil, threadsafe: true) - if @interval < 1 - warn "Flipper::Cloud poll interval must be greater than or equal to 1 but was #{@interval}. Setting @interval to 1." - @interval = 1 + if @interval < MINIMUM_POLL_INTERVAL + warn "Flipper::Cloud poll interval must be greater than or equal to #{MINIMUM_POLL_INTERVAL} but was #{@interval}. Setting @interval to #{MINIMUM_POLL_INTERVAL}." + @interval = MINIMUM_POLL_INTERVAL end @start_automatically = options.fetch(:start_automatically, true) From 2fb4cb9f14c0099c1bd0acc84562efedd6b72205 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Wed, 14 Feb 2024 11:06:32 -0500 Subject: [PATCH 2/2] More sleep time between polls Before we were trying to ensure it was interval or as fast as the request took. This is an issue if we are struggling to serve requests as it increases throughput when requests are slow instead of slowing them down. Need to probably back off even more if response time is more than 10 seconds but can look at that later. --- lib/flipper/poller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/flipper/poller.rb b/lib/flipper/poller.rb index f845310e5..30a74cdaf 100644 --- a/lib/flipper/poller.rb +++ b/lib/flipper/poller.rb @@ -66,8 +66,7 @@ def run # you can instrument these using poller.flipper end - sleep_interval = interval - (Concurrent.monotonic_time - start) - sleep sleep_interval if sleep_interval.positive? + sleep interval end end