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

Introduce pg pool options #64

Merged
merged 3 commits into from
Nov 7, 2024
Merged

Introduce pg pool options #64

merged 3 commits into from
Nov 7, 2024

Conversation

piotr-iohk
Copy link
Collaborator

While testing search-tx optimizations I've noticed that performance deteriorates suddenly after a few requests and it remains deteriorated until the mina-mesh restart.

After some research and playing around I've found that that when we use:

PgPool::connect(self.archive_database_url.as_str()).await?,

There are some defaults, in particular idle_timeout: 600s -> https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/pool/options.rs#L161. Which causes that after we reach the max pool size (default:10) they become stale for 600s and not quite re-used and that seems to affect the performance.

So this PR makes both variables (pool_size and idle_timeout) configurable via env vars, giving some reasonable defaults (pool_size=10 and idle_timeout=1). In particular low idle timeout seems to address the issue of deteriorating performance as the unused pools are probably garbage collected.

src/config.rs Outdated

/// The maximum number of concurrent connections allowed in the Archive
/// Database connection pool.
#[arg(long, env = "MINAMESH_MAX_DB_POOL_SIZE", default_value_t = 10)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually there is similar env var in rosetta MINA_ROSETTA_MAX_DB_POOL_SIZE: https://github.com/MinaProtocol/mina/blob/ca9c8c86aa21d3c346d28ea0be7ad4cb0c22bf7f/src/app/rosetta/lib/rosetta.ml#L192-L197

so maybe we should give it 128 as default? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever you think is best. This PR looks good. Approving incase you'd prefer to merge as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's go with 128.

@piotr-iohk piotr-iohk merged commit de18efe into main Nov 7, 2024
6 checks passed
@piotr-iohk piotr-iohk deleted the pg-pool-connection branch November 7, 2024 09:09
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