@@ -184,22 +184,32 @@ func BenchmarkSQLCatchVectorizedRuntimeError(b *testing.B) {
184
184
// crdb_test-build behavior.
185
185
defer colexecerror .ProductionBehaviorForTests ()()
186
186
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 } {
188
202
numConns := runtime .GOMAXPROCS (0 ) * parallelism
189
203
b .Run (fmt .Sprintf ("conns=%d" , numConns ), func (b * testing.B ) {
190
204
for _ , tc := range cases {
191
205
stmt := fmt .Sprintf (sqlFmt , tc .builtin )
192
206
b .Run (tc .name , func (b * testing.B ) {
193
- // Create as many warm connections as we will need for the benchmark.
194
207
conns := make (chan * gosql.DB , numConns )
195
208
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.
203
213
_ , _ = conn .Exec (stmt )
204
214
conns <- conn
205
215
}
@@ -209,7 +219,6 @@ func BenchmarkSQLCatchVectorizedRuntimeError(b *testing.B) {
209
219
var conn * gosql.DB
210
220
select {
211
221
case conn = <- conns :
212
- defer conn .Close ()
213
222
default :
214
223
b .Fatal ("not enough warm connections" )
215
224
}
0 commit comments