Skip to content

Commit

Permalink
initial base work for pace and concurrency control
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Oct 17, 2020
1 parent 47cc6be commit 9814e0c
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 59 deletions.
161 changes: 147 additions & 14 deletions cmd/ghz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,72 @@ var (
PlaceHolder(" ").IsSetByUser(&isAuthSet).String()

// Run
isAsyncSet = false
async = kingpin.Flag("async", "Make async requests.").
Default("false").IsSetByUser(&isAsyncSet).Bool()

isScheduleSet = false
schedule = kingpin.Flag("load-schedule", "Specifies the load schedule. Options are const, step, or line. Default is const.").
Default("const").IsSetByUser(&isScheduleSet).String()

isQSet = false
q = kingpin.Flag("qps", "Queries per second (QPS) rate limit for constant load. Default is no rate limit.").
Default("0").Short('q').IsSetByUser(&isQSet).Uint()

isLoadStartSet = false
loadStart = kingpin.Flag("load-start", "Specifies the load start value.").
Default("0").IsSetByUser(&isLoadStartSet).Uint()

isLoadStepSet = false
loadStep = kingpin.Flag("load-step", "Specifies the load step value or slope value.").
Default("0").IsSetByUser(&isLoadStepSet).Uint()

isLoadEndSet = false
loadEnd = kingpin.Flag("load-end", "Specifies the load end value.").
Default("0").IsSetByUser(&isLoadEndSet).Uint()

isLoadStepDurSet = false
loadStepDuration = kingpin.Flag("load-step-duration", "Specifies the load step duration value for step load schedule.").
Default("0").IsSetByUser(&isLoadStepDurSet).Duration()

isLoadMaxDurSet = false
loadMaxDuration = kingpin.Flag("load-max-duration", "Specifies the max load duration value for step or line.").
Default("0").IsSetByUser(&isLoadMaxDurSet).Duration()

// Concurrency
isCSet = false
c = kingpin.Flag("concurrency", "Number of requests to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50.").
c = kingpin.Flag("concurrency", "Number of request workers to run concurrently for const concurrency schedule. Default is 50.").
Short('c').Default("50").IsSetByUser(&isCSet).Uint()

isCScheduleSet = false
cschdule = kingpin.Flag("concurrency-schedule", "Concurrency change schedule. Options are const, step, or line. Default is const.").
Default("const").IsSetByUser(&isCScheduleSet).String()

isCMinSet = false
cmin = kingpin.Flag("concurrency-min", "Concurrency minimum / start value for step and line schedules.").
Default("0").IsSetByUser(&isCMinSet).Uint()

isCMaxSet = false
cmax = kingpin.Flag("concurrency-max", "Concurrency maximum / end value for step and line schedules.").
Default("0").IsSetByUser(&isCMaxSet).Uint()

isCStepSet = false
cstep = kingpin.Flag("concurrency-step", "Concurrency step / slope value for step and line schedules.").
Default("1").IsSetByUser(&isCStepSet).Uint()

isCStepDurSet = false
cStepDuration = kingpin.Flag("concurrency-step-duration", "Specifies the concurrency step duration value for step concurrency schedule.").
Default("0").IsSetByUser(&isCStepDurSet).Duration()

isCMaxDurSet = false
cMaxDuration = kingpin.Flag("concurrency-max-duration", "Specifies the max concurrency adjustment duration value for step or line concurrency schedule.").
Default("0").IsSetByUser(&isCMaxDurSet).Duration()

// Other
isNSet = false
n = kingpin.Flag("total", "Number of requests to run. Default is 200.").
Short('n').Default("200").IsSetByUser(&isNSet).Uint()

isQSet = false
q = kingpin.Flag("qps", "Rate limit, in queries per second (QPS). Default is no rate limit.").
Default("0").Short('q').IsSetByUser(&isQSet).Uint()

isTSet = false
t = kingpin.Flag("timeout", "Timeout for each request. Default is 20s, use 0 for infinite.").
Default("20s").Short('t').IsSetByUser(&isTSet).Duration()
Expand All @@ -102,7 +156,7 @@ var (
Short('x').Default("0").IsSetByUser(&isXSet).Duration()

isZStopSet = false
zstop = kingpin.Flag("duration-stop", "Specifies how duration stop is reported. Options are close, wait or ignore.").
zstop = kingpin.Flag("duration-stop", "Specifies how duration stop is reported. Options are close, wait or ignore. Default is close.").
Default("close").IsSetByUser(&isZStopSet).String()

// Data
Expand Down Expand Up @@ -384,6 +438,19 @@ func createConfigFromArgs(cfg *runner.Config) error {
cfg.ReflectMetadata = rmdMap
cfg.Debug = *debug
cfg.EnableCompression = *enableCompression
cfg.LoadSchedule = *schedule
cfg.LoadStart = *loadStart
cfg.LoadStep = *loadStep
cfg.LoadEnd = *loadEnd
cfg.LoadStepDuration = runner.Duration(*loadStepDuration)
cfg.LoadMaxDuration = runner.Duration(*loadMaxDuration)
cfg.Async = *async
cfg.CSchedule = *cschdule
cfg.CMin = *cmin
cfg.CStep = *cstep
cfg.CMax = *cmax
cfg.CStepDuration = runner.Duration(*cStepDuration)
cfg.CMaxDuration = runner.Duration(*cMaxDuration)

return nil
}
Expand All @@ -393,6 +460,8 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
return errors.New("config cannot be nil")
}

// proto

if isProtoSet {
dest.Proto = src.Proto
}
Expand All @@ -405,6 +474,8 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.Call = src.Call
}

