bencher

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForConfirmation added in v0.0.5

func AskForConfirmation(s string, in io.Reader) bool

askForConfirmation asks the user for confirmation. A user must type in "yes" or some similar confirmation, no by default

func RegisterHatchRate

func RegisterHatchRate(name string, constructor HatchRateConstructor) error

RegisterHatchRate is an extension method to register new HatchRates used for config resolution

func RegisterInvoker

func RegisterInvoker(name string, constructor InvokerConstructor) error

Extension Method to register more invoker used during config parsing

func SetDefaultLogger

func SetDefaultLogger(_log *logrus.Entry)

Types

type Bencher

type Bencher struct {
	//Some sort of Logger/Writer
	//Worker pool
	Work Workload

	Strict bool
	// contains filtered or unexported fields
}

func BencherFromConfig

func BencherFromConfig(config BenchmarkConfig, workload Workload) (*Bencher, error)

func BencherFromConfigFile

func BencherFromConfigFile(configFile io.ReadCloser) (*Bencher, error)

func BencherReadFromConfig added in v0.0.5

func BencherReadFromConfig(config BenchmarkConfig) (*Bencher, error)

func WithPayloadFunc

func WithPayloadFunc(bencher *Bencher, payloadFunc PayloadFunc) *Bencher

func WithPhasePostRun

func WithPhasePostRun(phaseIndex int, bencher *Bencher, runFunc PostRunFunc) *Bencher

func WithPhasePreRun

func WithPhasePreRun(phaseIndex int, bencher *Bencher, runFunc PreRunFunc) *Bencher

func WithPostRun

func WithPostRun(bencher *Bencher, runFunc PostRunFunc) *Bencher

func WithPreRun

func WithPreRun(bencher *Bencher, runFunc PreRunFunc) *Bencher

func (*Bencher) Run

func (b *Bencher) Run()

type BenchmarkConfig

type BenchmarkConfig struct {
	OutputFile string         `json:"output" yaml:"output"`
	Workload   WorkloadConfig `json:"workload" yaml:"workload"`
}

type ConstantRate

type ConstantRate struct {
	TotalRequests uint64

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ConstantRate) Close

func (f *ConstantRate) Close() error

func (*ConstantRate) OnFailed

func (f *ConstantRate) OnFailed()

func (*ConstantRate) OnQueued

func (f *ConstantRate) OnQueued()

func (*ConstantRate) OnSuccess

func (f *ConstantRate) OnSuccess()

func (*ConstantRate) Setup

func (f *ConstantRate) Setup(ctx context.Context, phase *Phase) (*sync.Cond, error)

func (*ConstantRate) Take

func (f *ConstantRate) Take() error

type FixedRPSRate

type FixedRPSRate struct {
	RPS             int64
	BypassAtFailure bool
	// contains filtered or unexported fields
}

func (*FixedRPSRate) Close

func (f *FixedRPSRate) Close() error

func (*FixedRPSRate) OnFailed

func (f *FixedRPSRate) OnFailed()

func (*FixedRPSRate) OnQueued

func (f *FixedRPSRate) OnQueued()

func (*FixedRPSRate) OnSuccess

func (f *FixedRPSRate) OnSuccess()

func (*FixedRPSRate) Setup

func (f *FixedRPSRate) Setup(ctx context.Context, phase *Phase) (*sync.Cond, error)

func (*FixedRPSRate) Take

func (f *FixedRPSRate) Take() error

type FunctionAPIInvoker

type FunctionAPIInvoker interface {
	Invoker
}

type HTTPInvoker

type HTTPInvoker struct {
	Request     *http.Request
	RequestBody []byte

	// DisableCompression is an option to disable compression in response
	DisableCompression bool

	// DisableKeepAlive is an option to prevents re-use of TCP connections between different HTTP requests
	DisableKeepAlive bool

	// DisableRedirects is an option to prevent the following of HTTP redirects
	DisableRedirects bool

	// H2 is an option to make HTTP/2 requests
	H2 bool

	// Timeout in seconds.
	Timeout int
	// contains filtered or unexported fields
}

TODO: needs testing

func (*HTTPInvoker) Exec

func (h *HTTPInvoker) Exec(rate HatchRate) error

func (*HTTPInvoker) Setup

func (h *HTTPInvoker) Setup(ctx context.Context, phase *Phase, bencher *Bencher) error

type HatchRate

type HatchRate interface {
	//function is called once before starting the phase
	Setup(context.Context, *Phase) (*sync.Cond, error)
	//function should block until the next request should be made
	Take() error
	//call if the invocation was successful
	OnSuccess()
	//call if the invocation failed
	OnFailed()
	//call if the invocation was queued
	OnQueued()

	Close() error
}

func NewRateFromConfig

