Skip to content

Commit

Permalink
distsql: add distsql package benchmark to daiy bench test (pingcap#28724
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tiancaiamao authored Oct 14, 2021
1 parent eaeb95a commit 092544c
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 58 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,14 @@ endif
# Usage:
# make bench-daily TO=/path/to/file.json
bench-daily:
go test github.com/pingcap/tidb/session -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/executor -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/tablecodec -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/expression -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/rowcodec -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/codec -run TestBenchDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/benchdaily -run TestBenchDaily \
go test github.com/pingcap/tidb/session -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/executor -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/tablecodec -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/expression -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/rowcodec -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/codec -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/distsql -bench BenchmarkDaily --outfile bench_daily.json
go test github.com/pingcap/tidb/util/benchdaily -bench BenchmarkDaily \
-date `git log -n1 --date=unix --pretty=format:%cd` \
-commit `git log -n1 --pretty=format:%h` \
-outfile $(TO)
Expand Down
74 changes: 74 additions & 0 deletions distsql/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2021 PingCAP, Inc.
//
// 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 distsql

import (
"context"
"testing"

"github.com/pingcap/tidb/util/benchdaily"
"github.com/pingcap/tidb/util/chunk"
)

func BenchmarkSelectResponseChunk_BigResponse(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
sctx := newMockSessionContext()
sctx.GetSessionVars().InitChunkSize = 32
sctx.GetSessionVars().MaxChunkSize = 1024
selectResult, colTypes := createSelectNormalByBenchmarkTest(4000, 20000, sctx)
chk := chunk.NewChunkWithCapacity(colTypes, 1024)
b.StartTimer()
for {
err := selectResult.Next(context.TODO(), chk)
if err != nil {
panic(err)
}
if chk.NumRows() == 0 {
break
}
chk.Reset()
}
}
}

func BenchmarkSelectResponseChunk_SmallResponse(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
sctx := newMockSessionContext()
sctx.GetSessionVars().InitChunkSize = 32
sctx.GetSessionVars().MaxChunkSize = 1024
selectResult, colTypes := createSelectNormalByBenchmarkTest(32, 3200, sctx)
chk := chunk.NewChunkWithCapacity(colTypes, 1024)
b.StartTimer()
for {
err := selectResult.Next(context.TODO(), chk)
if err != nil {
panic(err)
}
if chk.NumRows() == 0 {
break
}
chk.Reset()
}
}
}

func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkSelectResponseChunk_BigResponse,
BenchmarkSelectResponseChunk_SmallResponse,
)
}
44 changes: 0 additions & 44 deletions distsql/distsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,50 +337,6 @@ func (r *mockResultSubset) MemSize() int64 { return int64(cap(r.data)) }
// RespTime implements kv.ResultSubset interface.
func (r *mockResultSubset) RespTime() time.Duration { return 0 }

func BenchmarkSelectResponseChunk_BigResponse(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
sctx := newMockSessionContext()
sctx.GetSessionVars().InitChunkSize = 32
sctx.GetSessionVars().MaxChunkSize = 1024
selectResult, colTypes := createSelectNormalByBenchmarkTest(4000, 20000, sctx)
chk := chunk.NewChunkWithCapacity(colTypes, 1024)
b.StartTimer()
for {
err := selectResult.Next(context.TODO(), chk)
if err != nil {
panic(err)
}
if chk.NumRows() == 0 {
break
}
chk.Reset()
}
}
}

func BenchmarkSelectResponseChunk_SmallResponse(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
sctx := newMockSessionContext()
sctx.GetSessionVars().InitChunkSize = 32
sctx.GetSessionVars().MaxChunkSize = 1024
selectResult, colTypes := createSelectNormalByBenchmarkTest(32, 3200, sctx)
chk := chunk.NewChunkWithCapacity(colTypes, 1024)
b.StartTimer()
for {
err := selectResult.Next(context.TODO(), chk)
if err != nil {
panic(err)
}
if chk.NumRows() == 0 {
break
}
chk.Reset()
}
}
}

func newMockSessionContext() sessionctx.Context {
ctx := mock.NewContext()
ctx.GetSessionVars().StmtCtx = &stmtctx.StatementContext{
Expand Down
2 changes: 1 addition & 1 deletion executor/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ func BenchmarkPipelinedRowNumberWindowFunctionExecution(b *testing.B) {

}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkReadLastLinesOfHugeLine,
)
Expand Down
2 changes: 1 addition & 1 deletion expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ func (s *testVectorizeSuite2) TestVectorizedFilterConsiderNull(c *C) {
ctx.GetSessionVars().EnableVectorizedExpression = dafaultEnableVectorizedExpressionVar
}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkCastIntAsIntRow,
BenchmarkCastIntAsIntVec,
Expand Down
2 changes: 1 addition & 1 deletion session/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ func BenchmarkCompileExecutePreparedStmt(b *testing.B) {
// The format of the json output is described by the BenchOutput.
// Used by this command in the Makefile
// make bench-daily TO=xxx.json
func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkPreparedPointGet,
BenchmarkPointGet,
Expand Down
2 changes: 1 addition & 1 deletion tablecodec/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func BenchmarkDecodeRowKey(b *testing.B) {
}
}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkEncodeRowKeyWithHandle,
BenchmarkEncodeEndKey,
Expand Down
2 changes: 1 addition & 1 deletion util/benchdaily/bench_daily_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func combineFiles(commitHash string, dateInUnix string, inputFiles []string, out
enc.Encode(output)
}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
if !flag.Parsed() {
flag.Parse()
}
Expand Down
2 changes: 1 addition & 1 deletion util/codec/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func BenchmarkDecodeOneToChunk(b *testing.B) {
}
}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkDecodeWithSize,
BenchmarkDecodeWithOutSize,
Expand Down
2 changes: 1 addition & 1 deletion util/rowcodec/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func BenchmarkDecode(b *testing.B) {
}
}

func TestBenchDaily(t *testing.T) {
func BenchmarkDaily(b *testing.B) {
benchdaily.Run(
BenchmarkEncode,
BenchmarkDecode,
Expand Down

0 comments on commit 092544c

Please sign in to comment.