github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/flowinfra/flow_test.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package flowinfra_test 12 13 import ( 14 "context" 15 "fmt" 16 "testing" 17 18 "github.com/cockroachdb/cockroach/pkg/base" 19 "github.com/cockroachdb/cockroach/pkg/kv" 20 "github.com/cockroachdb/cockroach/pkg/security" 21 "github.com/cockroachdb/cockroach/pkg/sql" 22 "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" 23 "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" 24 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 25 "github.com/cockroachdb/cockroach/pkg/util/log" 26 ) 27 28 // BenchmarkFlowSetup sets up GOMAXPROCS goroutines where each is setting up 29 // a flow for a scan that is dominated by the setup cost. 30 func BenchmarkFlowSetup(b *testing.B) { 31 defer leaktest.AfterTest(b)() 32 logScope := log.Scope(b) 33 defer logScope.Close(b) 34 ctx := context.Background() 35 36 s, conn, _ := serverutils.StartServer(b, base.TestServerArgs{}) 37 defer s.Stopper().Stop(ctx) 38 39 r := sqlutils.MakeSQLRunner(conn) 40 r.Exec(b, "CREATE DATABASE b; CREATE TABLE b.test (k INT);") 41 42 execCfg := s.ExecutorConfig().(sql.ExecutorConfig) 43 dsp := execCfg.DistSQLPlanner 44 for _, distribute := range []bool{true, false} { 45 b.Run(fmt.Sprintf("distribute=%t", distribute), func(b *testing.B) { 46 b.RunParallel(func(pb *testing.PB) { 47 planner, cleanup := sql.NewInternalPlanner( 48 "test", 49 kv.NewTxn(ctx, s.DB(), s.NodeID()), 50 security.RootUser, 51 &sql.MemoryMetrics{}, 52 &execCfg, 53 ) 54 defer cleanup() 55 for pb.Next() { 56 if err := dsp.Exec( 57 ctx, 58 planner, 59 "SELECT k FROM b.test WHERE k=1", 60 distribute, 61 ); err != nil { 62 b.Fatal(err) 63 } 64 } 65 }) 66 }) 67 } 68 }