func NewRateFromConfig(config HatchRateConfig) (HatchRate, error)

type HatchRateConfig

type HatchRateConfig struct {
	Type    string                 `yaml:"type"`
	Options map[string]interface{} `yaml:",inline"`
}

type HatchRateConstructor

type HatchRateConstructor func(config HatchRateConfig) (HatchRate, error)

type Invoker

type Invoker interface {
	Setup(context.Context, *Phase, *Bencher) error
	Exec(rate HatchRate) error
}

func NewInvokerFromConfig

func NewInvokerFromConfig(config InvokerConfig) (Invoker, error)

type InvokerConfig

type InvokerConfig struct {
	Options map[string]interface{} `yaml:",inline"`
	Type    string                 `yaml:"type"`
}

type InvokerConstructor

type InvokerConstructor func(config InvokerConfig) (Invoker, error)

type NoopRate

type NoopRate struct {
	// contains filtered or unexported fields
}

func (*NoopRate) Close

func (n *NoopRate) Close() error

func (*NoopRate) OnFailed

func (n *NoopRate) OnFailed()

func (*NoopRate) OnQueued

func (n *NoopRate) OnQueued()

func (*NoopRate) OnSuccess

func (n *NoopRate) OnSuccess()

func (*NoopRate) Setup

func (n *NoopRate) Setup(ctx context.Context, phase *Phase) (*sync.Cond, error)

func (*NoopRate) Take

func (n *NoopRate) Take() error

type PayloadFunc

type PayloadFunc func(Invoker) []byte

type Phase

type Phase struct {
	Name        string        //unique name, might be used to identify this phase
	Threads     int           //number of threads that send the invocation
	HatchRate   HatchRate     //hatch rate, that governs how often new invocations are performed
	Timeout     time.Duration //max duration of this phase
	Target      string        //the target of this workload, can be an url or platfrom identifier (e.g. function name)
	PayloadFunc PayloadFunc   //if set this function is called during _each_ invocation to generate a payload, use for authentication
	PreRun      PreRunFunc    //if set this function will be called _once_ before running the phase
	PostRun     PostRunFunc   //if set this function will be called _once_ after running the phase
	Invocation  Invoker       //the invocation of this phase, e.g. HTTP or CLI
}

type PhaseConfig

type PhaseConfig struct {
	Name      string          `json:"name" yaml:"name"`
	Threads   int             `json:"threads" yaml:"threads"`
	HatchRate HatchRateConfig `json:"hatchRate" yaml:"hatchRate"`
	Timeout   time.Duration   `json:"timeout" yaml:"timeout"`
}

func (PhaseConfig) Unmarshal

func (c PhaseConfig) Unmarshal(target string, invoker Invoker) (Phase, error)

type PostRunFunc

type PostRunFunc func() error

type PreRunFunc

type PreRunFunc func() error

type SlopingRate

type SlopingRate struct {
	StartRate       int64
	HatchRate       float64
	BypassAtFailure bool
	// contains filtered or unexported fields
}

func (*SlopingRate) Close

func (r *SlopingRate) Close() error

func (*SlopingRate) OnFailed

func (r *SlopingRate) OnFailed()

func (*SlopingRate) OnQueued

func (r *SlopingRate) OnQueued()

func (*SlopingRate) OnSuccess

func (r *SlopingRate) OnSuccess()

func (*SlopingRate) Setup

func (r *SlopingRate) Setup(ctx context.Context, phase *Phase) (*sync.Cond, error)

func (*SlopingRate) Take

func (r *SlopingRate) Take() error

type WhiskInvoker

type WhiskInvoker struct {
	FunctionName string

	RequestPerMinute int64

	Host  string
	Token string

	Request interface{}
	// contains filtered or unexported fields
}

func (*WhiskInvoker) Exec

func (l *WhiskInvoker) Exec(rate HatchRate) error

func (*WhiskInvoker) Setup

func (l *WhiskInvoker) Setup(ctx context.Context, phase *Phase, bencher *Bencher) error

type Workload

type Workload struct {
	Name    string
	Target  string      //the target of this workload, can be an url or platfrom identifier (e.g. function name)
	PreRun  PreRunFunc  //if set this function will be called once before the benchmark
	Phases  []Phase     //phases of the workload
	PostRun PostRunFunc //if set this function will be called once after the benchmark
}

type WorkloadConfig

type WorkloadConfig struct {
	Name       string        `json:"name" yaml:"name"`
	Target     string        `json:"target" yaml:"target"`
	Phases     []PhaseConfig `json:"phases" yaml:"phases"`
	Invocation InvokerConfig `json:"invoker" yaml:"invoker"`
}

func (WorkloadConfig) Unmarshal

func (c WorkloadConfig) Unmarshal() (Workload, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL