Repository navigation
storage/aws: keep idle MySQL connections by default - #1244
Merged
Merged
Conversation
This was referenced Oct 22, 2026
grempe
force-pushed
the
mysql-idle-conns
branch
from
October 27, 2026 19:29
27219bb to
4bab8a5
Compare
Contributor
Author
|
Rebased onto |
roger2hk
reviewed
Nov 4, 2026
grempe
force-pushed
the
mysql-idle-conns
branch
from
November 4, 2026 16:20
4bab8a5 to
f310e16
Compare
Contributor
Author
|
Thanks! Switched to |
newMySQLSequencer and NewAntispam applied MaxIdleConns whenever it was >= 0, so a config that left it unset called SetMaxIdleConns(0) and the pool kept no idle connections: every query opened a new connection and closed it afterwards. Under load that meant about 1,700 new MySQL connections per 100,000 entries. Apply it whenever it is != 0, so that an unset value keeps the database/sql default, and a negative value still keeps no idle connections. Document MaxOpenConns and MaxIdleConns on aws.Config and AntispamOpts.
roger2hk
force-pushed
the
mysql-idle-conns
branch
from
November 4, 2026 23:11
f310e16 to
552b408
Compare
roger2hk
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1243.
newMySQLSequencerandNewAntispamappliedMaxIdleConnswhenever it was>= 0. A config that left it unset therefore calledSetMaxIdleConns(0), and the pool kept no idle connections: every query opened a new MySQL connection and closed it afterwards.This change applies it whenever it's
!= 0. An unset value then keeps thedatabase/sqldefault, which is currently 2, and a negative value still keeps no idle connections, asdatabase/sqldoes for anyn <= 0.MaxOpenConnsandMaxIdleConnsare now documented on bothaws.ConfigandAntispamOpts.Testing
TestMySQLSequencerIdleConnectionsandTestAntispamIdleConnections. Each makes 10 sequential queries on a new pool and checksDBStats.MaxIdleClosed:main, all 10 do;-1, all 10 do; onmain, none do, becausemainignores a negative value.>= 0, or to> 0, fails only that half's test.go test -race ./storage/aws/... -is_mysql_test_optional=falseagainst MySQL 8.4 passes on Go 1.26.10, and the tests also pass on Go 1.27.3.golangci-lintv2.13.2 reports 0 issues.TestConstructAndUseAppender(/tmp is not a directory), which fails the same way onmainhere.MaxIdleConnsmain-164The spread when unset comes from the default's 2 idle connections: when more queries run at once, the extra connections are closed afterwards.
A behaviour change to note: an explicit
MaxIdleConns: 0used to keep no idle connections; it now keeps the default, and-1keeps none. The same goes for--db_max_idle_conns=0in the AWS conformance and migrate binaries. Their help text ("defaults to 2") still holds, so this PR leaves them unchanged.Reviewed and submitted by me, a human. The investigation, the fix and its testing were developed with the assistance of an AI coding agent.