Skip to content

Commit

Permalink
add custom pacer and worker ticker configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Nov 20, 2020
1 parent 6c935ef commit c115457
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"text/template"
"time"

"github.com/bojand/ghz/load"
"github.com/jhump/protoreflect/desc"
"github.com/pkg/errors"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -63,6 +64,8 @@ type RunConfig struct {
loadDuration time.Duration
loadStepDuration time.Duration

pacer load.Pacer

// concurrency
c int
cStart uint
Expand All @@ -72,6 +75,8 @@ type RunConfig struct {
cMaxDuration time.Duration
cStepDuration time.Duration

workerTicker load.WorkerTicker

// test
n int
async bool
Expand Down Expand Up @@ -886,6 +891,24 @@ func WithConcurrencyDuration(duration time.Duration) Option {
}
}

// WithPacer specified the custom pacer to use
func WithPacer(p load.Pacer) Option {
return func(o *RunConfig) error {
o.pacer = p

return nil
}
}

// WithWorkerTicker specified the custom worker ticker to use
func WithWorkerTicker(ticker load.WorkerTicker) Option {
return func(o *RunConfig) error {
o.workerTicker = ticker

return nil
}
}

func createClientTransportCredentials(skipVerify bool, cacertFile, clientCertFile, clientKeyFile, cname string) (credentials.TransportCredentials, error) {
var tlsConf tls.Config

Expand Down
8 changes: 8 additions & 0 deletions runner/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ func min(a, b int) int {
}

func createWorkerTicker(config *RunConfig) load.WorkerTicker {
if config.workerTicker != nil {
return config.workerTicker
}

var wt load.WorkerTicker
switch config.cSchedule {
case ScheduleLine:
Expand Down Expand Up @@ -506,6 +510,10 @@ func createWorkerTicker(config *RunConfig) load.WorkerTicker {
}

func createPacer(config *RunConfig) load.Pacer {
if config.pacer != nil {
return config.pacer
}

var p load.Pacer
switch config.loadSchedule {
case ScheduleLine:
Expand Down

0 comments on commit c115457

Please sign in to comment.