yesodweb / yesodweb/persistent

createSqlPool's idle timeout seems much too short

Open
#775 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

https://hackage.haskell.org/package/persistent-2.7.3.1/docs/src/Database-Persist-Sql-Run.html#createSqlPool calls createPool with 1 stripe and a 20s idle timeout on resources. I would say that

a) This is much too small

and, to contradict myself somewhat

b) There is no one-size-fits-all.

I would at least bump this up to 5 minutes. Anything but a heavily loaded site essentially negates any benefit of using a pool, constantly forming new connections. I've instrumented the use of a 20s timeout in a pool at work, and while we are constantly serving requests, in the last hour we've opened 160 new database connections.

Methodology

I simply added a Prometheus.incCounter call to the function passed to create in resource-pool.

Here is our traffic (average requests/s with a 1h look back)
traffic

Here is a a counter of new database connections (average new connections per second).
connections

And here is a graph showing every time the new connection counter increases:

counter

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with createSqlPool in Database-Persist-Sql-Run.html and inspect the createPool call, focusing on its one-stripe configuration and 20-second idle timeout. Review the issue's connection-creation measurements and determine a timeout behavior that addresses the reported churn while accounting for the stated lack of a one-size-fits-all setting; done means the agreed behavior is implemented and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.