Repository navigation
Commit 67a1cbc
Make pool min_size a maintained connection floor (MagicStack#1323)
Currently `min_size` only controls how many connections a pool opens at
startup. Once idle connections expire through
`max_inactive_connection_lifetime`, or are closed by the server, the
pool can drain to zero regardless of `min_size`.
Split the old meaning into two parameters:
* `init_size`: number of connections opened when the pool is created.
Defaults to `min_size`, so existing callers see the same startup
behaviour.
* `min_size`: number of live connections the pool attempts to maintain
at all times.
Changes in behavior:
* The inactivity callback no longer closes a connection when the pool is
at or below `min_size`. It stays open, and its timer is re-armed on
the next acquire/release.
* When a pooled connection closes, including an idle one that was not
checked out, a background maintenance task reconnects holders until
the floor is restored. Failed reconnects are logged and retried
with exponential backoff capped at 60 seconds.
* The holder queue prefers holders that already have a live connection
(LIFO within each group), and maintenance takes only disconnected
holders.
* A pool whose initialization fails terminates any connections it
already opened.
* A holder that finishes connecting after the pool has started closing
closes the new connection instead of keeping it.
Note: to keep the old behaviour with no effective floor, pass
`init_size=N`, `min_size=0` where you previously passed `min_size=N`.
Co-authored-by: Elvis Pranskevichus <[email protected]>1 parent 25aaaf5 commit 67a1cbc
8 files changed
Lines changed: 667 additions & 75 deletions
File tree
- asyncpg
- _testbase
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| |||
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
| 285 | + | |
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
| |||
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
369 | | - | |
| 371 | + | |
370 | 372 | | |
371 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
372 | 379 | | |
| 380 | + | |
373 | 381 | | |
374 | 382 | | |
375 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1158 | 1158 | | |
1159 | 1159 | | |
1160 | 1160 | | |
1161 | | - | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
1162 | 1171 | | |
1163 | 1172 | | |
1164 | 1173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| |||
1599 | 1605 | | |
1600 | 1606 | | |
1601 | 1607 | | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
1605 | | - | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
1606 | 1613 | | |
1607 | 1614 | | |
1608 | 1615 | | |
| |||
0 commit comments