Commit 4692abaa authored by David H. Wilkins's avatar David H. Wilkins

Stop environments from needless refreshes

Currently, Environment has the following ReactiveCache setting:

- reactive_cache_refresh_interval = 1.minute (Default Value)
- reactive_cache_lifetime = 10.minutes (Default Value)

This causes ReactiveCacheWorker to run at least 10 times before the
lifetime of the `:active` key expires.

When ReactiveCache receives a request for a currently `:active`
request, the active request is expires time is reset to
`reactive_cache_lifetime` from the current time - meaning that the
redis keys will always stay active while they are being requested.

Changing the values to:

- reactive_cache_refresh_interval = 1.minute
- reactive_cache_lifetime = 55.seconds

will cause the lifetime of the `:active` key to expire sooner than the
ReactiveCacheWorker runs only if the value key has not been requested
in the interim. If the user has navigated away from the page, the
ReactiveCacheWorker will NOT continue to refresh the data for 10
minutes.  The next execution of the ReactiveCacheWorker will be the
last one.

I left the refresh interval at 1.minute since our users probably
expect to get refreshes on 1 minute intervals.
parent e6b4a14f
...@@ -4,6 +4,9 @@ class Environment < ApplicationRecord ...@@ -4,6 +4,9 @@ class Environment < ApplicationRecord
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include ReactiveCaching include ReactiveCaching
self.reactive_cache_refresh_interval = 1.minute
self.reactive_cache_lifetime = 55.seconds
belongs_to :project, required: true belongs_to :project, required: true
has_many :deployments, -> { visible }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :deployments, -> { visible }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
......
...@@ -744,6 +744,12 @@ describe Environment, :use_clean_rails_memory_store_caching do ...@@ -744,6 +744,12 @@ describe Environment, :use_clean_rails_memory_store_caching do
allow(environment).to receive(:deployment_platform).and_return(double) allow(environment).to receive(:deployment_platform).and_return(double)
end end
context 'reactive cache configuration' do
it 'does not continue to spawn jobs' do
expect(described_class.reactive_cache_lifetime).to be < described_class.reactive_cache_refresh_interval
end
end
context 'reactive cache is empty' do context 'reactive cache is empty' do
before do before do
stub_reactive_cache(environment, nil) stub_reactive_cache(environment, nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment