Skip to content

Commit

Permalink
sql: create benchmark for concurrent sequence increments
Browse files Browse the repository at this point in the history
Previously, there was no benchmark that tested the performance
of concurrent increments to sequences. There was also no
benchmark which compared sequence performance based on
different cache sizes. This change adds a benchmark to measure
performance based on the above criteria.

Release note: None
  • Loading branch information
jayshrivastava committed Feb 4, 2021
1 parent 850a09e commit 0be8b34
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions pkg/sql/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,49 @@ import (
)

func BenchmarkSequenceIncrement(b *testing.B) {
cluster := serverutils.StartNewTestCluster(b, 3, base.TestClusterArgs{})
defer cluster.Stopper().Stop(context.Background())

sqlDB := cluster.ServerConn(0)
runSubBenchMark := func(b *testing.B, cacheSize int, parallelism int) {
subBenchMark := func(b *testing.B) {
cluster := serverutils.StartNewTestCluster(b, 3, base.TestClusterArgs{})
defer cluster.Stopper().Stop(context.Background())

sqlDB := cluster.ServerConn(0)
if _, err := sqlDB.Exec(fmt.Sprintf(`
CREATE SEQUENCE seq CACHE %d;
CREATE TABLE tbl (
id INT PRIMARY KEY DEFAULT nextval('seq'),
foo text
);
`, cacheSize)); err != nil {
b.Fatal(err)
}

if _, err := sqlDB.Exec(`
CREATE DATABASE test;
USE test;
CREATE SEQUENCE seq;
CREATE TABLE tbl (
id INT PRIMARY KEY DEFAULT nextval('seq'),
foo text
);
`); err != nil {
b.Fatal(err)
b.SetParallelism(parallelism)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
session, err := sqlDB.Conn(context.Background())
if err != nil {
b.Fatal(err)
}
conn := sqlutils.MakeSQLRunner(session)
for pb.Next() {
conn.Exec(b, "INSERT INTO tbl (foo) VALUES ('foo')")
}
if err = session.Close(); err != nil {
b.Fatal(err)
}
})
}
b.Run(fmt.Sprintf("Cache-%d-P-%d", cacheSize, parallelism), subBenchMark)
}

b.ResetTimer()
for n := 0; n < b.N; n++ {
if _, err := sqlDB.Exec("INSERT INTO tbl (foo) VALUES ('foo')"); err != nil {
b.Fatal(err)
cacheSizes := []int{1, 32, 64, 128, 256, 512}
parallelism := []int{1, 2, 4, 8}

for _, cacheSize := range cacheSizes {
for _, p := range parallelism {
runSubBenchMark(b, cacheSize, p)
}
}
b.StopTimer()
}

func BenchmarkUniqueRowID(b *testing.B) {
Expand Down

0 comments on commit 0be8b34

Please sign in to comment.