-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix connection timeout #456
Open
bram-vdberg
wants to merge
10
commits into
main
Choose a base branch
from
Fix-Connection-Timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
837a8f4
Add logging for solver-rewards dry run
bram-vdberg eeb09c1
Add pre-ping
bram-vdberg 5f66926
Update connection args
bram-vdberg 4ad5435
Check statement timeout
bram-vdberg 0fbfbff
Bug fixes
bram-vdberg 463061d
Catch error and log
bram-vdberg 526afb6
Set idle timeout to 900
bram-vdberg 2fb2fcd
Remove try catch
bram-vdberg 83e2b0b
Remove unnecessary files
bram-vdberg 6bf737c
Reformatting
bram-vdberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from pandas import DataFrame, Series | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.engine import Engine | ||
from sqlalchemy import text | ||
|
||
from src.logger import set_log | ||
from src.utils.query_file import open_query | ||
|
@@ -21,8 +22,19 @@ class MultiInstanceDBFetcher: | |
""" | ||
|
||
def __init__(self, db_urls: list[str]): | ||
log.info("Initializing MultiInstanceDBFetcher") | ||
self.connections = [ | ||
create_engine(f"postgresql+psycopg2://{url}") for url in db_urls | ||
create_engine( | ||
f"postgresql+psycopg2://{url}", | ||
pool_pre_ping=True, | ||
connect_args={ | ||
"keepalives": 1, | ||
"keepalives_idle": 30, | ||
"keepalives_interval": 10, | ||
"keepalives_count": 5, | ||
}, | ||
) | ||
for url in db_urls | ||
] | ||
|
||
@classmethod | ||
|
@@ -58,10 +70,14 @@ def get_solver_rewards( | |
|
||
# Here, we use the convention that we run the prod query for the first connection | ||
# and the barn query to all other connections | ||
log.info("Setting tcp_keepalives_idle to 900 for prod connection") | ||
self.connections[0].execute(text("SET tcp_keepalives_idle = 900;")) | ||
log.info("Running prod query for first connection (in get_solver_rewards)") | ||
results.append( | ||
self.exec_query(query=batch_reward_query_prod, engine=self.connections[0]) | ||
) | ||
for engine in self.connections[1:]: | ||
log.info("Running barn query on other connections (in get_solver_rewards") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the long term plan here? It seems that not setting the time out for barn is fine. But it also makes it a bit more difficult to understand what is happening here. |
||
results.append( | ||
self.exec_query(query=batch_reward_query_barn, engine=engine) | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would probably introduce a constant for this value.