Skip to content

Commit

Permalink
Merge pull request #1 from sujitdmello/skipFirstOption
Browse files Browse the repository at this point in the history
Added the skipFirst option for warmup delays
  • Loading branch information
sujitdmello authored Jul 10, 2020
2 parents 02c0138 + d58bcb9 commit 4cea308
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Flags:
--key= File containing client private key, to present to the server. Must also provide -cert option.
--cname= Server name override when validating TLS certificate - useful for self signed certs.
--skipTLS Skip TLS client verification of the server's certificate chain and host name.
--skipFirst Skip the first X requests from the timing calculations (useful for initial warmup)
--insecure Use plaintext and insecure connection.
--authority= Value to be used as the :authority pseudo-header. Only works if -insecure is used.
-c, --concurrency=50 Number of requests to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50.
Expand Down
9 changes: 9 additions & 0 deletions cmd/ghz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var (
skipVerify = kingpin.Flag("skipTLS", "Skip TLS client verification of the server's certificate chain and host name.").
Default("false").IsSetByUser(&isSkipSet).Bool()

isSkipFirstSet = false
skipFirst = kingpin.Flag("skipFirst", "Skip the first X requests when doing the results tally.").
Default("0").IsSetByUser(&isSkipFirstSet).Uint()

isInsecSet = false
insecure = kingpin.Flag("insecure", "Use plaintext and insecure connection.").
Default("false").IsSetByUser(&isInsecSet).Bool()
Expand Down Expand Up @@ -357,6 +361,7 @@ func createConfigFromArgs(cfg *runner.Config) error {
cfg.Cert = *cert
cfg.Key = *key
cfg.SkipTLSVerify = *skipVerify
cfg.SkipFirst = *skipFirst
cfg.Insecure = *insecure
cfg.Authority = *authority
cfg.CName = *cname
Expand Down Expand Up @@ -423,6 +428,10 @@ func mergeConfig(dest *runner.Config, src *runner.Config) error {
dest.SkipTLSVerify = src.SkipTLSVerify
}

if isSkipFirstSet {
dest.SkipFirst = src.SkipFirst
}

if isInsecSet {
dest.Insecure = src.Insecure
}
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ require (
github.com/alecthomas/kingpin v1.3.8-0.20191105203113-8c96d1c22481
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/bojand/hri v1.1.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/go-playground/validator v9.30.0+incompatible
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
github.com/golangci/golangci-lint v1.27.0 // indirect
github.com/google/uuid v1.1.1
github.com/jhump/protoreflect v1.5.0
github.com/jinzhu/configor v1.1.1
github.com/jinzhu/gorm v1.9.11
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mfridman/tparse v0.7.4 // indirect
github.com/pkg/errors v0.8.1
github.com/rakyll/statik v0.1.6
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.5.1
go.uber.org/multierr v1.3.0
go.uber.org/zap v1.13.0
golang.org/x/net v0.0.0-20191021144547-ec77196f6094
golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect
google.golang.org/grpc v1.24.0
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)
286 changes: 286 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Config struct {
Cert string `json:"cert" toml:"cert" yaml:"cert"`
Key string `json:"key" toml:"key" yaml:"key"`
SkipTLSVerify bool `json:"skipTLS" toml:"skipTLS" yaml:"skipTLS"`
SkipFirst uint `json:"skipFirst" toml:"skipFirst" yaml:"skipFirst"`
CName string `json:"cname" toml:"cname" yaml:"cname"`
Authority string `json:"authority" toml:"authority" yaml:"authority"`
Insecure bool `json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty"`
Expand Down
21 changes: 17 additions & 4 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ type RunConfig struct {
log Logger

// misc
name string
cpus int
tags []byte
name string
cpus int
tags []byte
skipFirst uint
}

// Option controls some aspect of run
Expand Down Expand Up @@ -450,6 +451,17 @@ func WithCPUs(c uint) Option {
}
}

// WithSkipFirst is the skipFirst option
func WithSkipFirst(c uint) Option {
return func(o *RunConfig) error {
if c > 0 {
o.skipFirst = uint(c)
}

return nil
}
}

// WithProtoFile specified proto file path and optionally import paths
// We will automatically add the proto file path's directory and the current directory
// WithProtoFile("greeter.proto", []string{"/home/protos"})
Expand All @@ -458,7 +470,7 @@ func WithProtoFile(proto string, importPaths []string) Option {
proto = strings.TrimSpace(proto)
if proto != "" {
if filepath.Ext(proto) != ".proto" {
return errors.Errorf(fmt.Sprintf("proto: must have .proto extension"))
return errors.New("proto: must have .proto extension")
}

o.proto = proto
Expand Down Expand Up @@ -648,6 +660,7 @@ func fromConfig(cfg *Config) []Option {
WithCertificate(cfg.Cert, cfg.Key),
WithServerNameOverride(cfg.CName),
WithSkipTLSVerify(cfg.SkipTLSVerify),
WithSkipFirst(cfg.SkipFirst),
WithInsecure(cfg.Insecure),
WithAuthority(cfg.Authority),
WithConcurrency(cfg.C),
Expand Down
9 changes: 8 additions & 1 deletion runner/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Options struct {
Cert string `json:"cert,omitempty"`
Key string `json:"key,omitempty"`
SkipTLS bool `json:"skipTLS,omitempty"`
SkipFirst uint `json:"skipFirst,omitempty"`
CName string `json:"cname,omitempty"`
Authority string `json:"authority,omitempty"`
Insecure bool `json:"insecure"`
Expand Down Expand Up @@ -133,9 +134,14 @@ func newReporter(results chan *callResult, c *RunConfig) *Reporter {

// Run runs the reporter
func (r *Reporter) Run() {
var skipCount uint

for res := range r.results {
if skipCount < r.config.skipFirst {
skipCount++
continue
}
errStr := ""

r.totalCount++
r.totalLatenciesSec += res.duration.Seconds()
r.statusCodeDist[res.status]++
Expand Down Expand Up @@ -179,6 +185,7 @@ func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report
Key: r.config.key,
CName: r.config.cname,
SkipTLS: r.config.skipVerify,
SkipFirst: r.config.skipFirst,
Insecure: r.config.insecure,
Authority: r.config.authority,
Total: uint(r.config.n),
Expand Down

0 comments on commit 4cea308

Please sign in to comment.