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

Add remove to connection pool's Lease interface. #4680

Open
kdubb opened this issue Apr 24, 2023 · 0 comments
Open

Add remove to connection pool's Lease interface. #4680

kdubb opened this issue Apr 24, 2023 · 0 comments

Comments

@kdubb
Copy link

kdubb commented Apr 24, 2023

Describe the feature

Add a remove method to io.vertx.core.net.impl.pool.Lease that allows leaseholders to remove the leased object instead of recycling it to the pool. A client would call remove instead of recycle when they determine the leased object should no longer be used.

The goal is to allow clients of the pool to make deterministic decisions on wether a leased object should be returned or recycled.

Use cases

SqlConnectionPool evictions are now (#1298) tested for idle time and max lifetime. Additionally, the eviction process is periodic and only checks "slots" that are not actively in use. Generally this works fine.

This leaves the problem of pools under heavy load. In this scenario there is no guarantee that eviction will ever be able to check for max lifetime because all connections might be in use when the eviction check is run.

During the SqlConnectionPool.PooledConnection "close" we know if the connection has exceeded its maximum lifetime but there is no way to hold the lease (so it's not recycled) and close/remove the connection from the pool.

With an added remove method, PooledConnection could communicate this removal requirement to the pool as it encounters it.

Contribution

I am willing to implement the feature or pass it off to @tsegismont or @vietj.

kdubb added a commit to kdubb/vert.x that referenced this issue Apr 24, 2023
chandramouli-r added a commit to chandramouli-r/vert.x that referenced this issue Jun 13, 2023
This PR tries to implement eclipse-vertx#4680.
A new method, release(Handler<AsyncResult<T>> handler) is added to the Lease
interface, with the default implementation calling recycle().

In SimpleConnectionPool, LeaseImpl implements the release() method by invoking
slot.pool.release().

The release() method in the Pool reduces slot.usage by 1, and if the usage count
reaches 0, it invokes pool.remove(slot).

The PR also introduces another member variable within the Slot object, called
inactive (boolean). When release() is invoked on a slot, the slot is marked as
inactive irrespective of the usage count. inactive is also set to true in Evict,
before we remove the slot (when usage count is 0).

A new Slot is initialized with inactive as true. The only time inactive gets set
to false is when a connection is successfully established for the slot.

In pool.acquire, we skip slots that are marked as inactive. This behavior means
it is better to invoke pool.connect() whenever a slot is removed, even when
there are no Waiters. This change will be made in a follow-up PR.

release() can subsequently be used by SqlConnectionPool instead of recycle(),
when it determines that a given connection is past its maxLifetime (else it uses
recycle()).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant