-
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.
Performance Fixes for Vitess 18 (#14383)
Signed-off-by: Vicent Marti <[email protected]>
- Loading branch information
Showing
8 changed files
with
283 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package endtoend | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"sync" | ||
"testing" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
) | ||
|
||
// 10 groups, 119 characters | ||
const cValueTemplate = "###########-###########-###########-" + | ||
"###########-###########-###########-" + | ||
"###########-###########-###########-" + | ||
"###########" | ||
|
||
// 5 groups, 59 characters | ||
const padValueTemplate = "###########-###########-###########-" + | ||
"###########-###########" | ||
|
||
func sysbenchRandom(rng *rand.Rand, template string) []byte { | ||
out := make([]byte, 0, len(template)) | ||
for i := range template { | ||
switch template[i] { | ||
case '#': | ||
out = append(out, '0'+byte(rng.Intn(10))) | ||
default: | ||
out = append(out, template[i]) | ||
} | ||
} | ||
return out | ||
} | ||
|
||
var oltpInitOnce sync.Once | ||
|
||
func BenchmarkOLTP(b *testing.B) { | ||
const MaxRows = 10000 | ||
const RangeSize = 100 | ||
|
||
rng := rand.New(rand.NewSource(1234)) | ||
|
||
ctx := context.Background() | ||
conn, err := mysql.Connect(ctx, &vtParams) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
defer conn.Close() | ||
|
||
var query bytes.Buffer | ||
|
||
oltpInitOnce.Do(func() { | ||
b.Logf("seeding database for benchmark...") | ||
|
||
var rows int = 1 | ||
for i := 0; i < MaxRows/10; i++ { | ||
query.Reset() | ||
query.WriteString("insert into oltp_test(id, k, c, pad) values ") | ||
for j := 0; j < 10; j++ { | ||
if j > 0 { | ||
query.WriteString(", ") | ||
} | ||
_, _ = fmt.Fprintf(&query, "(%d, %d, '%s', '%s')", rows, rng.Int31n(0xFFFF), sysbenchRandom(rng, cValueTemplate), sysbenchRandom(rng, padValueTemplate)) | ||
rows++ | ||
} | ||
|
||
_, err = conn.ExecuteFetch(query.String(), -1, false) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
b.Logf("finshed (inserted %d rows)", rows) | ||
}) | ||
|
||
b.Run("SimpleRanges", func(b *testing.B) { | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
id := rng.Intn(MaxRows) | ||
|
||
query.Reset() | ||
_, _ = fmt.Fprintf(&query, "SELECT c FROM oltp_test WHERE id BETWEEN %d AND %d", id, id+rng.Intn(RangeSize)-1) | ||
_, err := conn.ExecuteFetch(query.String(), 1000, false) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
}) | ||
|
||
b.Run("SumRanges", func(b *testing.B) { | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
id := rng.Intn(MaxRows) | ||
|
||
query.Reset() | ||
_, _ = fmt.Fprintf(&query, "SELECT SUM(k) FROM oltp_test WHERE id BETWEEN %d AND %d", id, id+rng.Intn(RangeSize)-1) | ||
_, err := conn.ExecuteFetch(query.String(), 1000, false) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
}) | ||
|
||
b.Run("OrderRanges", func(b *testing.B) { | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
id := rng.Intn(MaxRows) | ||
|
||
query.Reset() | ||
_, _ = fmt.Fprintf(&query, "SELECT c FROM oltp_test WHERE id BETWEEN %d AND %d ORDER BY c", id, id+rng.Intn(RangeSize)-1) | ||
_, err := conn.ExecuteFetch(query.String(), 1000, false) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
}) | ||
|
||
b.Run("DistinctRanges", func(b *testing.B) { | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
id := rng.Intn(MaxRows) | ||
|
||
query.Reset() | ||
_, _ = fmt.Fprintf(&query, "SELECT DISTINCT c FROM oltp_test WHERE id BETWEEN %d AND %d ORDER BY c", id, id+rng.Intn(RangeSize)-1) | ||
_, err := conn.ExecuteFetch(query.String(), 1000, false) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
}) | ||
} |
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
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
Oops, something went wrong.