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

Research performance impact of directing Sch A traffic to one replica #4038

Closed
8 of 9 tasks
lbeaufort opened this issue Oct 24, 2019 · 0 comments
Closed
8 of 9 tasks
Assignees

Comments

@lbeaufort
Copy link
Member

lbeaufort commented Oct 24, 2019

We should research the performance impact of directing Sch A traffic to one replica and everything else to the other. The idea came from the notion of schedule A “hogging” resources from all the other queries. We could use the queries/activity levels from the outage drill to test before/after.

We probably want to look at RoutingSession

class RoutingSession(SignallingSession):
"""Route requests to database leader or follower as appropriate.
Based on http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/
"""
@property
def followers(self):
return self.app.config['SQLALCHEMY_FOLLOWERS']
@property
def follower_tasks(self):
return self.app.config['SQLALCHEMY_FOLLOWER_TASKS']
@property
def restrict_follower_traffic_to_tasks(self):
return self.app.config['SQLALCHEMY_RESTRICT_FOLLOWER_TRAFFIC_TO_TASKS']
@property
def use_follower(self):
# Check for read operations and configured followers.
use_follower = (
not self._flushing and
len(self.followers) > 0
)
# Optionally restrict traffic to followers for only supported tasks.
if use_follower and self.restrict_follower_traffic_to_tasks:
use_follower = (
celery.current_task and
celery.current_task.name in self.follower_tasks
)
return use_follower
def get_bind(self, mapper=None, clause=None):
if self.use_follower:
return random.choice(self.followers)
return super().get_bind(mapper=mapper, clause=clause)

This looks doable in theory: https://github.com/fecgov/openFEC/pull/4048/files
Need to set SQLA_FOLLOWERS env var to test

Completion criteria:

Summary of results
Negative impact on Schedule A performance outweighs the improved performance of other endpoints. While this could be a stopgap measure to "quarantine" schedule A data, it's not a good long-term solution. Per @PaulClark2 I'm going to make a wiki with step-by-step instructions on spinning up another read replica in production, which would yield better results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant