vitess.io/vitess@v0.16.2/go/test/endtoend/vreplication/performance_test.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package vreplication
    18  
    19  import (
    20  	"fmt"
    21  	"io"
    22  	"testing"
    23  	"time"
    24  
    25  	"vitess.io/vitess/go/test/endtoend/cluster"
    26  
    27  	"github.com/stretchr/testify/require"
    28  )
    29  
    30  func TestReplicationStress(t *testing.T) {
    31  	if !*cluster.PerfTest {
    32  		t.Skip("performance tests disabled")
    33  	}
    34  
    35  	const initialStressVSchema = `
    36  {
    37    "tables": {
    38  	"largebin": {},
    39  	"customer": {}
    40    }
    41  }
    42  `
    43  	const initialStressSchema = `
    44  create table largebin(pid int, maindata varbinary(4096), primary key(pid));
    45  create table customer(cid int, name varbinary(128), meta json default null, typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid))  CHARSET=utf8mb4;
    46  `
    47  
    48  	const defaultCellName = "zone1"
    49  
    50  	const sourceKs = "stress_src"
    51  	const targetKs = "stress_tgt"
    52  
    53  	allCells := []string{defaultCellName}
    54  	allCellNames = defaultCellName
    55  
    56  	vc = NewVitessCluster(t, "TestReplicationStress", allCells, mainClusterConfig)
    57  	require.NotNil(t, vc)
    58  
    59  	defer vc.TearDown(t)
    60  
    61  	defaultCell = vc.Cells[defaultCellName]
    62  	vc.AddKeyspace(t, []*Cell{defaultCell}, sourceKs, "0", initialStressVSchema, initialStressSchema, 0, 0, 100, nil)
    63  	vtgate = defaultCell.Vtgates[0]
    64  	require.NotNil(t, vtgate)
    65  
    66  	err := cluster.WaitForHealthyShard(vc.VtctldClient, "product", "0")
    67  	require.NoError(t, err)
    68  
    69  	vtgateConn = getConnection(t, vc.ClusterConfig.hostname, vc.ClusterConfig.vtgateMySQLPort)
    70  	defer vtgateConn.Close()
    71  
    72  	verifyClusterHealth(t, vc)
    73  
    74  	const insertCount = 16 * 1024 * 1024
    75  
    76  	tablet := defaultCell.Keyspaces[sourceKs].Shards["0"].Tablets["zone1-100"].Vttablet
    77  	tablet.BulkLoad(t, "stress_src", "largebin", func(w io.Writer) {
    78  		for i := 0; i < insertCount; i++ {
    79  			fmt.Fprintf(w, "\"%d\",%q\n", i, "foobar")
    80  		}
    81  	})
    82  
    83  	waitForRowCount(t, vtgateConn, "stress_src:0", "largebin", insertCount)
    84  
    85  	t.Logf("creating new keysepace '%s'", targetKs)
    86  	vc.AddKeyspace(t, []*Cell{defaultCell}, targetKs, "0", initialStressVSchema, initialStressSchema, 0, 0, 200, nil)
    87  	waitForRowCount(t, vtgateConn, "stress_tgt:0", "largebin", 0)
    88  
    89  	t.Logf("moving 'largebin' table...")
    90  	moveStart := time.Now()
    91  
    92  	for _, ks := range defaultCell.Keyspaces {
    93  		for _, shard := range ks.Shards {
    94  			for _, tablet := range shard.Tablets {
    95  				tablet.Vttablet.ToggleProfiling()
    96  			}
    97  		}
    98  	}
    99  
   100  	moveTablesAction(t, "Create", defaultCell.Name, "stress_workflow", sourceKs, targetKs, "largebin")
   101  
   102  	keyspaceTgt := defaultCell.Keyspaces[targetKs]
   103  	for _, shard := range keyspaceTgt.Shards {
   104  		for _, tablet := range shard.Tablets {
   105  			t.Logf("catchup shard=%v, tablet=%v", shard.Name, tablet.Name)
   106  			tablet.Vttablet.WaitForVReplicationToCatchup(t, "stress_workflow", fmt.Sprintf("vt_%s", tablet.Vttablet.Keyspace), 5*time.Minute)
   107  		}
   108  	}
   109  
   110  	for _, ks := range defaultCell.Keyspaces {
   111  		for _, shard := range ks.Shards {
   112  			for _, tablet := range shard.Tablets {
   113  				tablet.Vttablet.ToggleProfiling()
   114  			}
   115  		}
   116  	}
   117  
   118  	t.Logf("finished catching up after MoveTables (%v)", time.Since(moveStart))
   119  	waitForRowCount(t, vtgateConn, "stress_tgt:0", "largebin", insertCount)
   120  }