Skip to content

Commit b42a0ce

Browse files
committed
colexecerror: further optimize BenchmarkSQLCatchVectorizedRuntimeError
Rather than creating and closing connections for each test case, we can just reuse the same connections in the benchmark, which speeds it up significantly (from about 4 min to 1 min). Release note: None
1 parent 9de4d01 commit b42a0ce

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

pkg/sql/colexecerror/error_test.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,32 @@ func BenchmarkSQLCatchVectorizedRuntimeError(b *testing.B) {
184184
// crdb_test-build behavior.
185185
defer colexecerror.ProductionBehaviorForTests()()
186186

187-
for _, parallelism := range []int{1, 8, 32} {
187+
const maxParallelism = 32
188+
maxNumConns := runtime.GOMAXPROCS(0) * maxParallelism
189+
// Create as many warm connections as we will need for the benchmark. These
190+
// will be reused across all test cases to avoid the connection churn.
191+
connsPool := make([]*gosql.DB, maxNumConns)
192+
for i := range connsPool {
193+
conn := s.ApplicationLayer().SQLConn(b, serverutils.DBName(""))
194+
// Make sure we're using local, vectorized execution.
195+
sqlDB := sqlutils.MakeSQLRunner(conn)
196+
sqlDB.Exec(b, "SET distsql = off")
197+
sqlDB.Exec(b, "SET vectorize = on")
198+
connsPool[i] = conn
199+
}
200+
201+
for _, parallelism := range []int{1, 8, maxParallelism} {
188202
numConns := runtime.GOMAXPROCS(0) * parallelism
189203
b.Run(fmt.Sprintf("conns=%d", numConns), func(b *testing.B) {
190204
for _, tc := range cases {
191205
stmt := fmt.Sprintf(sqlFmt, tc.builtin)
192206
b.Run(tc.name, func(b *testing.B) {
193-
// Create as many warm connections as we will need for the benchmark.
194207
conns := make(chan *gosql.DB, numConns)
195208
for i := 0; i < numConns; i++ {
196-
conn := s.ApplicationLayer().SQLConn(b, serverutils.DBName(""))
197-
// Make sure we're using local, vectorized execution.
198-
sqlDB := sqlutils.MakeSQLRunner(conn)
199-
sqlDB.Exec(b, "SET distsql = off")
200-
sqlDB.Exec(b, "SET vectorize = on")
201-
// Warm up the connection by executing the statement once. We should
202-
// always go through the query plan cache after this.
209+
conn := connsPool[i]
210+
// Warm up the connection by executing the statement
211+
// once. We should always go through the query plan
212+
// cache after this.
203213
_, _ = conn.Exec(stmt)
204214
conns <- conn
205215
}
@@ -209,7 +219,6 @@ func BenchmarkSQLCatchVectorizedRuntimeError(b *testing.B) {
209219
var conn *gosql.DB
210220
select {
211221
case conn = <-conns:
212-
defer conn.Close()
213222
default:
214223
b.Fatal("not enough warm connections")
215224
}

0 commit comments

Comments
 (0)