github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/performance/utils/benchmark_runner/run_test.go (about) 1 // Copyright 2022 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package benchmark_runner 16 17 import ( 18 "context" 19 "errors" 20 "fmt" 21 "log" 22 "os" 23 "path/filepath" 24 "testing" 25 ) 26 27 var runTests = os.Getenv("RUN_BENCHMARK_RUNNER_TESTS") 28 var doltExec = os.Getenv("BENCHMARK_RUNNER_DOLT_EXEC") 29 var doltVersion = os.Getenv("BENCHMARK_RUNNER_DOLT_VERSION") 30 var mysqlExec = os.Getenv("BENCHMARK_RUNNER_MYSQL_EXEC") 31 var mysqlProtocol = os.Getenv("BENCHMARK_RUNNER_MYSQL_PROTOCOL") 32 var mysqlSocket = os.Getenv("BENCHMARK_RUNNER_MYSQL_SOCKET") 33 var mysqlVersion = os.Getenv("BENCHMARK_RUNNER_MYSQL_VERSION") 34 var doltgresExec = os.Getenv("BENCHMARK_RUNNER_DOLTGRES_EXEC") 35 var doltgresVersion = os.Getenv("BENCHMARK_RUNNER_DOLTGRES_VERSION") 36 var postgresExec = os.Getenv("BENCHMARK_RUNNER_POSTGRES_EXEC") 37 var postgresInitExec = os.Getenv("BENCHMARK_RUNNER_POSTGRES_INIT_EXEC") 38 var postgresVersion = os.Getenv("BENCHMARK_RUNNER_POSTGRES_VERSION") 39 var sysbenchLuaScripts = os.Getenv("BENCHMARK_RUNNER_SYSBENCH_LUA_SCRIPTS") 40 var tpccLuaScripts = os.Getenv("BENCHMARK_RUNNER_TPCC_LUA_SCRIPTS") 41 42 func TestRunner(t *testing.T) { 43 if runTests == "" { 44 t.Skip() 45 } 46 dir := t.TempDir() 47 log.Println(dir) 48 err := os.Chdir(dir) 49 if err != nil { 50 log.Fatal(err) 51 } 52 53 conf := &sysbenchRunnerConfigImpl{ 54 Tests: []TestConfig{ 55 NewTestConfig("oltp_read_only", nil, false), 56 //NewTestConfig("oltp_update_index", nil, false), 57 //NewTestConfig("oltp_delete_insert", nil, true), 58 }, 59 //Tests: selectTests("oltp_read_write", "oltp_update_index", "oltp_update_non_index", "oltp_insert", "bulk_insert", "oltp_write_only", "oltp_delete"), 60 Servers: []ServerConfig{ 61 &doltServerConfigImpl{ 62 Id: "test", 63 Version: doltVersion, 64 ResultsFormat: CsvFormat, 65 ServerExec: doltExec, 66 }, 67 }, 68 ScriptDir: sysbenchLuaScripts, 69 TestOptions: []string{ 70 "--rand-seed=1", 71 "--table-size=30", 72 "--rand-type=uniform", 73 "--time=30", 74 "--percentile=50", 75 }, 76 InitBigRepo: true, 77 } 78 79 err = Run(context.Background(), conf) 80 if err != nil { 81 log.Fatal(err) 82 } 83 } 84 85 func selectTests(names ...string) []TestConfig { 86 tests := make([]TestConfig, len(names)) 87 for i := range names { 88 tests[i] = &testConfigImpl{Name: names[i], FromScript: false} 89 } 90 return tests 91 } 92 93 func TestDoltMysqlSysbenchRunner(t *testing.T) { 94 if runTests == "" { 95 t.Skip() 96 } 97 dir := t.TempDir() 98 log.Println(dir) 99 err := os.Chdir(dir) 100 if err != nil { 101 log.Fatal(err) 102 } 103 104 conf := &sysbenchRunnerConfigImpl{ 105 Tests: []TestConfig{ 106 NewTestConfig("oltp_read_only", nil, false), 107 //NewTestConfig("oltp_update_index", nil, false), 108 //NewTestConfig("oltp_delete_insert", nil, true), 109 }, 110 Servers: []ServerConfig{ 111 &doltServerConfigImpl{ 112 Id: "test-dolt", 113 Version: doltVersion, 114 ResultsFormat: CsvFormat, 115 ServerExec: doltExec, 116 }, 117 &mysqlServerConfigImpl{ 118 Id: "test-mysql", 119 Port: 3606, 120 Version: mysqlVersion, 121 ResultsFormat: CsvFormat, 122 ServerExec: mysqlExec, 123 ServerUser: "root", 124 SkipLogBin: true, 125 ConnectionProtocol: mysqlProtocol, 126 Socket: mysqlSocket, 127 }, 128 }, 129 ScriptDir: sysbenchLuaScripts, 130 TestOptions: []string{ 131 "--rand-seed=1", 132 "--table-size=30", 133 "--rand-type=uniform", 134 "--time=30", 135 "--percentile=50", 136 }, 137 InitBigRepo: true, 138 } 139 140 err = Run(context.Background(), conf) 141 if err != nil { 142 log.Fatal(err) 143 } 144 } 145 146 func TestDoltgresPostgresSysbenchRunner(t *testing.T) { 147 if runTests == "" { 148 t.Skip() 149 } 150 dir := t.TempDir() 151 log.Println(dir) 152 err := os.Chdir(dir) 153 if err != nil { 154 log.Fatal(err) 155 } 156 157 conf := &sysbenchRunnerConfigImpl{ 158 Tests: []TestConfig{ 159 NewTestConfig("oltp_read_only", nil, false), 160 //NewTestConfig("oltp_update_index", nil, false), 161 }, 162 Servers: []ServerConfig{ 163 &postgresServerConfigImpl{ 164 Id: "test-postgres", 165 Host: "127.0.0.1", 166 Version: postgresVersion, 167 ResultsFormat: CsvFormat, 168 ServerExec: postgresExec, 169 InitExec: postgresInitExec, 170 ServerUser: "root", 171 }, 172 &doltgresServerConfigImpl{ 173 Id: "test-doltgres", 174 Port: 4433, 175 Host: "127.0.0.1", 176 Version: doltgresVersion, 177 ResultsFormat: CsvFormat, 178 ServerExec: doltgresExec, 179 }, 180 }, 181 TestOptions: []string{ 182 "--rand-seed=1", 183 "--table-size=30", 184 "--rand-type=uniform", 185 "--time=30", 186 "--percentile=50", 187 }, 188 } 189 190 err = Run(context.Background(), conf) 191 if err != nil { 192 log.Fatal(err) 193 } 194 } 195 196 func TestDoltProfiler(t *testing.T) { 197 if runTests == "" { 198 t.Skip() 199 } 200 dir := t.TempDir() 201 log.Println(dir) 202 err := os.Chdir(dir) 203 if err != nil { 204 log.Fatal(err) 205 } 206 207 id := "test-dolt-profile" 208 conf := &sysbenchRunnerConfigImpl{ 209 Tests: []TestConfig{ 210 NewTestConfig("oltp_read_only", nil, false), 211 }, 212 Servers: []ServerConfig{ 213 &doltServerConfigImpl{ 214 Id: id, 215 Version: doltVersion, 216 ResultsFormat: CsvFormat, 217 ServerExec: doltExec, 218 ServerProfile: CpuServerProfile, 219 ProfilePath: dir, 220 }, 221 }, 222 TestOptions: []string{ 223 "--rand-seed=1", 224 "--table-size=30", 225 "--rand-type=uniform", 226 "--time=30", 227 "--percentile=50", 228 }, 229 } 230 231 err = Run(context.Background(), conf) 232 if err != nil { 233 log.Fatal(err) 234 } 235 236 expectedProfile := filepath.Join(dir, fmt.Sprintf("%s_%s", id, cpuProfileFilename)) 237 if _, err := os.Stat(expectedProfile); errors.Is(err, os.ErrNotExist) { 238 log.Fatal("failed to create dolt cpu profile") 239 } 240 } 241 242 func TestDoltMysqlTpccRunner(t *testing.T) { 243 t.Skip() // skip for now since this is kinda slow for pr ci 244 dir := t.TempDir() 245 log.Println(dir) 246 err := os.Chdir(dir) 247 if err != nil { 248 log.Fatal(err) 249 } 250 251 conf := &tpccConfigImpl{ 252 Servers: []ServerConfig{ 253 &doltServerConfigImpl{ 254 Id: "test-dolt-tpcc", 255 Version: doltVersion, 256 ResultsFormat: CsvFormat, 257 ServerExec: doltExec, 258 }, 259 &mysqlServerConfigImpl{ 260 Id: "test-mysql-tpcc", 261 Port: 3606, 262 Version: mysqlVersion, 263 ResultsFormat: CsvFormat, 264 ServerExec: mysqlExec, 265 ServerUser: "root", 266 SkipLogBin: true, 267 ConnectionProtocol: mysqlProtocol, 268 Socket: mysqlSocket, 269 }, 270 }, 271 ScriptDir: tpccLuaScripts, 272 } 273 274 err = RunTpcc(context.Background(), conf) 275 if err != nil { 276 log.Fatal(err) 277 } 278 }