Skip to content

Conversation

@KarthikeyaKollu
Copy link

Description

This PR resolves the issue of a missing pool_config module in the SQLAlchemyDatabaseManager implementation (memori/database/sqlalchemy_manager.py). The absence of this module caused an ImportError.

To address the issue, I added a new pool_config.py file to centralize the default database connection pool settings. The following configurations have been introduced:

  • DEFAULT_POOL_SIZE = 5: Sets the maximum size of the connection pool for regular database connections.
  • DEFAULT_MAX_OVERFLOW = 10: Defines the maximum number of connections that can exceed the pool size during high-demand periods.
  • DEFAULT_POOL_TIMEOUT = 30: Specifies the time (in seconds) the application waits for a database connection before throwing a timeout error.
  • DEFAULT_POOL_RECYCLE = 3600: Ensures that connections are refreshed/recycled after 1 hour to prevent stale or idle connections.
  • DEFAULT_POOL_PRE_PING = True: Enables pre-ping checks to validate connection health before use.

Copy link

@MathiasRanna MathiasRanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted the same issue. Would approve this pull request from my side.

Although something like this for pool_config.py would be better.


"""
Database connection pool configuration for Memori.

Provides centralized defaults for SQLAlchemy connection pool settings.
These can be overridden via environment variables or per-instance parameters.
"""

import os


class PoolConfig:
    """
    Centralized database connection pool configuration.
    
    Defaults can be overridden via environment variables:
    - MEMORI_DATABASE__POOL_SIZE
    - MEMORI_DATABASE__POOL_MAX_OVERFLOW
    - MEMORI_DATABASE__POOL_TIMEOUT
    - MEMORI_DATABASE__POOL_RECYCLE
    - MEMORI_DATABASE__POOL_PRE_PING
    """

    def __init__(self) -> None:
        """Initialize pool config with defaults or environment overrides."""
        self.DEFAULT_POOL_SIZE = int(
            os.getenv("MEMORI_DATABASE__POOL_SIZE", "5")
        )
        self.DEFAULT_MAX_OVERFLOW = int(
            os.getenv("MEMORI_DATABASE__POOL_MAX_OVERFLOW", "10")
        )
        self.DEFAULT_POOL_TIMEOUT = int(
            os.getenv("MEMORI_DATABASE__POOL_TIMEOUT", "30")
        )
        self.DEFAULT_POOL_RECYCLE = int(
            os.getenv("MEMORI_DATABASE__POOL_RECYCLE", "1800")
        )
        self.DEFAULT_POOL_PRE_PING = (
            os.getenv("MEMORI_DATABASE__POOL_PRE_PING", "true").lower() == "true"
        )


pool_config = PoolConfig()

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

Successfully merging this pull request may close these issues.

2 participants