Skip to content

Commit

Permalink
Merge pull request #7467 from dolthub/db/sysbench-profile
Browse files Browse the repository at this point in the history
[no-release-notes] update sysbench runner tool to cpu profile dolt server
  • Loading branch information
coffeegoddd authored Feb 7, 2024
2 parents 0428499 + 16179c2 commit 64d3675
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 32 deletions.
51 changes: 34 additions & 17 deletions go/performance/utils/sysbench_runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ const (
sysbenchUsername = "sysbench"
sysbenchUserLocal = "'sysbench'@'localhost'"
sysbenchPassLocal = "sysbenchpass"

userFlag = "--user"
hostFlag = "--host"
portFlag = "--port"
skipBinLogFlag = "--skip-log-bin"
profileFlag = "--prof"
profilePathFlag = "--prof-path"
cpuProfile = "cpu"
doltgresDataDirFlag = "--data-dir"
MysqlDataDirFlag = "--datadir"
MysqlInitializeInsecureFlag = "--initialize-insecure"
)

var (
Expand All @@ -64,9 +75,6 @@ var defaultSysbenchParams = []string{
}

var defaultDoltServerParams = []string{"sql-server"}
var defaultMysqlServerParams = []string{}
var defaultDoltgresServerParams = []string{}
var defaultPostgresServerParams = []string{}

var defaultSysbenchTests = []*ConfigTest{
NewConfigTest("oltp_read_only", []string{}, false),
Expand Down Expand Up @@ -283,6 +291,12 @@ type ServerConfig struct {

// Socket is the path to the server socket
Socket string

// ServerProfile specifies the golang profile to take of a Dolt server
ServerProfile string

// ProfilePath path to directory where server profile will be written
ProfilePath string
}

func (sc *ServerConfig) GetId() string {
Expand All @@ -293,36 +307,39 @@ func (sc *ServerConfig) GetId() string {
}

// GetServerArgs returns the args used to start a server
func (sc *ServerConfig) GetServerArgs() []string {
func (sc *ServerConfig) GetServerArgs() ([]string, error) {
params := make([]string, 0)

defaultParams := make([]string, 0)
if sc.Server == Dolt {
defaultParams = defaultDoltServerParams
if sc.ServerProfile != "" {
if sc.ServerProfile == cpuProfile {
params = append(params, profileFlag, cpuProfile)
} else {
return nil, fmt.Errorf("unsupported server profile: %s", sc.ServerProfile)
}
if sc.ProfilePath != "" {
params = append(params, profilePathFlag, sc.ProfilePath)
}
}
params = append(params, defaultDoltServerParams...)
} else if sc.Server == MySql {
defaultParams = defaultMysqlServerParams
if sc.ServerUser != "" {
params = append(params, fmt.Sprintf("--user=%s", sc.ServerUser))
params = append(params, fmt.Sprintf("%s=%s", userFlag, sc.ServerUser))
}
if sc.SkipLogBin {
params = append(params, "--skip-log-bin")
params = append(params, skipBinLogFlag)
}
} else if sc.Server == Doltgres {
defaultParams = defaultDoltgresServerParams
} else if sc.Server == Postgres {
defaultParams = defaultPostgresServerParams
}

params = append(params, defaultParams...)
if sc.Server == Dolt || sc.Server == Doltgres {
params = append(params, fmt.Sprintf("--host=%s", sc.Host))
params = append(params, fmt.Sprintf("%s=%s", hostFlag, sc.Host))
}
if sc.Port != 0 {
params = append(params, fmt.Sprintf("--port=%d", sc.Port))
params = append(params, fmt.Sprintf("%s=%d", portFlag, sc.Port))
}

params = append(params, sc.ServerArgs...)
return params
return params, nil
}

// Config is the configuration for a benchmarking run
Expand Down
7 changes: 5 additions & 2 deletions go/performance/utils/sysbench_runner/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ var stampFunc = func() string { return time.Now().UTC().Format(stampFormat) }

// BenchmarkDolt benchmarks dolt based on the provided configurations
func BenchmarkDolt(ctx context.Context, config *Config, serverConfig *ServerConfig) (Results, error) {
serverParams := serverConfig.GetServerArgs()
serverParams, err := serverConfig.GetServerArgs()
if err != nil {
return nil, err
}

err := DoltVersion(ctx, serverConfig.ServerExec)
err = DoltVersion(ctx, serverConfig.ServerExec)
if err != nil {
return nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions go/performance/utils/sysbench_runner/doltgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ import (

// BenchmarkDoltgres benchmarks doltgres based on the provided configurations
func BenchmarkDoltgres(ctx context.Context, config *Config, serverConfig *ServerConfig) (Results, error) {
serverParams := serverConfig.GetServerArgs()
serverParams, err := serverConfig.GetServerArgs()
if err != nil {
return nil, err
}

err := DoltVersion(ctx, serverConfig.ServerExec)
err = DoltVersion(ctx, serverConfig.ServerExec)
if err != nil {
return nil, err
}
Expand All @@ -47,7 +50,7 @@ func BenchmarkDoltgres(ctx context.Context, config *Config, serverConfig *Server
cleanupDoltgresServerDir(serverDir)
}()

serverParams = append(serverParams, fmt.Sprintf("--data-dir=%s", serverDir))
serverParams = append(serverParams, fmt.Sprintf("%s=%s", doltgresDataDirFlag, serverDir))

withKeyCtx, cancel := context.WithCancel(ctx)
gServer, serverCtx := errgroup.WithContext(withKeyCtx)
Expand Down
11 changes: 8 additions & 3 deletions go/performance/utils/sysbench_runner/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ func BenchmarkMysql(ctx context.Context, config *Config, serverConfig *ServerCon
}

gServer, serverCtx = errgroup.WithContext(withKeyCtx)
serverParams := serverConfig.GetServerArgs()
serverParams = append(serverParams, fmt.Sprintf("--datadir=%s", serverDir))
var serverParams []string
serverParams, err = serverConfig.GetServerArgs()
if err != nil {
cancel()
return nil, err
}
serverParams = append(serverParams, fmt.Sprintf("%s=%s", MysqlDataDirFlag, serverDir))

server = getMysqlServer(serverCtx, serverConfig, serverParams)

Expand Down Expand Up @@ -153,7 +158,7 @@ func InitMysqlDataDir(ctx context.Context, config *ServerConfig) (string, error)
return "", err
}

msInit := ExecCommand(ctx, config.ServerExec, "--initialize-insecure", fmt.Sprintf("--datadir=%s", serverDir))
msInit := ExecCommand(ctx, config.ServerExec, MysqlInitializeInsecureFlag, fmt.Sprintf("%s=%s", MysqlDataDirFlag, serverDir))
err = msInit.Run()
if err != nil {
return "", err
Expand Down
7 changes: 6 additions & 1 deletion go/performance/utils/sysbench_runner/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ func BenchmarkPostgres(ctx context.Context, config *Config, serverConfig *Server
return nil, err
}
gServer, serverCtx = errgroup.WithContext(withKeyCtx)
serverParams := serverConfig.GetServerArgs()
var serverParams []string
serverParams, err = serverConfig.GetServerArgs()
if err != nil {
cancel()
return nil, err
}
serverParams = append(serverParams, "-D", serverDir)
server = getMysqlServer(serverCtx, serverConfig, serverParams)
server.Env = append(server.Env, "LC_ALL=C")
Expand Down
5 changes: 4 additions & 1 deletion go/performance/utils/sysbench_runner/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ func (r *Result) Stamp(stampFunc func() string) {

// FromConfigsNewResult returns a new result with some fields set based on the provided configs
func FromConfigsNewResult(config *Config, serverConfig *ServerConfig, t *Test, suiteId string, idFunc func() string) (*Result, error) {
serverParams := serverConfig.GetServerArgs()
serverParams, err := serverConfig.GetServerArgs()
if err != nil {
return nil, err
}

var getId func() string
if idFunc == nil {
Expand Down
7 changes: 5 additions & 2 deletions go/performance/utils/tpcc_runner/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ const (

// BenchmarkDolt executes a set of tpcc tests against a dolt server.
func BenchmarkDolt(ctx context.Context, tppcConfig *TpccBenchmarkConfig, serverConfig *sysbench_runner.ServerConfig) (sysbench_runner.Results, error) {
serverParams := serverConfig.GetServerArgs()
serverParams, err := serverConfig.GetServerArgs()
if err != nil {
return nil, err
}

err := sysbench_runner.UpdateDoltConfig(ctx, serverConfig.ServerExec)
err = sysbench_runner.UpdateDoltConfig(ctx, serverConfig.ServerExec)
if err != nil {
return nil, err
}
Expand Down
9 changes: 7 additions & 2 deletions go/performance/utils/tpcc_runner/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ func BenchmarkMysql(ctx context.Context, config *TpccBenchmarkConfig, serverConf
}

gServer, serverCtx = errgroup.WithContext(withKeyCtx)
serverParams := serverConfig.GetServerArgs()
serverParams = append(serverParams, fmt.Sprintf("--datadir=%s", serverDir))
var serverParams []string
serverParams, err = serverConfig.GetServerArgs()
if err != nil {
cancel()
return nil, err
}
serverParams = append(serverParams, fmt.Sprintf("%s=%s", sysbench_runner.MysqlDataDirFlag, serverDir))
server = getMysqlServer(serverCtx, serverConfig, serverParams)

// launch the mysql server
Expand Down
5 changes: 4 additions & 1 deletion go/performance/utils/tpcc_runner/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (

// FromConfigsNewResult returns a new result with some fields set based on the provided configs
func FromConfigsNewResult(config *TpccBenchmarkConfig, serverConfig *sysbench_runner.ServerConfig, test *TpccTest, suiteId string, idFunc func() string) (*sysbench_runner.Result, error) {
serverParams := serverConfig.GetServerArgs()
serverParams, err := serverConfig.GetServerArgs()
if err != nil {
return nil, err
}

var getId func() string
if idFunc == nil {
Expand Down

0 comments on commit 64d3675

Please sign in to comment.