-
Notifications
You must be signed in to change notification settings - Fork 71
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
Added the ability to separate out reads and writes into their own connection pools. #344
Conversation
|
||
>``` | ||
> USE_SEPARATE_READER_POOL = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am looking for something exactly like this PR. This variable seems a bit redundant. It could simply be:
USE_SEPARATE_READER_POOL = bool(MF_METADATA_DB_READ_REPLICA_HOST)
thus disabling the feature if no host is given and implicitly turning it on if one is given. This would also prevent the case where this is set to true and no host is given.
4cfbb2b
to
bf42469
Compare
services/utils/__init__.py
Outdated
@@ -196,7 +206,8 @@ def __init__(self, | |||
prefix="MF_METADATA_DB_", | |||
pool_min: int = 1, | |||
pool_max: int = 10, | |||
timeout: int = 60): | |||
timeout: int = 60, | |||
read_replica_host: str = "localhost"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using localhost here as a default could lead to odd issues if the USE_SEPARATE_READER_POOL
is set but the host has not been set. I would lean towards using the existence of [PREFIX]_READ_REPLICA_HOST
as a feature gate directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed read_replica_host
some testing notes: validated the PR by running a read replica locally. Basic operations seem to be working as intended. Only pending concern is with the unrelated changes in the diff, which seem to stem from other open PR's not yet in |
16832a3
to
12209c9
Compare
…endpoints choosing the right pool in execute_sql
3019760
to
4c7c1b4
Compare
services/utils/__init__.py
Outdated
from functools import wraps | ||
from typing import Dict | ||
import logging | ||
import psycopg2 | ||
from packaging.version import Version, parse | ||
|
||
USE_SEPARATE_READER_POOL = os.environ.get("USE_SEPARATE_READER_POOL", "0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be cast to a boolean instead to make using it a bit cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also echo the comment that @dhpollack made on the need for a separate toggle for the reader pool, vs. simply looking at the existence of the MF_METADATA_DB_READ_REPLICA_HOST
? This would cut down on the environment variables required to configure the feature as well.
The reader pool has a fallback to the default host if a read replica host is not configured. Is it a valid use case to want a separate reader pool if we're targeting only one host? wouldn't increasing the pool size serve the same purpose in this case?
This remediates this by considering a run 'failed' if the hb hasn't been updated within heartbeat_cutoff time as opposed to the heartbeat_threshold time
Would be interested in the functionality in this PR Any idea on the status of it? Seems there have been some open comments for a long time. @pjoshi30 @wangchy27 You are still interested in this PR? |
* Upgrade Github actions used in `dockerimage` action (#379) * upgrade github actions used in dockerimage action * remove setup-buildx-action and pin to hashes. * change deprecated pkg_resources to importlib.metadata (#387) * In a previous commit, the detection of a failure became too aggressive. (#386) * In a previous commit, the detection of a failure became too aggressive. This remediates this by considering a run 'failed' if the hb hasn't been updated within heartbeat_cutoff time as opposed to the heartbeat_threshold time * change run finished at query to heartbeat_cutoff from threshold * clean up unused values from run query --------- Co-authored-by: Sakari Ikonen <sakari.a.ikonen@gmail.com> * fix PATH_PREFIX handling in metadata service so it doesn't interfere with mfgui routes (#388) * Configurable SSL Connection (#373) * [TRIS-297] Configurable SSL Connection (#1) * Configurable SSL connection * Update services/utils/__init__.py * no ssl unit testing (#3) * ssl seperate test (#4) * dsn generator sslmode none (#5) * fix run_goose.py not working without SSL mode env variables. (#390) * change run inactive cutoff default to 6 minutes. cleanup unused constant (#392) * clarify comment on read replica hosts * make USE_SEPARATE_READER_POOL a boolean * remove unnecessary conditionals for pool choice in execute_sql --------- Co-authored-by: Tom Furmston <tfurmston@googlemail.com> Co-authored-by: Romain <romain-intel@users.noreply.github.com> Co-authored-by: Oleg Avdeev <oleg.v.avdeev@gmail.com> Co-authored-by: RikishK <69884402+RikishK@users.noreply.github.com>
still an issue to be solved; the changes to the queries broke the transactional tag mutation, as that performs multiple queries over a cursor, which now gets closed mid-operation |
This PR adds the ability to separate out reads and writes into their own separate DB connection pools. The reader pool would point to a read replica endpoint and the write pool would point to a writer endpoint. More details on how to do this has been added to the
environment.md
doc.We have tested this change with Amazon Aurora (with the Postgres DB Engine v13.7). With Aurora Postgres, we have a single writer and multiple read replicas. As a side note, Aurora MySQL supports multiple writers which could potentially work with this setup, however, we have not tested these changes with Aurora MySQL.
A brief overview of changes:
AsyncPostgresTable
class.