Skip to content

Commit

Permalink
qps -> rps. add load walktrough. wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Oct 22, 2020
1 parent 05b30b9 commit 8eaf49b
Show file tree
Hide file tree
Showing 20 changed files with 937 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Flags:
--insecure Use plaintext and insecure connection.
--authority= Value to be used as the :authority pseudo-header. Only works if -insecure is used.
--async Make requests asynchronous as soon as possible. Does not wait for request to finish before sending next one.
-q, --qps=0 Queries per second (QPS) rate limit for constant load schedule. Default is no rate limit.
-r, --rps=0 Requests per second (RPS) rate limit for constant load schedule. Default is no rate limit.
--load-schedule="const" Specifies the load schedule. Options are const, step, or line. Default is const.
--load-start=0 Specifies the qps load start value for step or line schedules.
--load-start=0 Specifies the RPS load start value for step or line schedules.
--load-step=0 Specifies the load step value or slope value.
--load-end=0 Specifies the load end value for step or line load schedules.
--load-step-duration=0 Specifies the load step duration value for step load schedule.
Expand Down
14 changes: 7 additions & 7 deletions cmd/ghz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ var (
async = kingpin.Flag("async", "Make requests asynchronous as soon as possible. Does not wait for request to finish before sending next one.").
Default("false").IsSetByUser(&isAsyncSet).Bool()

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

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()

isLoadStartSet = false
loadStart = kingpin.Flag("load-start", "Specifies the qps load start value for step or line schedules.").
loadStart = kingpin.Flag("load-start", "Specifies the RPS load start value for step or line schedules.").
Default("0").IsSetByUser(&isLoadStartSet).Uint()

isLoadStepSet = false
Expand Down Expand Up @@ -414,7 +414,7 @@ func createConfigFromArgs(cfg *runner.Config) error {
cfg.CName = *cname
cfg.N = *n
cfg.C = *c
cfg.QPS = *q
cfg.RPS = *rps
cfg.Z = runner.Duration(*z)
cfg.X = runner.Duration(*x)
cfg.Timeout = runner.Duration(*t)
Expand Down Expand Up @@ -616,8 +616,8 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.Async = src.Async
}

if isQSet {
dest.QPS = src.QPS
if isRPSSet {
dest.RPS = src.RPS
}

if isScheduleSet {
Expand Down
2 changes: 1 addition & 1 deletion printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (rp *ReportPrinter) getInfluxTags(addErrors bool) string {
s = append(s, fmt.Sprintf(`host="%v"`, options.Host))
s = append(s, fmt.Sprintf("n=%v", options.Total))
s = append(s, fmt.Sprintf("c=%v", options.Concurrency))
s = append(s, fmt.Sprintf("qps=%v", options.QPS))
s = append(s, fmt.Sprintf("rps=%v", options.RPS))
s = append(s, fmt.Sprintf("z=%v", options.Duration.Nanoseconds()))
s = append(s, fmt.Sprintf("timeout=%v", options.Timeout.Seconds()))
s = append(s, fmt.Sprintf("dial_timeout=%v", options.DialTimeout.Seconds()))
Expand Down
6 changes: 3 additions & 3 deletions printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPrinter_getInfluxLine(t *testing.T) {
{
"empty",
runner.Report{},
`ghz_run,call="",host="",n=0,c=0,qps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="null",metadata="",tags="",errors=0,has_errors=false count=0,total=0,average=0,fastest=0,slowest=0,rps=0.00,errors=0 0`,
`ghz_run,call="",host="",n=0,c=0,rps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="null",metadata="",tags="",errors=0,has_errors=false count=0,total=0,average=0,fastest=0,slowest=0,rps=0.00,errors=0 0`,
},
{
"basic",
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestPrinter_getInfluxLine(t *testing.T) {
},
},
},
fmt.Sprintf(`ghz_run,name="run\ name",proto="/apis/greeter.proto",call="helloworld.Greeter.SayHello",host="0.0.0.0:50051",n=200,c=50,qps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="{\"name\":\"Bob\ Smith\"}",metadata="{\"foo\ bar\":\"biz\ baz\"}",tags="",errors=5,has_errors=true count=200,total=2000000000,average=10000000,fastest=1000000,slowest=100000000,rps=2000.00,median=5000000,p95=20000000,errors=5 %+v`, unixTimeNow),
fmt.Sprintf(`ghz_run,name="run\ name",proto="/apis/greeter.proto",call="helloworld.Greeter.SayHello",host="0.0.0.0:50051",n=200,c=50,rps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="{\"name\":\"Bob\ Smith\"}",metadata="{\"foo\ bar\":\"biz\ baz\"}",tags="",errors=5,has_errors=true count=200,total=2000000000,average=10000000,fastest=1000000,slowest=100000000,rps=2000.00,median=5000000,p95=20000000,errors=5 %+v`, unixTimeNow),
},
}

Expand Down Expand Up @@ -235,7 +235,7 @@ func TestPrinter_printInfluxDetails(t *testing.T) {
},
},
},
fmt.Sprintf(`ghz_detail,name="run\ name",proto="/apis/greeter.proto",call="helloworld.Greeter.SayHello",host="0.0.0.0:50051",n=200,c=50,qps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="{\"name\":\"Bob\ Smith\"}",metadata="{\"foo\ bar\":\"biz\ baz\"}",tags="",hasError=false latency=1000000,error="",status="OK" %+v
fmt.Sprintf(`ghz_detail,name="run\ name",proto="/apis/greeter.proto",call="helloworld.Greeter.SayHello",host="0.0.0.0:50051",n=200,c=50,rps=0,z=0,timeout=0,dial_timeout=0,keepalive=0,data="{\"name\":\"Bob\ Smith\"}",metadata="{\"foo\ bar\":\"biz\ baz\"}",tags="",hasError=false latency=1000000,error="",status="OK" %+v
`, unixTimeNow),
},
}
Expand Down
2 changes: 1 addition & 1 deletion runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type Config struct {
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"`
RPS uint `json:"rps" toml:"rps" yaml:"rps"`
Z Duration `json:"duration" toml:"duration" yaml:"duration"`
ZStop string `json:"duration-stop" toml:"duration-stop" yaml:"duration-stop" default:"close"`
X Duration `json:"max-duration" toml:"max-duration" yaml:"max-duration"`
Expand Down
12 changes: 6 additions & 6 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type RunConfig struct {
authority string

// load
qps int
rps int
loadStart uint
loadEnd uint
loadStep int
Expand Down Expand Up @@ -247,11 +247,11 @@ func WithConcurrency(c uint) Option {
}
}

// WithQPS specifies the QPS (queries per second) limit option
// WithQPS(10)
func WithQPS(qps uint) Option {
// WithRPS specifies the RPS (requests per second) limit option
// WithRPS(10)
func WithRPS(v uint) Option {
return func(o *RunConfig) error {
o.qps = int(qps)
o.rps = int(v)

return nil
}
Expand Down Expand Up @@ -907,7 +907,7 @@ func fromConfig(cfg *Config) []Option {
WithAuthority(cfg.Authority),
WithConcurrency(cfg.C),
WithTotalRequests(cfg.N),
WithQPS(cfg.QPS),
WithRPS(cfg.RPS),
WithTimeout(time.Duration(cfg.Timeout)),
WithRunDuration(time.Duration(cfg.Z)),
WithDialTimeout(time.Duration(cfg.DialTimeout)),
Expand Down
22 changes: 11 additions & 11 deletions runner/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, false, c.insecure)
assert.Equal(t, 200, c.n)
assert.Equal(t, 50, c.c)
assert.Equal(t, 0, c.qps)
assert.Equal(t, 0, c.rps)
assert.Equal(t, false, c.binary)
assert.Equal(t, 0, c.skipFirst)
assert.Equal(t, time.Duration(0), c.z)
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
WithInsecure(true),
WithTotalRequests(100),
WithConcurrency(20),
WithQPS(5),
WithRPS(5),
WithSkipFirst(5),
WithRunDuration(time.Duration(5*time.Minute)),
WithKeepalive(time.Duration(60*time.Second)),
Expand All @@ -100,7 +100,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, true, c.insecure)
assert.Equal(t, math.MaxInt32, c.n)
assert.Equal(t, 20, c.c)
assert.Equal(t, 5, c.qps)
assert.Equal(t, 5, c.rps)
assert.Equal(t, 5, c.skipFirst)
assert.Equal(t, false, c.binary)
assert.Equal(t, time.Duration(5*time.Minute), c.z)
Expand All @@ -126,7 +126,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
WithAuthority("someauth"),
WithTotalRequests(100),
WithConcurrency(20),
WithQPS(5),
WithRPS(5),
WithSkipFirst(5),
WithKeepalive(time.Duration(60*time.Second)),
WithTimeout(time.Duration(10*time.Second)),
Expand All @@ -149,7 +149,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, "someauth", c.authority)
assert.Equal(t, 100, c.n)
assert.Equal(t, 20, c.c)
assert.Equal(t, 5, c.qps)
assert.Equal(t, 5, c.rps)
assert.Equal(t, 5, c.skipFirst)
assert.Equal(t, true, c.binary)
assert.Equal(t, time.Duration(0), c.z)
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
WithCertificate("../testdata/localhost.crt", "../testdata/localhost.key"),
WithInsecure(true),
WithConcurrency(20),
WithQPS(5),
WithRPS(5),
WithSkipFirst(5),
WithRunDuration(time.Duration(5*time.Minute)),
WithKeepalive(time.Duration(60*time.Second)),
Expand All @@ -218,7 +218,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, "../testdata/localhost.key", c.key)
assert.Equal(t, math.MaxInt32, c.n)
assert.Equal(t, 20, c.c)
assert.Equal(t, 5, c.qps)
assert.Equal(t, 5, c.rps)
assert.Equal(t, 5, c.skipFirst)
assert.Equal(t, false, c.binary)
assert.Equal(t, time.Duration(5*time.Minute), c.z)
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, false, c.insecure)
assert.Equal(t, 200, c.n)
assert.Equal(t, 50, c.c)
assert.Equal(t, 0, c.qps)
assert.Equal(t, 0, c.rps)
assert.Equal(t, 0, c.skipFirst)
assert.Equal(t, time.Duration(0), c.z)
assert.Equal(t, time.Duration(0), c.keepaliveTime)
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, false, c.insecure)
assert.Equal(t, 200, c.n)
assert.Equal(t, 50, c.c)
assert.Equal(t, 0, c.qps)
assert.Equal(t, 0, c.rps)
assert.Equal(t, 0, c.skipFirst)
assert.Equal(t, false, c.binary)
assert.Equal(t, time.Duration(0), c.z)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, false, c.insecure)
assert.Equal(t, 200, c.n)
assert.Equal(t, 50, c.c)
assert.Equal(t, 0, c.qps)
assert.Equal(t, 0, c.rps)
assert.Equal(t, 0, c.skipFirst)
assert.Equal(t, 1, c.nConns)
assert.Equal(t, false, c.binary)
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
assert.Equal(t, false, c.insecure)
assert.Equal(t, 200, c.n)
assert.Equal(t, 50, c.c)
assert.Equal(t, 0, c.qps)
assert.Equal(t, 0, c.rps)
assert.Equal(t, 0, c.skipFirst)
assert.Equal(t, 5, c.nConns)
assert.Equal(t, false, c.binary)
Expand Down
4 changes: 2 additions & 2 deletions runner/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Options struct {
Insecure bool `json:"insecure"`
Total uint `json:"total,omitempty"`
Concurrency uint `json:"concurrency,omitempty"`
QPS uint `json:"qps,omitempty"`
RPS uint `json:"rps,omitempty"`
Connections uint `json:"connections,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report
Authority: r.config.authority,
Total: uint(r.config.n),
Concurrency: uint(r.config.c),
QPS: uint(r.config.qps),
RPS: uint(r.config.rps),
Connections: uint(r.config.nConns),
Duration: r.config.z,
Timeout: r.config.timeout,
Expand Down
2 changes: 1 addition & 1 deletion runner/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func createPacer(config *RunConfig) load.Pacer {
Max: uint64(config.n),
}
default:
p = &load.ConstantPacer{Freq: uint64(config.qps), Max: uint64(config.n)}
p = &load.ConstantPacer{Freq: uint64(config.rps), Max: uint64(config.n)}
}

return p
Expand Down
4 changes: 2 additions & 2 deletions runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestRunUnary(t *testing.T) {
assert.Equal(t, 1, connCount)
})

t.Run("test QPS", func(t *testing.T) {
t.Run("test RPS", func(t *testing.T) {

gs.ResetCounters()

Expand All @@ -258,7 +258,7 @@ func TestRunUnary(t *testing.T) {
WithProtoFile("../testdata/greeter.proto", []string{}),
WithTotalRequests(10),
WithConcurrency(2),
WithQPS(1),
WithRPS(1),
WithTimeout(time.Duration(20*time.Second)),
WithDialTimeout(time.Duration(20*time.Second)),
WithData(data),
Expand Down
2 changes: 1 addition & 1 deletion testdata/config/config0.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"keepalive": 0,
"total": 1000,
"concurrency": 1,
"qps": 0,
"rps": 0,
"host": "127.0.0.1:9000",
"data": "foo"
}
4 changes: 2 additions & 2 deletions testdata/config/config0.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ keepalive = 0
total = 1000
# Number of requests to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50.
concurrency = 1
# Rate limit, in queries per second (QPS). Default is no rate limit.
qps = 0
# Rate limit, in requests per second (RPS). Default is no rate limit.
RPS = 0
host = "127.0.0.1:9000"
data="""
{
Expand Down
2 changes: 1 addition & 1 deletion testdata/config/config0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ connections: 3
keepalive: 0
total: 1000
concurrency: 1
qps: 0
rps: 0
host: 127.0.0.1:9000
data: foo
Loading

0 comments on commit 8eaf49b

Please sign in to comment.