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

perf: add POSTGRES_MAX_CONNECTIONS env. #1922

Merged
merged 6 commits into from
Dec 27, 2024

Conversation

shaohuzhang1
Copy link
Contributor

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.

Copy link

f2c-ci-robot bot commented Dec 27, 2024

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.

Copy link

f2c-ci-robot bot commented Dec 27, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -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')
}
}

Copy link
Contributor Author

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

  1. 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.

  2. Type Annotations: Add type annotations where applicable to improve readability and help with static analysis tools like mypy.

  3. Ensure Values are Positive Integers: Validate that POOL_SIZE and MAX_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.

@liqiang-fit2cloud liqiang-fit2cloud merged commit 24bac65 into main Dec 27, 2024
4 of 5 checks passed
@liqiang-fit2cloud liqiang-fit2cloud deleted the pr@main@add_POSTGRES_MAX_CONNECTIONS_env branch December 27, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants