Skip to content

Connection pool improvements#301

Draft
rsamoilov wants to merge 11 commits into
mainfrom
pool-improvements
Draft

Connection pool improvements#301
rsamoilov wants to merge 11 commits into
mainfrom
pool-improvements

Conversation

@rsamoilov
Copy link
Copy Markdown
Member

This pull request introduces several enhancements to the ActiveRecord connection pool extension, focusing on improved connection lifecycle management, configuration flexibility, and maintenance routines. It also updates database configuration templates to use a more descriptive parameter name. The most important changes are grouped below.

  • Introduced logic to retire connections exceeding a maximum age (retire_old_connections), proactively establish minimum connections (preconnect), and keep idle connections alive with pings (keep_alive).
  • Modified the flush method to always preserve at least the minimum number of connections and only run on the owner thread
  • Added an owner thread check to the reap and flush methods to ensure maintenance is only performed by the framework, thus disabling the standard ActiveRecord reaper.

rsamoilov added 11 commits May 20, 2026 10:57
this way we don't establish extra connections under low load
this ensures we skip first `min_connections` connections and iterate starting from the end of the list, which is where preconnected connections are located
if a fiber is killed while waiting on a DB query, the `conn.active?` call inside `reap` will block until the query is finished. Which is why we now wrap it into a fiber to ensure it doesn't block the reactor.
Additionally, new connections are now added to the bottom of the list to preserve active connections (created based on `min_connections`) at the top
…s at the same time

this is the same approach as in `reap`: connections are removed from the pool before pinging. This ensures no other query can use the connection while it's being pinged
@rsamoilov rsamoilov force-pushed the pool-improvements branch from bdf204f to b37ff91 Compare May 25, 2026 12:49
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.

1 participant