Skip to content

Commit

Permalink
[no-release-notes] redo how to set tpc-c testing statistics (#7806)
Browse files Browse the repository at this point in the history
* [no-release-notes] redo how to set tpc-c testing statistics

* [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh

* Remove old code

* don't collect stats for mysql

* tpcc uses non-standard port

---------

Co-authored-by: max-hoffman <[email protected]>
  • Loading branch information
max-hoffman and max-hoffman authored May 3, 2024
1 parent 05b2b24 commit 34c3613
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 22 deletions.
22 changes: 0 additions & 22 deletions go/performance/utils/benchmark_runner/dolt_tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
80 changes: 80 additions & 0 deletions go/performance/utils/benchmark_runner/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/jmoiron/sqlx"
)

type tpccTesterImpl struct {
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 34c3613

Please sign in to comment.