yesodweb / yesodweb/persistent
createSqlPool's idle timeout seems much too short
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)

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

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

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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