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

refactor: Added min idle and max lifetime for database config #2900

Merged
merged 6 commits into from
Nov 28, 2023

Conversation

akshay-97
Copy link
Contributor

@akshay-97 akshay-97 commented Nov 17, 2023

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Added min_idle : minimum number of connections to be maintained as idle in pool all times (default 0), and max_lifetime:
maximum lifetime of connections after which they will be removed from the pool ; options in database Config, allowing
custom values to be set while running application.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

having no idle connections in pool requires application to create new db connection for each request(sparse requests that come after idle_timeout, so no connections are available in pool when min_idle = 0), maintaining minimum connections should have marginal improvement in latency in such cases

How did you test it?

Config set:
min_idle : 2
idle_timeout : 120 secs
Test Sequence:
t0 : /payments
t130 : /payments

check the active/idle connections in psql using:
select * from pg_stat_activity where "datname" = 'hyperswitch_db';

or tcp connections made from app to database:
lsof -i tcp:5432 | grep router

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • [ x] I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@akshay-97 akshay-97 requested a review from a team as a code owner November 17, 2023 11:13
@github-actions github-actions bot added the S-conventions-not-followed Status: This PR does not follow contributing guidelines label Nov 17, 2023
@akshay-97 akshay-97 changed the title added min_idle, max_lifetime for database config refactor: added min_idle, max_lifetime for database config Nov 17, 2023
@github-actions github-actions bot removed the S-conventions-not-followed Status: This PR does not follow contributing guidelines label Nov 17, 2023
@akshay-97 akshay-97 self-assigned this Nov 17, 2023
jarnura
jarnura previously approved these changes Nov 17, 2023
Comment on lines 95 to 97
database
.max_lifetime
.map(|x| std::time::Duration::from_secs(x)),
Copy link
Member

@dracarys18 dracarys18 Nov 17, 2023

Choose a reason for hiding this comment

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

Suggested change
database
.max_lifetime
.map(|x| std::time::Duration::from_secs(x)),
database
.max_lifetime
.map(std::time::Duration::from_secs),

dracarys18
dracarys18 previously approved these changes Nov 17, 2023
@github-actions github-actions bot added the S-conventions-not-followed Status: This PR does not follow contributing guidelines label Nov 22, 2023
@akshay-97 akshay-97 changed the title refactor: added min_idle, max_lifetime for database config refactor: added min idle, max lifetime for database config Nov 22, 2023
@github-actions github-actions bot added S-conventions-not-followed Status: This PR does not follow contributing guidelines and removed S-conventions-not-followed Status: This PR does not follow contributing guidelines labels Nov 22, 2023
@akshay-97 akshay-97 changed the title refactor: added min idle, max lifetime for database config refactor: Added min idle and max lifetime for database config Nov 22, 2023
@github-actions github-actions bot added S-conventions-not-followed Status: This PR does not follow contributing guidelines and removed S-conventions-not-followed Status: This PR does not follow contributing guidelines labels Nov 22, 2023
@github-actions github-actions bot removed the S-conventions-not-followed Status: This PR does not follow contributing guidelines label Nov 23, 2023
@akshay-97 akshay-97 dismissed stale reviews from dracarys18 and jarnura via 5fc7340 November 28, 2023 12:28
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Nov 28, 2023
Merged via the queue into main with commit b3c51e6 Nov 28, 2023
12 of 14 checks passed
@Gnanasundari24 Gnanasundari24 deleted the added_pool_config branch November 28, 2023 13:47
lsampras added a commit that referenced this pull request Nov 28, 2023
Co-authored-by: akshay.s <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Gnanasundari24 <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
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.

4 participants