github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/sysbench.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package main 12 13 import ( 14 "context" 15 "fmt" 16 "time" 17 ) 18 19 type sysbenchWorkload int 20 21 const ( 22 oltpDelete sysbenchWorkload = iota 23 oltpInsert 24 oltpPointSelect 25 oltpUpdateIndex 26 oltpUpdateNonIndex 27 oltpReadOnly 28 oltpReadWrite 29 oltpWriteOnly 30 31 numSysbenchWorkloads 32 ) 33 34 var sysbenchWorkloadName = map[sysbenchWorkload]string{ 35 oltpDelete: "oltp_delete", 36 oltpInsert: "oltp_insert", 37 oltpPointSelect: "oltp_point_select", 38 oltpUpdateIndex: "oltp_update_index", 39 oltpUpdateNonIndex: "oltp_update_non_index", 40 oltpReadOnly: "oltp_read_only", 41 oltpReadWrite: "oltp_read_write", 42 oltpWriteOnly: "oltp_write_only", 43 } 44 45 func (w sysbenchWorkload) String() string { 46 return sysbenchWorkloadName[w] 47 } 48 49 type sysbenchOptions struct { 50 workload sysbenchWorkload 51 duration time.Duration 52 concurrency int 53 tables int 54 rowsPerTable int 55 } 56 57 func (o *sysbenchOptions) cmd(haproxy bool) string { 58 pghost := "{pghost:1}" 59 if haproxy { 60 pghost = "127.0.0.1" 61 } 62 return fmt.Sprintf(`sysbench \ 63 --db-driver=pgsql \ 64 --pgsql-host=%s \ 65 --pgsql-port=26257 \ 66 --pgsql-user=root \ 67 --pgsql-password= \ 68 --pgsql-db=sysbench \ 69 --report-interval=1 \ 70 --time=%d \ 71 --threads=%d \ 72 --tables=%d \ 73 --table_size=%d \ 74 --auto_inc=false \ 75 %s`, 76 pghost, 77 int(o.duration.Seconds()), 78 o.concurrency, 79 o.tables, 80 o.rowsPerTable, 81 o.workload, 82 ) 83 } 84 85 func runSysbench(ctx context.Context, t *test, c *cluster, opts sysbenchOptions) { 86 allNodes := c.Range(1, c.spec.NodeCount) 87 roachNodes := c.Range(1, c.spec.NodeCount-1) 88 loadNode := c.Node(c.spec.NodeCount) 89 90 t.Status("installing cockroach") 91 c.Put(ctx, cockroach, "./cockroach", allNodes) 92 c.Start(ctx, t, roachNodes) 93 waitForFullReplication(t, c.Conn(ctx, allNodes[0])) 94 95 t.Status("installing haproxy") 96 if err := c.Install(ctx, t.l, loadNode, "haproxy"); err != nil { 97 t.Fatal(err) 98 } 99 c.Run(ctx, loadNode, "./cockroach gen haproxy --insecure --url {pgurl:1}") 100 c.Run(ctx, loadNode, "haproxy -f haproxy.cfg -D") 101 102 t.Status("installing sysbench") 103 if err := c.Install(ctx, t.l, loadNode, "sysbench"); err != nil { 104 t.Fatal(err) 105 } 106 107 m := newMonitor(ctx, c, roachNodes) 108 m.Go(func(ctx context.Context) error { 109 t.Status("preparing workload") 110 c.Run(ctx, c.Node(1), `./cockroach sql --insecure -e "CREATE DATABASE sysbench"`) 111 c.Run(ctx, loadNode, opts.cmd(false /* haproxy */)+" prepare") 112 113 t.Status("running workload") 114 c.Run(ctx, loadNode, opts.cmd(true /* haproxy */)+" run") 115 return nil 116 }) 117 m.Wait() 118 } 119 120 func registerSysbench(r *testRegistry) { 121 for w := sysbenchWorkload(0); w < numSysbenchWorkloads; w++ { 122 const n = 3 123 const cpus = 32 124 const conc = 4 * cpus 125 opts := sysbenchOptions{ 126 workload: w, 127 duration: 10 * time.Minute, 128 concurrency: conc, 129 tables: 10, 130 rowsPerTable: 10000000, 131 } 132 133 r.Add(testSpec{ 134 Name: fmt.Sprintf("sysbench/%s/nodes=%d/cpu=%d/conc=%d", w, n, cpus, conc), 135 Owner: OwnerKV, 136 Cluster: makeClusterSpec(n+1, cpu(cpus)), 137 Run: func(ctx context.Context, t *test, c *cluster) { 138 runSysbench(ctx, t, c, opts) 139 }, 140 }) 141 } 142 }