Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll Memoizer #704

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Poll Memoizer #704

wants to merge 8 commits into from

Conversation

bkeepers
Copy link
Collaborator

@bkeepers bkeepers commented Mar 13, 2023

Currently, Flipper is configured by default to perform memoization and preloading per request, which will query the primary storage adapter each time a request is received. This is fine on a lot of apps, but can add some overhead on apps with heavy traffic.

This pull request adds a memoize = :poll configuration option:

# config/initializers/flipper.rb
Rails.application.configure do
-  config.flipper.memoize = true
+  config.flipper.memoize = :poll
end

Setting memoize = :poll will switch memoization to a new background thread polling strategy based on the Poll adapter introduced in #682. The Poll adapter will start a background thread that will load all features from the primary storage adapter into a Memory adapter on an interval. Flipper will then read from this Memory adapter instead of the primary storage adapter (it actually has multiple instances of the Memory adapter, one for the background, and then one for each app thread that is synchronized before each request).

TODO:

@adapter = if memoize == :poll
Adapters::Poll.new(Adapters::Memory.new, adapter,
key: 'memoizer',
interval: 5,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: make configurable

@adapter = adapter
@adapter = if memoize == :poll
Adapters::Poll.new(Adapters::Memory.new, adapter,
key: 'memoizer',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If multiple DSL instances are created with memoize: :poll and different adapters, this will not behave as expected. I wonder if Poller.get should also look for equality in the adapters. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the key just be unique per adapter?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather a better way to phrase that, is there a way to make the key unique per instance? We have the name. That would help with different adapters. Perhaps there is another way to add uniqueness per instance too... hmm

lib/flipper/adapters/poll.rb Show resolved Hide resolved
Base automatically changed from poll-improvements to main March 13, 2023 23:00
instrumenter: @instrumenter
).tap do |poll|
# Force poller to sync in current thread now
poll.poller.sync
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to make a method for this to avoid reaching into poller.

@bkeepers
Copy link
Collaborator Author

bkeepers commented Aug 1, 2023

I'm going to hold off on this for now since we're not using this adapter in production. Eventually I do think some kind of interval-based memoization (instead of request-based) will really help improve performance, but I'd like to think on it a bit.

@bkeepers bkeepers closed this Aug 1, 2023
@bkeepers bkeepers deleted the poll-memoizer branch August 1, 2023 15:01
@bkeepers bkeepers restored the poll-memoizer branch December 16, 2023 13:53
@bkeepers bkeepers reopened this Dec 16, 2023
* origin/main: (454 commits)
  Use flippercloud.io API, don't retry failures
  Move rails constants
  Show deprecation warning for Rails < 6.1.0
  Show deprecation warning for Ruby < 3.0
  UI: show a badge if a new release is available
  Use GitHub Releases for changelog
  Fix warning from script/bootstrap
  Prepare for 1.1.2 release
  Update Changelog
  Fix remove_index for older Rails versions
  Add length to update migration
  Create instead of purge before all
  Indifferent access for old Rails versions
  Fix rescue that may be obscuring errors on Actions
  Skip AR tests locally if db can't connect
  Add rails to readme like summary
  Add feature flag to summaries
  Duplicate postgres env config
  Move postgres env config
  Configure postgres and mysql on CI
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants