Skip to content

Commit

Permalink
bench: ignore cluster startup and shutdown
Browse files Browse the repository at this point in the history
This commit adjusts our benchmark harness to ignore the overhead of
starting up and shutting down the test cluster. This allows us to avoid
spurious "regressions" like that we've seen due to cockroachdb#117116.

Epic: None

Release note: None
  • Loading branch information
yuzefovich committed Jan 17, 2024
1 parent 1898adc commit 2857dca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/bench/foreachdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var runSepProcessTenant = flag.Bool("run-sep-process-tenant", false, "run separa
// BenchmarkFn is a function that runs a benchmark using the given SQLRunner.
type BenchmarkFn func(b *testing.B, db *sqlutils.SQLRunner)

// timerUtil is a helper method that should be called right before the
// invocation of BenchmarkFn and the returned function should be deferred.
func timerUtil(b *testing.B) func() {
b.ResetTimer()
b.StartTimer()
return b.StopTimer
}

func benchmarkCockroach(b *testing.B, f BenchmarkFn) {
s, db, _ := serverutils.StartServer(
b, base.TestServerArgs{
Expand All @@ -54,6 +62,7 @@ func benchmarkCockroach(b *testing.B, f BenchmarkFn) {
b.Fatal(err)
}

defer timerUtil(b)()
f(b, sqlutils.MakeSQLRunner(db))
}

Expand Down Expand Up @@ -103,6 +112,7 @@ func benchmarkSharedProcessTenantCockroach(b *testing.B, f BenchmarkFn) {
_, err = tenantDB.Exec(`CREATE DATABASE bench`)
require.NoError(b, err)

defer timerUtil(b)()
f(b, sqlutils.MakeSQLRunner(tenantDB))
}

Expand Down Expand Up @@ -133,6 +143,7 @@ func benchmarkSepProcessTenantCockroach(b *testing.B, f BenchmarkFn) {
_, err = tenantDB.Exec(`CREATE DATABASE bench`)
require.NoError(b, err)

defer timerUtil(b)()
f(b, sqlutils.MakeSQLRunner(tenantDB))
}

Expand All @@ -150,6 +161,7 @@ func benchmarkMultinodeCockroach(b *testing.B, f BenchmarkFn) {
}
defer tc.Stopper().Stop(context.TODO())

defer timerUtil(b)()
f(b, sqlutils.MakeRoundRobinSQLRunner(tc.Conns[0], tc.Conns[1], tc.Conns[2]))
}

Expand Down Expand Up @@ -198,6 +210,7 @@ func benchmarkPostgres(b *testing.B, f BenchmarkFn) {
r := sqlutils.MakeSQLRunner(db)
r.Exec(b, `CREATE SCHEMA IF NOT EXISTS bench`)

defer timerUtil(b)()
f(b, r)
}

Expand All @@ -218,6 +231,7 @@ func benchmarkMySQL(b *testing.B, f BenchmarkFn) {
r := sqlutils.MakeSQLRunner(db)
r.Exec(b, `CREATE DATABASE IF NOT EXISTS bench`)

defer timerUtil(b)()
f(b, r)
}

Expand Down

0 comments on commit 2857dca

Please sign in to comment.