-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
sysbench.go
181 lines (160 loc) · 4.94 KB
/
sysbench.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package tests
import (
"context"
"fmt"
"time"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod"
"github.com/cockroachdb/cockroach/pkg/roachprod/errors"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/stretchr/testify/require"
)
type sysbenchWorkload int
const (
oltpDelete sysbenchWorkload = iota
oltpInsert
oltpPointSelect
oltpUpdateIndex
oltpUpdateNonIndex
oltpReadOnly
oltpReadWrite
oltpWriteOnly
numSysbenchWorkloads
)
var sysbenchWorkloadName = map[sysbenchWorkload]string{
oltpDelete: "oltp_delete",
oltpInsert: "oltp_insert",
oltpPointSelect: "oltp_point_select",
oltpUpdateIndex: "oltp_update_index",
oltpUpdateNonIndex: "oltp_update_non_index",
oltpReadOnly: "oltp_read_only",
oltpReadWrite: "oltp_read_write",
oltpWriteOnly: "oltp_write_only",
}
func (w sysbenchWorkload) String() string {
return sysbenchWorkloadName[w]
}
type sysbenchOptions struct {
workload sysbenchWorkload
duration time.Duration
concurrency int
tables int
rowsPerTable int
}
func (o *sysbenchOptions) cmd(haproxy bool) string {
pghost := "{pghost:1}"
pgport := "{pgport:1}"
if haproxy {
pghost = "127.0.0.1"
pgport = "26257"
}
return fmt.Sprintf(`sysbench \
--db-driver=pgsql \
--pgsql-host=%s \
--pgsql-port=%s \
--pgsql-user=%s \
--pgsql-password=%s \
--pgsql-db=sysbench \
--report-interval=1 \
--time=%d \
--threads=%d \
--tables=%d \
--table_size=%d \
--auto_inc=false \
%s`,
pghost,
pgport,
install.DefaultUser,
install.DefaultPassword,
int(o.duration.Seconds()),
o.concurrency,
o.tables,
o.rowsPerTable,
o.workload,
)
}
func runSysbench(ctx context.Context, t test.Test, c cluster.Cluster, opts sysbenchOptions) {
allNodes := c.Range(1, c.Spec().NodeCount)
roachNodes := c.Range(1, c.Spec().NodeCount-1)
loadNode := c.Node(c.Spec().NodeCount)
t.Status("installing cockroach")
c.Start(ctx, t.L(), option.DefaultStartOpts(), install.MakeClusterSettings(), roachNodes)
err := WaitFor3XReplication(ctx, t, t.L(), c.Conn(ctx, t.L(), allNodes[0]))
require.NoError(t, err)
t.Status("installing haproxy")
if err = c.Install(ctx, t.L(), loadNode, "haproxy"); err != nil {
t.Fatal(err)
}
// cockroach gen haproxy does not support specifying a non root user
pgurl, err := roachprod.PgURL(ctx, t.L(), c.MakeNodes(c.Node(1)), install.CockroachNodeCertsDir, roachprod.PGURLOptions{
External: true,
Auth: install.AuthRootCert,
Secure: c.IsSecure(),
})
if err != nil {
t.Fatal(err)
}
c.Run(ctx, option.WithNodes(loadNode), fmt.Sprintf("./cockroach gen haproxy --url %s", pgurl[0]))
c.Run(ctx, option.WithNodes(loadNode), "haproxy -f haproxy.cfg -D")
t.Status("installing sysbench")
if err := c.Install(ctx, t.L(), loadNode, "sysbench"); err != nil {
t.Fatal(err)
}
m := c.NewMonitor(ctx, roachNodes)
m.Go(func(ctx context.Context) error {
t.Status("preparing workload")
c.Run(ctx, option.WithNodes(c.Node(1)), `./cockroach sql --url={pgurl:1} -e "CREATE DATABASE sysbench"`)
c.Run(ctx, option.WithNodes(loadNode), opts.cmd(false /* haproxy */)+" prepare")
t.Status("running workload")
cmd := opts.cmd(true /* haproxy */) + " run"
result, err := c.RunWithDetailsSingleNode(ctx, t.L(), option.WithNodes(loadNode), cmd)
// Sysbench occasionally segfaults. When that happens, don't fail the
// test.
if result.RemoteExitStatus == errors.SegmentationFaultExitCode {
t.L().Printf("sysbench segfaulted; passing test anyway")
return nil
}
if err != nil {
return err
}
return nil
})
m.Wait()
}
func registerSysbench(r registry.Registry) {
for w := sysbenchWorkload(0); w < numSysbenchWorkloads; w++ {
const n = 3
const cpus = 32
const conc = 8 * cpus
opts := sysbenchOptions{
workload: w,
duration: 10 * time.Minute,
concurrency: conc,
tables: 10,
rowsPerTable: 10000000,
}
r.Add(registry.TestSpec{
Name: fmt.Sprintf("sysbench/%s/nodes=%d/cpu=%d/conc=%d", w, n, cpus, conc),
Owner: registry.OwnerTestEng,
Cluster: r.MakeClusterSpec(n+1, spec.CPU(cpus)),
CompatibleClouds: registry.AllExceptAWS,
Suites: registry.Suites(registry.Nightly),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runSysbench(ctx, t, c, opts)
},
})
}
}