Skip to content

Commit

Permalink
test: add benchmarks for concatenate and simple-concatenate
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Mar 21, 2024
1 parent d40d2a6 commit 4b34a80
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
52 changes: 52 additions & 0 deletions go/vt/vtgate/engine/concatenate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"errors"
"fmt"
"strings"
"sync/atomic"
"testing"

querypb "vitess.io/vitess/go/vt/proto/query"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/test/utils"

Expand Down Expand Up @@ -211,3 +214,52 @@ func TestConcatenateTypes(t *testing.T) {
})
}
}

func BenchmarkConcatenateTryExecute(b *testing.B) {
fakeSrc1, fakeSrc2, prim := createConcatenateForTest()
ctx := context.Background()
b.ResetTimer()
vcursor := &noopVCursor{}
count := 0
for i := 0; i < b.N; i++ {
res, err := prim.TryExecute(ctx, vcursor, map[string]*querypb.BindVariable{}, true)
require.NoError(b, err)
count += len(res.Rows)
fakeSrc1.curResult = 0
fakeSrc2.curResult = 0
}
}

func BenchmarkConcatenateTryStreamExecute(b *testing.B) {
fakeSrc1, fakeSrc2, prim := createConcatenateForTest()
ctx := context.Background()
b.ResetTimer()
vcursor := &noopVCursor{}
var count atomic.Int32
for i := 0; i < b.N; i++ {
err := prim.TryStreamExecute(ctx, vcursor, map[string]*querypb.BindVariable{}, true, func(result *sqltypes.Result) error {
count.Add(int32(len(result.Rows)))
return nil
})
require.NoError(b, err)
fakeSrc1.curResult = 0
fakeSrc2.curResult = 0
}
}

func createConcatenateForTest() (*fakePrimitive, *fakePrimitive, *Concatenate) {
fake := r("id|col1|col2", "int64|varchar|varbinary", "1|a1|b1", "2|a2|b2")
var rows []string
for x := range 10 {
rows = append(rows, fmt.Sprintf("%d|a%d|b%d", x, x, x))
}
result := sqltypes.MakeTestResult(fake.Fields, rows...)
fake.Rows = result.Rows
fakeSrc1 := &fakePrimitive{results: []*sqltypes.Result{fake, fake}}
fakeSrc2 := &fakePrimitive{results: []*sqltypes.Result{fake, fake}}
prim := NewConcatenate([]Primitive{
fakeSrc1,
fakeSrc2,
}, nil)
return fakeSrc1, fakeSrc2, prim
}
88 changes: 88 additions & 0 deletions go/vt/vtgate/engine/simple_concatenate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package engine

import (
"context"
"fmt"
"sync/atomic"
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
)

func BenchmarkSimpleConcatenateTryExecute(b *testing.B) {
fakeSrc1, fakeSrc2, prim := createSimpleConcatenateForTest()
ctx := context.Background()
b.ResetTimer()
vcursor := &noopVCursor{}
count := 0
for i := 0; i < b.N; i++ {
res, err := prim.TryExecute(ctx, vcursor, map[string]*querypb.BindVariable{}, true)
require.NoError(b, err)
count += len(res.Rows)
fakeSrc1.curResult = 0
fakeSrc2.curResult = 0
}
}

func BenchmarkSimpleConcatenateTryStreamExecute(b *testing.B) {
fakeSrc1, fakeSrc2, prim := createSimpleConcatenateForTest()
ctx := context.Background()
b.ResetTimer()
vcursor := &noopVCursor{}
var count atomic.Int32
for i := 0; i < b.N; i++ {
err := prim.TryStreamExecute(ctx, vcursor, map[string]*querypb.BindVariable{}, true, func(result *sqltypes.Result) error {
count.Add(int32(len(result.Rows)))
return nil
})
require.NoError(b, err)
fakeSrc1.curResult = 0
fakeSrc2.curResult = 0
}
}

func createSimpleConcatenateForTest() (*fakePrimitive, *fakePrimitive, *SimpleConcatenate) {
fake := r("id|col1|col2", "int64|varchar|varbinary", "1|a1|b1", "2|a2|b2")
var rows []string
for x := range 10 {
rows = append(rows, fmt.Sprintf("%d|a%d|b%d", x, x, x))
}
result := sqltypes.MakeTestResult(fake.Fields, rows...)
fake.Rows = result.Rows
fakeSrc1 := &fakePrimitive{results: []*sqltypes.Result{fake, fake}}
fakeSrc2 := &fakePrimitive{results: []*sqltypes.Result{fake, fake}}
prim := NewSimpleConcatenate([]Primitive{
fakeSrc1,
fakeSrc2,
})
return fakeSrc1, fakeSrc2, prim
}

func TestName(t *testing.T) {
var x atomic.Bool
for range 100 {
go func() {
old := x.Swap(true)
t.Log(old)
}()
}
}

0 comments on commit 4b34a80

Please sign in to comment.