// security

if isCACertSet {
dest.RootCert = src.RootCert
}
Expand Down Expand Up @@ -437,18 +508,12 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.CName = src.CName
}

// run

if isNSet {
dest.N = src.N
}

if isCSet {
dest.C = src.C
}

if isQSet {
dest.QPS = src.QPS
}

if isZSet {
dest.Z = src.Z
}
Expand All @@ -465,6 +530,8 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.ZStop = src.ZStop
}

// data

if isDataSet {
dest.Data = src.Data
}
Expand All @@ -489,6 +556,8 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.MetadataPath = src.MetadataPath
}

// other

if isSISet {
dest.SI = src.SI
}
Expand Down Expand Up @@ -541,6 +610,70 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.Host = src.Host
}

// load

if isAsyncSet {
dest.Async = src.Async
}

if isQSet {
dest.QPS = src.QPS
}

if isScheduleSet {
dest.LoadSchedule = src.LoadSchedule
}

if isLoadStartSet {
dest.LoadStart = src.LoadStart
}

if isLoadStepSet {
dest.LoadStep = src.LoadStep
}

if isLoadEndSet {
dest.LoadEnd = src.LoadEnd
}

if isLoadStepDurSet {
dest.LoadStepDuration = src.LoadStepDuration
}

if isLoadMaxDurSet {
dest.LoadMaxDuration = src.LoadMaxDuration
}

// concurrency

if isCSet {
dest.C = src.C
}

if isCScheduleSet {
dest.CSchedule = src.CSchedule
}

if isCMinSet {
dest.CMin = src.CMin
}

if isCStepSet {
dest.CStep = src.CStep
}

if isCMaxSet {
dest.CMax = src.CMax
}

if isCStepDurSet {
dest.CStepDuration = src.CStepDuration
}

if isCMaxDurSet {
dest.CMaxDuration = src.CMaxDuration
}

return nil
}

Expand Down
14 changes: 13 additions & 1 deletion runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (d Duration) String() string {

// UnmarshalJSON is our custom unmarshaller with JSON support
func (d *Duration) UnmarshalJSON(text []byte) error {
// strValue := string(text)
first := text[0]
last := text[len(text)-1]
if first == '"' && last == '"' {
Expand Down Expand Up @@ -68,7 +67,14 @@ type Config struct {
Authority string `json:"authority" toml:"authority" yaml:"authority"`
Insecure bool `json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty"`
N uint `json:"total" toml:"total" yaml:"total" default:"200"`
Async bool `json:"async,omitempty" toml:"async,omitempty" yaml:"async,omitempty"`
C uint `json:"concurrency" toml:"concurrency" yaml:"concurrency" default:"50"`
CSchedule string `json:"concurrency-schedule" toml:"concurrency-schedule" yaml:"concurrency-schedule" default:"const"`
CMin uint `json:"concurrency-min" toml:"concurrency-min" yaml:"concurrency-min" default:"1"`
CMax uint `json:"concurrency-max" toml:"concurrency-max" yaml:"concurrency-max" default:"0"`
CStep uint `json:"concurrency-step" toml:"concurrency-step" yaml:"concurrency-step" default:"0"`
CStepDuration Duration `json:"concurrency-step-duration" toml:"concurrency-step-duration" yaml:"concurrency-step-duration" default:"0"`
CMaxDuration Duration `json:"concurrency-max-duration" toml:"concurrency-max-duration" yaml:"concurrency-max-duration" default:"0"`
Connections uint `json:"connections" toml:"connections" yaml:"connections" default:"1"`
QPS uint `json:"qps" toml:"qps" yaml:"qps"`
Z Duration `json:"duration" toml:"duration" yaml:"duration"`
Expand All @@ -94,6 +100,12 @@ type Config struct {
Debug string `json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty"`
Host string `json:"host" toml:"host" yaml:"host"`
EnableCompression bool `json:"enable-compression,omitempty" toml:"enable-compression,omitempty" yaml:"enable-compression,omitempty"`
LoadSchedule string `json:"load-schedule" toml:"load-schedule" yaml:"load-schedule" default:"const"`
LoadStart uint `json:"load-start" toml:"load-start" yaml:"load-start"`
LoadEnd uint `json:"load-end" toml:"load-end" yaml:"load-end"`
LoadStep uint `json:"load-step" toml:"load-step" yaml:"load-step"`
LoadStepDuration Duration `json:"load-step-duration" toml:"load-step-duration" yaml:"load-step-duration"`
LoadMaxDuration Duration `json:"load-max-duration" toml:"load-max-duration" yaml:"load-max-duration"`
}

func checkData(data interface{}) error {
Expand Down
7 changes: 5 additions & 2 deletions runner/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ func TestConfig_Load(t *testing.T) {
Data: map[string]interface{}{
"f_strings": []interface{}{"123", "456"},
},
Format: "summary",
DialTimeout: Duration(10 * time.Second),
Format: "summary",
DialTimeout: Duration(10 * time.Second),
LoadSchedule: "const",
CSchedule: "const",
CMin: 1,
},
true,
},
Expand Down
Loading

0 comments on commit 9814e0c

Please sign in to comment.