github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/roachmart.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  )
    17  
    18  func registerRoachmart(r *testRegistry) {
    19  	runRoachmart := func(ctx context.Context, t *test, c *cluster, partition bool) {
    20  		c.Put(ctx, cockroach, "./cockroach")
    21  		c.Put(ctx, workload, "./workload")
    22  		c.Start(ctx, t)
    23  
    24  		// TODO(benesch): avoid hardcoding this list.
    25  		nodes := []struct {
    26  			i    int
    27  			zone string
    28  		}{
    29  			{1, "us-central1-b"},
    30  			{4, "us-west1-b"},
    31  			{7, "europe-west2-b"},
    32  		}
    33  
    34  		roachmartRun := func(ctx context.Context, i int, args ...string) {
    35  			args = append(args,
    36  				"--local-zone="+nodes[i].zone,
    37  				"--local-percent=90",
    38  				"--users=10",
    39  				"--orders=100",
    40  				fmt.Sprintf("--partition=%v", partition))
    41  
    42  			if err := c.RunE(ctx, c.Node(nodes[i].i), args...); err != nil {
    43  				t.Fatal(err)
    44  			}
    45  		}
    46  		t.Status("initializing workload")
    47  		roachmartRun(ctx, 0, "./workload", "init", "roachmart")
    48  
    49  		duration := " --duration=" + ifLocal("10s", "10m")
    50  
    51  		t.Status("running workload")
    52  		m := newMonitor(ctx, c)
    53  		for i := range nodes {
    54  			i := i
    55  			m.Go(func(ctx context.Context) error {
    56  				roachmartRun(ctx, i, "./workload", "run", "roachmart", duration)
    57  				return nil
    58  			})
    59  		}
    60  
    61  		m.Wait()
    62  	}
    63  
    64  	for _, v := range []bool{true, false} {
    65  		v := v
    66  		r.Add(testSpec{
    67  			Name:    fmt.Sprintf("roachmart/partition=%v", v),
    68  			Owner:   OwnerPartitioning,
    69  			Cluster: makeClusterSpec(9, geo(), zones("us-central1-b,us-west1-b,europe-west2-b")),
    70  			Run: func(ctx context.Context, t *test, c *cluster) {
    71  				runRoachmart(ctx, t, c, v)
    72  			},
    73  		})
    74  	}
    75  }