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

Implement Connection Pooling for Oracle Provider to Improve Performance #1655

Closed
Moritz-Langer opened this issue May 14, 2024 · 5 comments
Closed
Labels
enhancement New feature or request OGC API - Features OGC API - Features
Milestone

Comments

@Moritz-Langer
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Performance improvements might be gained when using a connection pool for database providers.
I have seen this commit to the postgres provider: 6442813

Describe the solution you'd like
Upon application start check for config whether there are features/collections using the Oracle provider. If the Oracle provider is in use, the application should initialize a connection pool. Subsequent connections required by the Oracle provider should then be acquired from this pool rather than creating new connections per request.

Open Question: Initialize Pool globally for example within itemtypes.py?

Describe alternatives you've considered
I thought about handling within the oracle provider alone, but this might lead to initializing pools for every request or am I mistaking here?

Additional context
Connection pooling can drastically reduce the overhead associated with establishing connections to the database, particularly under load. By managing a pool of reusable connections, the system can gain improvements in response time and reduce the load on the database server.

Discussion Points

  • I invite feedback on the proposed solution, especially regarding where and how to initialize the connection pool.
  • Insights into how connection pooling is being handled in similar projects or different providers would be extremely valuable.
  • Any concerns or additional benefits not already considered?
@Moritz-Langer Moritz-Langer added the enhancement New feature or request label May 14, 2024
@Moritz-Langer
Copy link
Contributor Author

Moritz-Langer commented May 22, 2024

On the weekend I started with an initial implementation along the line of the following:

class DatabaseConnection:
    """Database connection class to be used as 'with' statement.
    The class returns a connection object.
    """
    pool = None  # Class-level connection pool
    @classmethod
    def initialize_pool(cls, conn_dict):
        """Initialize the connection pool if not already initialized."""
        LOGGER.debug(f"conn_dict contains {conn_dict}")
        if DatabaseConnection.pool is None:
            DatabaseConnection.pool = oracledb.create_pool(
                            user=conn_dict["user"],
                            password=conn_dict["password"],
                            dsn=dsn,
                            min=2,  
                            max=10,  
                            increment=1, 
                        )

This looks promising and I will create a pull-request after some more polishing

@tomkralidis
Copy link
Member

cc'ing @totycro and @8luewater for feedback/input.

@Moritz-Langer
Copy link
Contributor Author

Moritz-Langer commented Jun 12, 2024

@8luewater I am currently finishing up on this.
We ran internal tests using locust which showed an around 10x improvement in speed using session pooling.
edit: 10x improvement given around 50 concurrent users

In the current design you would have to set environment variables like this to your linux / server environment:

export ORACLE_POOL_MIN=2
export ORACLE_POOL_MAX=10

Then the DatabaseConnection class uses these env variables as input parameters for the creation of a session pool.
When these env vars are not set, the regular behaviour is triggered and single connections are established for incomming requests.
@totycro and I discussed the issue of activating/configuring the session pool in the YAML file, but currently this is tricky since it would be global but would have to be written to every collection item in the yaml file.

Do you have any feedback/wishes/critique regarding this approach?

@8luewater
Copy link
Contributor

8luewater commented Jun 13, 2024 via email

@Moritz-Langer Moritz-Langer changed the title Implement Connection Pooling for Oracle Provider to Improve Performance (potentially other Database Providers as well) Implement Connection Pooling for Oracle Provider to Improve Performance Jun 13, 2024
@tomkralidis tomkralidis added this to the 0.17.0 milestone Jun 19, 2024
@tomkralidis tomkralidis added the OGC API - Features OGC API - Features label Jun 19, 2024
@tomkralidis
Copy link
Member

Added in #1688 (thanks @Moritz-Langer!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OGC API - Features OGC API - Features
Projects
None yet
Development

No branches or pull requests

3 participants