diff --git a/go/performance/utils/benchmark_runner/dolt_tpcc.go b/go/performance/utils/benchmark_runner/dolt_tpcc.go index 0b976dbb960..e8b57c9ed95 100644 --- a/go/performance/utils/benchmark_runner/dolt_tpcc.go +++ b/go/performance/utils/benchmark_runner/dolt_tpcc.go @@ -71,10 +71,6 @@ func (b *doltTpccBenchmarkerImpl) Benchmark(ctx context.Context) (Results, error } defer os.RemoveAll(testRepo) - if err := configureStats(ctx, b.serverConfig.GetServerExec(), testRepo); err != nil { - return nil, err - } - serverParams, err := b.serverConfig.GetServerArgs() if err != nil { return nil, err @@ -118,21 +114,3 @@ func GetTpccTests(config TpccConfig) []Test { } return tests } - -func configureStats(ctx context.Context, doltPath, dbPath string) error { - queries := []string{ - "set @@PERSIST.dolt_stats_auto_refresh_enabled = 1;", - "set @@PERSIST.dolt_stats_auto_refresh_interval = 0", - "set @@PERSIST.dolt_stats_auto_refresh_threshold = 1.0;", - "select sleep(1)", - "set @@PERSIST.dolt_stats_auto_refresh_enabled = 0;", - } - for _, q := range queries { - q := ExecCommand(ctx, doltPath, "sql", "-q", q) - q.Dir = dbPath - if err := q.Run(); err != nil { - return err - } - } - return nil -} diff --git a/go/performance/utils/benchmark_runner/tpcc.go b/go/performance/utils/benchmark_runner/tpcc.go index be265e6b568..4ef585dc044 100644 --- a/go/performance/utils/benchmark_runner/tpcc.go +++ b/go/performance/utils/benchmark_runner/tpcc.go @@ -20,6 +20,10 @@ import ( "os" "os/exec" "path/filepath" + "strings" + "time" + + "github.com/jmoiron/sqlx" ) type tpccTesterImpl struct { @@ -51,6 +55,78 @@ func (t *tpccTesterImpl) outputToResult(output []byte) (*Result, error) { return OutputToResult(output, t.serverConfig.GetServerType(), t.serverConfig.GetVersion(), t.test.GetName(), t.test.GetId(), t.suiteId, t.config.GetRuntimeOs(), t.config.GetRuntimeGoArch(), t.serverParams, t.test.GetParamsToSlice(), nil, false) } +func (t *tpccTesterImpl) collectStats(ctx context.Context) error { + if !strings.Contains(t.serverConfig.GetServerExec(), "dolt") { + return nil + } + db, err := sqlx.Open("mysql", fmt.Sprintf("root:@tcp(%s:%d)/sbt", t.serverConfig.GetHost(), t.serverConfig.GetPort())) + if err != nil { + return err + } + c, err := db.Connx(ctx) + if err != nil { + return err + } + + { + // configuration, restart, and check needs to be in the same session + tx, err := c.BeginTxx(ctx, nil) + if err != nil { + return err + } + + if _, err := tx.Exec("set @@GLOBAL.dolt_stats_auto_refresh_enabled = 1;"); err != nil { + return err + } + if _, err := tx.Exec("set @@GLOBAL.dolt_stats_auto_refresh_interval = 0;"); err != nil { + return err + } + if _, err := tx.Exec("set @@PERSIST.dolt_stats_auto_refresh_interval = 0;"); err != nil { + return err + } + if _, err := tx.Exec("set @@PERSIST.dolt_stats_auto_refresh_enabled = 1;"); err != nil { + return err + } + if _, err := tx.Exec("use sbt;"); err != nil { + return err + } + if _, err := tx.Exec("call dolt_stats_restart();"); err != nil { + return err + } + + rows := map[string]interface{}{"cnt": 0} + tick := time.NewTicker(5 * time.Second) + for { + if rows["cnt"] != 0 { + fmt.Printf("collected %d histogram buckets\n", rows["cnt"]) + break + } + select { + case <-tick.C: + res, err := tx.Queryx("select count(*) as cnt from dolt_statistics;") + if err != nil { + return err + } + if !res.Next() { + return fmt.Errorf("failed to set statistics") + } + if err := res.MapScan(rows); err != nil { + return err + } + if err := res.Close(); err != nil { + return err + } + } + } + } + + if _, err := c.QueryContext(ctx, "call dolt_stats_stop();"); err != nil { + return err + } + + return nil +} + func (t *tpccTesterImpl) prepare(ctx context.Context) error { args := t.test.GetPrepareArgs(t.serverConfig) cmd := exec.CommandContext(ctx, t.tpccCommand, args...) @@ -105,6 +181,10 @@ func (t *tpccTesterImpl) Test(ctx context.Context) (*Result, error) { return nil, err } + if err := t.collectStats(ctx); err != nil { + return nil, err + } + fmt.Println("Running test", t.test.GetName()) rs, err := t.run(ctx)