-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
perf: add POSTGRES_MAX_CONNECTIONS env. #1922
perf: add POSTGRES_MAX_CONNECTIONS env. #1922
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -111,7 +111,7 @@ def get_db_setting(self) -> dict: | |||
"ENGINE": self.get('DB_ENGINE'), | |||
"POOL_OPTIONS": { | |||
"POOL_SIZE": 20, | |||
"MAX_OVERFLOW": 80 | |||
"MAX_OVERFLOW": self.get('DB_MAX_OVERFLOW') | |||
} | |||
} | |||
|
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.
The code looks mostly correct for retrieving database settings from configuration data. However, there's a few points that could be improved:
Improvements
-
Use Configurables: Instead of using
get('DB_MAX_OVERFLOW')
directly, consider defining a configurable variable if you plan to change it frequently. This can make the code more maintainable. -
Type Annotations: Add type annotations where applicable to improve readability and help with static analysis tools like mypy.
-
Ensure Values are Positive Integers: Validate that
POOL_SIZE
andMAX_OVERFLOW
are positive integers before proceeding.
Here's an adjusted version of the function:
from typing import Any, Dict
def get_db_setting(self) -> Dict[str, Any]:
"""
Retrieve database settings from the configuration.
Returns:
A dictionary containing database connection settings.
"""
return {
"ENGINE": self.get('DB_ENGINE'),
"POOL_OPTIONS": {
"POOL_SIZE": int(self.get('DB_POOL_SIZE', 5)), # Default size is 5
"MAX_OVERFLOW": int(self.get('DB_MAX_OVERFLOW', 20)) # Default overflow is 20
}
}
# Example usage:
# db_settings = get_db_setting()
Optimization Suggestions
- Early Return for Non-Configurable Values: If certain values (like
POOL_SIZE
) have default configurations, early returning these can reduce unnecessary processing.
This revised code includes simple types and adds some basic validation to ensure the necessary keys exist and have valid numeric values.
build: remove pyc compilation.
Merge branch 'main' of https://github.com/maxkb-dev/maxkb
Merge branch 'main' of https://github.com/maxkb-dev/maxkb
perf: increase MAX_OVERFLOW of database connection pool.
Merge branch 'main' of https://github.com/maxkb-dev/maxkb
perf: add POSTGRES_MAX_CONNECTIONS env.