Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 191cd61

Browse files
authored
Merge pull request #1 from hicqu/write-stress-more-options
2 parents 632af71 + 0b8b395 commit 191cd61

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

testcase/example/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
937937
gopkg.in/yaml.v2 v2.0.0/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
938938
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
939939
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
940+
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
940941
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
941942
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
942943
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=

testcase/write-stress/append.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package testcase
1616
import (
1717
"context"
1818
"encoding/base64"
19+
"fmt"
1920
"math/rand"
2021
"sync"
2122

@@ -34,8 +35,23 @@ func (c *appendClient) SetUp(ctx context.Context, nodes []cluster.Node, clientNo
3435
if err := c.baseClient.SetUp(ctx, nodes, clientNodes, idx); err != nil {
3536
return err
3637
}
37-
util.MustExec(c.db, "drop table if exists write_stress")
38-
util.MustExec(c.db, "create table write_stress(col1 bigint, col2 varchar(256), data longtext, key k(col1, col2))")
38+
// Use 32 threads to create tables.
39+
var wg sync.WaitGroup
40+
for i := 0; i < 32; i++ {
41+
wg.Add(1)
42+
go func(tid int) {
43+
defer wg.Done()
44+
for j := 0; j < c.tables; j++ {
45+
if j%32 == tid {
46+
sql := fmt.Sprintf("drop table if exists write_stress%d", j+1)
47+
util.MustExec(c.db, sql)
48+
sql = fmt.Sprintf("create table write_stress%d(col1 bigint, col2 varchar(256), data longtext, key k(col1, col2))", j+1)
49+
util.MustExec(c.db, sql)
50+
}
51+
}
52+
}(i)
53+
}
54+
wg.Wait()
3955
return nil
4056
}
4157

@@ -66,14 +82,16 @@ func (c *appendClient) runClient(ctx context.Context) error {
6682
rng := rand.New(rand.NewSource(rand.Int63()))
6783

6884
col2 := make([]byte, 192)
69-
data := make([]byte, 65536)
85+
data := make([]byte, c.padLength)
7086
for {
7187
col1 := rng.Int63()
7288
col2Len := rng.Intn(192)
7389
_, _ = rng.Read(col2[:col2Len])
74-
dataLen := rng.Intn(65536)
90+
dataLen := rng.Intn(c.padLength)
7591
_, _ = rng.Read(data[:dataLen])
76-
_, err := c.db.ExecContext(ctx, "insert into write_stress values (?, ?, ?)", col1,
92+
tid := rng.Int()%c.tables + 1
93+
sql := fmt.Sprintf("insert into write_stress%d values (?, ?, ?)", tid)
94+
_, err := c.db.ExecContext(ctx, sql, col1,
7795
base64.StdEncoding.EncodeToString(col2[:col2Len]),
7896
base64.StdEncoding.EncodeToString(data[:dataLen]))
7997
if err != nil {

testcase/write-stress/client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ import (
2828

2929
// CaseCreator is a creator of test client
3030
type CaseCreator struct {
31-
Concurrency int
3231
CaseName string
32+
Concurrency int
33+
Tables int
34+
PadLength int
3335
}
3436

3537
// Create creates a test client
3638
func (c CaseCreator) Create(node cluster.ClientNode) core.Client {
37-
base := baseClient{concurrency: c.Concurrency}
39+
base := baseClient{
40+
concurrency: c.Concurrency,
41+
tables: c.Tables,
42+
padLength: c.PadLength,
43+
}
3844
switch c.CaseName {
3945
case "uniform":
4046
return &uniformClient{base}
@@ -47,6 +53,8 @@ func (c CaseCreator) Create(node cluster.ClientNode) core.Client {
4753
type baseClient struct {
4854
db *sql.DB
4955
concurrency int
56+
tables int
57+
padLength int
5058
}
5159

5260
func (c *baseClient) SetUp(ctx context.Context, _ []cluster.Node, clientNodes []cluster.ClientNode, idx int) error {

testcase/write-stress/cmd/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import (
3232

3333
var (
3434
concurrency = flag.Int("concurrency", 1024, "write concurrency")
35-
caseName = flag.String("case-name", "uniform", "test case name")
35+
tables = flag.Int("tables", 1, "total tables")
36+
padLength = flag.Int("pad-length", 65536, "pad string length")
37+
38+
caseName = flag.String("case-name", "uniform", "test case name")
3639
)
3740

3841
func main() {
@@ -47,8 +50,10 @@ func main() {
4750
Config: &cfg,
4851
Provider: cluster.NewDefaultClusterProvider(),
4952
ClientCreator: testcase.CaseCreator{
50-
Concurrency: *concurrency,
5153
CaseName: *caseName,
54+
Concurrency: *concurrency,
55+
Tables: *tables,
56+
PadLength: *padLength,
5257
},
5358
NemesisGens: util.ParseNemesisGenerators(fixture.Context.Nemesis),
5459
ClusterDefs: test_infra.NewDefaultCluster(c.Namespace, c.ClusterName, c.TiDBClusterConfig),

testcase/write-stress/uniform.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package testcase
1616
import (
1717
"context"
1818
"encoding/base64"
19+
"fmt"
1920
"math/rand"
2021
"sync"
2122

@@ -35,8 +36,23 @@ func (c *uniformClient) SetUp(ctx context.Context, nodes []cluster.Node, clientN
3536
if err := c.baseClient.SetUp(ctx, nodes, clientNodes, idx); err != nil {
3637
return err
3738
}
38-
util.MustExec(c.db, "drop table if exists write_stress")
39-
util.MustExec(c.db, "create table write_stress(id varchar(40) primary key clustered, col1 bigint, col2 varchar(256), data longtext, key k(col1, col2))")
39+
// Use 32 threads to create tables.
40+
var wg sync.WaitGroup
41+
for i := 0; i < 32; i++ {
42+
wg.Add(1)
43+
go func(tid int) {
44+
defer wg.Done()
45+
for j := 0; j < c.tables; j++ {
46+
if j%32 == tid {
47+
sql := fmt.Sprintf("drop table if exists write_stress%d", j+1)
48+
util.MustExec(c.db, sql)
49+
sql = fmt.Sprintf("create table write_stress(id varchar(40) primary key clustered, col1 bigint, col2 varchar(256), data longtext, key k(col1, col2))", j+1)
50+
util.MustExec(c.db, sql)
51+
}
52+
}
53+
}(i)
54+
}
55+
wg.Wait()
4056
return nil
4157
}
4258

@@ -68,15 +84,17 @@ func (c *uniformClient) runClient(ctx context.Context) error {
6884
rng := rand.New(rand.NewSource(rand.Int63()))
6985

7086
col2 := make([]byte, 192)
71-
data := make([]byte, 65536)
87+
data := make([]byte, c.padLength)
7288
for {
7389
uuid := uuid.New().String()
7490
col1 := rng.Int63()
7591
col2Len := rng.Intn(192)
7692
_, _ = rng.Read(col2[:col2Len])
77-
dataLen := rng.Intn(65536)
93+
dataLen := rng.Intn(c.padLength)
7894
_, _ = rng.Read(data[:dataLen])
79-
_, err := c.db.ExecContext(ctx, "insert into write_stress values (?, ?, ?, ?)", uuid, col1,
95+
tid := rng.Int()%c.tables + 1
96+
sql := fmt.Sprintf("insert into write_stress%d values (?, ?, ?)", tid)
97+
_, err := c.db.ExecContext(ctx, sql, uuid, col1,
8098
base64.StdEncoding.EncodeToString(col2[:col2Len]),
8199
base64.StdEncoding.EncodeToString(data[:dataLen]))
82100
if err != nil {

0 commit comments

Comments
 (0)