Skip to content

Commit 8de603d

Browse files
committed
workload: cache DNS lookups by default
By default, DNS lookups used by jackc/pgx are now cached for 30s. A negative duration will disable the caching behavior. While performing load testing, at higher connection counts with lower connection rates, it was possible to overwhelm the default environment DNS resolvers. Epic: none Release note: None
1 parent 4c39761 commit 8de603d

File tree

14 files changed

+79
-6
lines changed

14 files changed

+79
-6
lines changed

DEPS.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7666,6 +7666,16 @@ def go_deps():
76667666
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/cors/com_github_rs_cors-v1.8.0.zip",
76677667
],
76687668
)
7669+
go_repository(
7670+
name = "com_github_rs_dnscache",
7671+
build_file_proto_mode = "disable_global",
7672+
importpath = "github.com/rs/dnscache",
7673+
sha256 = "11e1fa18f7a18eac97b54b3726363598577ac0df7a6ce806f4775088593c0047",
7674+
strip_prefix = "github.com/rs/[email protected]",
7675+
urls = [
7676+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/dnscache/com_github_rs_dnscache-v0.0.0-20230804202142-fc85eb664529.zip",
7677+
],
7678+
)
76697679
go_repository(
76707680
name = "com_github_rs_xid",
76717681
build_file_proto_mode = "disable_global",

build/bazelutil/distdir_files.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ DISTDIR_FILES = {
901901
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rogpeppe/fastuuid/com_github_rogpeppe_fastuuid-v1.2.0.zip": "f9b8293f5e20270e26fb4214ca7afec864de92c73d03ff62b5ee29d1db4e72a1",
902902
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rogpeppe/go-internal/com_github_rogpeppe_go_internal-v1.9.0.zip": "7d777908b9c91a1685f2d709550e6b7478e14e9c4699dffd7f0a150e36dbc7e9",
903903
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/cors/com_github_rs_cors-v1.8.0.zip": "9aeb6b48d7ba5d34187b40adaed8280f0690e6d9b4fd6132eccbd62aa2c0efd9",
904+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/dnscache/com_github_rs_dnscache-v0.0.0-20230804202142-fc85eb664529.zip": "11e1fa18f7a18eac97b54b3726363598577ac0df7a6ce806f4775088593c0047",
904905
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/xid/com_github_rs_xid-v1.3.0.zip": "809ed1d8845fe5d73f6973e9b7a33eefd786cc97b1aebe493243e420b7c89958",
905906
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/rs/zerolog/com_github_rs_zerolog-v1.15.0.zip": "8e98c48e7fd132aafbf129664e8fd65229d067d772bff4bd712a497b7a2f00c4",
906907
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/russross/blackfriday/com_github_russross_blackfriday-v1.6.0.zip": "8dbd018a896577afef870d49adc9a7cbdcef54f6edd97dcbbe1b53e7cd6d66d4",

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ require (
205205
github.com/pseudomuto/protoc-gen-doc v1.3.2
206206
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
207207
github.com/robfig/cron/v3 v3.0.1
208+
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529
208209
github.com/sasha-s/go-deadlock v0.3.1
209210
github.com/shirou/gopsutil/v3 v3.21.12
210211
github.com/slack-go/slack v0.9.5

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,8 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f
20622062
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
20632063
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
20642064
github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM=
2065+
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529 h1:18kd+8ZUlt/ARXhljq+14TwAoKa61q6dX8jtwOf6DH8=
2066+
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA=
20652067
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
20662068
github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4=
20672069
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=

pkg/ccl/testccl/workload/schemachange/schema_change_external_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ func TestWorkload(t *testing.T) {
3939
scope := log.Scope(t)
4040
defer scope.Close(t)
4141
dir := scope.GetDirectory()
42-
ctx := context.Background()
42+
ctx, cancel := context.WithCancel(context.Background())
43+
defer cancel() // NOTE: Required to cleanup dnscache refresh Go routine
44+
4345
tc, _, cleanup := multiregionccltestutils.TestingCreateMultiRegionCluster(
4446
t,
4547
3, /* numServers */

pkg/workload/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ go_library(
3131
"@com_github_jackc_pgx_v5//pgconn",
3232
"@com_github_jackc_pgx_v5//pgxpool",
3333
"@com_github_lib_pq//:pq",
34+
"@com_github_rs_dnscache//:dnscache",
3435
"@com_github_spf13_pflag//:pflag",
3536
"@org_golang_x_sync//errgroup",
3637
],

pkg/workload/bank/bank_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func TestBank(t *testing.T) {
3737
{10, 100, 10}, // don't make more ranges than rows
3838
}
3939

40-
ctx := context.Background()
40+
ctx, cancel := context.WithCancel(context.Background())
41+
defer cancel()
42+
4143
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{UseDatabase: `test`})
4244
defer s.Stopper().Stop(ctx)
4345
sqlutils.MakeSQLRunner(db).Exec(t, `CREATE DATABASE test`)

pkg/workload/connection.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ConnFlags struct {
2828
Method string // Method for issuing queries; see SQLRunner.
2929

3030
ConnHealthCheckPeriod time.Duration
31+
DNSRefreshInterval time.Duration
3132
MaxConnIdleTime time.Duration
3233
MaxConnLifetime time.Duration
3334
MaxConnLifetimeJitter time.Duration
@@ -44,6 +45,7 @@ func NewConnFlags(genFlags *Flags) *ConnFlags {
4445
c.IntVar(&c.Concurrency, `concurrency`, 2*runtime.GOMAXPROCS(0),
4546
`Number of concurrent workers`)
4647
c.StringVar(&c.Method, `method`, `cache_statement`, `SQL issue method (cache_statement, cache_describe, describe_exec, exec, simple_protocol)`)
48+
c.DurationVar(&c.DNSRefreshInterval, `dns-refresh`, defaultDNSCacheRefresh, `Interval used to refresh cached DNS entries (<0 disables)`)
4749
c.DurationVar(&c.ConnHealthCheckPeriod, `conn-healthcheck-period`, 30*time.Second, `Interval that health checks are run on connections`)
4850
c.IntVar(&c.MinConns, `min-conns`, 0, `Minimum number of connections to attempt to keep in the pool`)
4951
c.DurationVar(&c.MaxConnIdleTime, `max-conn-idle-time`, 150*time.Second, `Max time an idle connection will be kept around`)
@@ -58,6 +60,7 @@ func NewConnFlags(genFlags *Flags) *ConnFlags {
5860
`concurrency`,
5961
`conn-healthcheck-period`,
6062
`db`,
63+
`dns-refresh`,
6164
`max-conn-idle-time`,
6265
`max-conn-lifetime-jitter`,
6366
`max-conn-lifetime`,

pkg/workload/csv_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func TestHandleCSV(t *testing.T) {
7676
}
7777

7878
func BenchmarkWriteCSVRows(b *testing.B) {
79-
ctx := context.Background()
79+
ctx, cancel := context.WithCancel(context.Background())
80+
defer cancel()
8081

8182
var batches []coldata.Batch
8283
for _, table := range tpcc.FromWarehouses(1).Tables() {

pkg/workload/insights/insights_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func TestInsightsWorkload(t *testing.T) {
3838
{10, 100, 10}, // don't make more ranges than rows
3939
}
4040

41-
ctx := context.Background()
41+
ctx, cancel := context.WithCancel(context.Background())
42+
defer cancel()
43+
4244
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{UseDatabase: `test`})
4345
defer s.Stopper().Stop(ctx)
4446
sqlutils.MakeSQLRunner(db).Exec(t, `CREATE DATABASE test`)

0 commit comments

Comments
 (0)