]> Cypherpunks repositories - gostls13.git/commit
database/sql: optimize connection request pool
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 17 Mar 2024 01:29:06 +0000 (18:29 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 18 Mar 2024 23:40:44 +0000 (23:40 +0000)
commit190d0d3e69b113bea0b6b604ba2f0beb62c08741
tree04d06f56ce711e71011956c6e6fb7733731b786a
parent1ed85ee228023d766b37db056311929c00091c9f
database/sql: optimize connection request pool

This replaces a map used as a set with a slice.

We were using a surprising amount of CPU in this code, making mapiters
to pull out a random element of the map. Instead, just rand.IntN to pick
a random element of the slice.

It also adds a benchmark:

                     │    before    │                after                │
                     │    sec/op    │   sec/op     vs base                │
    ConnRequestSet-8   1818.0n ± 0%   452.4n ± 0%  -75.12% (p=0.000 n=10)

(whether random is a good policy is a bigger question, but this
 optimizes the current policy without changing behavior)

Updates #66361

Change-Id: I3d456a819cc720c2d18e1befffd2657e5f50f1e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/572119
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
src/database/sql/sql.go
src/database/sql/sql_test.go
src/go/build/deps_test.go