-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce network pressure on multi row insert (#14064)
Signed-off-by: Harshit Gangal <[email protected]>
- Loading branch information
1 parent
6231bc4
commit b793adf
Showing
14 changed files
with
445 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
go/test/endtoend/vtgate/queries/benchmark/benchmark_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2023 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 dml | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"vitess.io/vitess/go/test/endtoend/utils" | ||
) | ||
|
||
type testQuery struct { | ||
tableName string | ||
cols []string | ||
intTyp []bool | ||
} | ||
|
||
func (tq *testQuery) getInsertQuery(rows int) string { | ||
var allRows []string | ||
for i := 0; i < rows; i++ { | ||
var row []string | ||
for _, isInt := range tq.intTyp { | ||
if isInt { | ||
row = append(row, strconv.Itoa(i)) | ||
continue | ||
} | ||
row = append(row, "'"+getRandomString(50)+"'") | ||
} | ||
allRows = append(allRows, "("+strings.Join(row, ",")+")") | ||
} | ||
return fmt.Sprintf("insert into %s(%s) values %s", tq.tableName, strings.Join(tq.cols, ","), strings.Join(allRows, ",")) | ||
} | ||
|
||
func getRandomString(size int) string { | ||
var str strings.Builder | ||
|
||
for i := 0; i < size; i++ { | ||
str.WriteByte(byte(rand.Intn(27) + 97)) | ||
} | ||
return str.String() | ||
} | ||
|
||
func BenchmarkShardedTblNoLookup(b *testing.B) { | ||
conn, closer := start(b) | ||
defer closer() | ||
|
||
cols := []string{"id", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12"} | ||
intType := make([]bool, len(cols)) | ||
intType[0] = true | ||
tq := &testQuery{ | ||
tableName: "tbl_no_lkp_vdx", | ||
cols: cols, | ||
intTyp: intType, | ||
} | ||
for _, rows := range []int{1, 10, 100, 500, 1000, 5000, 10000} { | ||
insStmt := tq.getInsertQuery(rows) | ||
b.Run(fmt.Sprintf("16-shards-%d-rows", rows), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = utils.Exec(b, conn, insStmt) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
Copyright 2023 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 dml | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
"vitess.io/vitess/go/test/endtoend/utils" | ||
) | ||
|
||
var ( | ||
clusterInstance *cluster.LocalProcessCluster | ||
vtParams mysql.ConnParams | ||
mysqlParams mysql.ConnParams | ||
sKs = "sks" | ||
uKs = "uks" | ||
cell = "test" | ||
|
||
//go:embed sharded_schema.sql | ||
sSchemaSQL string | ||
|
||
//go:embed vschema.json | ||
sVSchema string | ||
) | ||
|
||
var ( | ||
shards4 = []string{ | ||
"-40", "40-80", "80-c0", "c0-", | ||
} | ||
|
||
shards8 = []string{ | ||
"-20", "20-40", "40-60", "60-80", "80-a0", "a0-c0", "c0-e0", "e0-", | ||
} | ||
|
||
shards16 = []string{ | ||
"-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-a0", "a0-b0", "b0-c0", "c0-d0", "d0-e0", "e0-f0", "f0-", | ||
} | ||
|
||
shards32 = []string{ | ||
"-05", "05-10", "10-15", "15-20", "20-25", "25-30", "30-35", "35-40", "40-45", "45-50", "50-55", "55-60", "60-65", "65-70", "70-75", "75-80", | ||
"80-85", "85-90", "90-95", "95-a0", "a0-a5", "a5-b0", "b0-b5", "b5-c0", "c0-c5", "c5-d0", "d0-d5", "d5-e0", "e0-e5", "e5-f0", "f0-f5", "f5-", | ||
} | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
defer cluster.PanicHandler(nil) | ||
flag.Parse() | ||
|
||
exitCode := func() int { | ||
clusterInstance = cluster.NewCluster(cell, "localhost") | ||
defer clusterInstance.Teardown() | ||
|
||
// Start topo server | ||
err := clusterInstance.StartTopo() | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
// Start sharded keyspace | ||
sKeyspace := &cluster.Keyspace{ | ||
Name: sKs, | ||
SchemaSQL: sSchemaSQL, | ||
VSchema: sVSchema, | ||
} | ||
|
||
err = clusterInstance.StartKeyspace(*sKeyspace, shards4, 0, false) | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
// Start vtgate | ||
err = clusterInstance.StartVtgate() | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
vtParams = clusterInstance.GetVTParams(sKs) | ||
|
||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} | ||
|
||
func start(b *testing.B) (*mysql.Conn, func()) { | ||
conn, err := mysql.Connect(context.Background(), &vtParams) | ||
require.NoError(b, err) | ||
|
||
deleteAll := func() { | ||
tables := []string{"tbl_no_lkp_vdx"} | ||
for _, table := range tables { | ||
_, _ = utils.ExecAllowError(b, conn, "delete from "+table) | ||
} | ||
} | ||
|
||
deleteAll() | ||
|
||
return conn, func() { | ||
deleteAll() | ||
conn.Close() | ||
cluster.PanicHandler(b) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
go/test/endtoend/vtgate/queries/benchmark/sharded_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
create table tbl_no_lkp_vdx | ||
( | ||
id bigint, | ||
c1 varchar(50), | ||
c2 varchar(50), | ||
c3 varchar(50), | ||
c4 varchar(50), | ||
c5 varchar(50), | ||
c6 varchar(50), | ||
c7 varchar(50), | ||
c8 varchar(50), | ||
c9 varchar(50), | ||
c10 varchar(50), | ||
c11 varchar(50), | ||
c12 varchar(50) | ||
) Engine = InnoDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"sharded": true, | ||
"vindexes": { | ||
"xxhash": { | ||
"type": "xxhash" | ||
} | ||
}, | ||
"tables": { | ||
"tbl_no_lkp_vdx": { | ||
"column_vindexes": [ | ||
{ | ||
"column": "id", | ||
"name": "xxhash" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.