Skip to content

pg-pool min parameter is not obeyed with bursty traffic #3508

@barryhagan

Description

@barryhagan

The min parameter for pg.Pool was implemented in this PR.

The implementation has a problem that will cause the number of clients to drop below the min if multiple clients release during the same idle window. The isAboveMin() check occurs during the release of a client, but the actual removal occurs in asetTimeout callback.

Example

 const pool = new Pool({ max: 10, min: 5})

If you start with an empty pool, and you fire 10 concurrent requests to the database, you will fill up the pool to 10 clients.
Now, if you make no other requests, all of those 10 clients will release at roughly the same time. Each of those will evaluate isAboveMin() to true, so each will create the callback to remove the client after the idleTimeout. This will drop the client count to 0.

The isAboveMin() check should also be made in the callback, so you can get atomic removals and prevent all of the clients from being removed if they release in the same idle window and all think they can be removed and stay above the min settings.

As it stands, if more than (max-min) clients release in a time window less than the idle timeout, they will cause the client count to drop below min. This is mostly a problem for a bursty traffic profile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions