load

package
v0.94.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstWorkerTicker

type ConstWorkerTicker struct {
	C chan TickValue // The tick value channel
	N uint           // The number of workers
}

ConstWorkerTicker represents a constant number of workers. It would send one value for initial number of workers to start.

func (*ConstWorkerTicker) Finish

func (c *ConstWorkerTicker) Finish()

Finish closes the channel.

func (*ConstWorkerTicker) Run

func (c *ConstWorkerTicker) Run()

Run runs the ticker.

func (*ConstWorkerTicker) Ticker

func (c *ConstWorkerTicker) Ticker() <-chan TickValue

Ticker returns the ticker channel.

type ConstantPacer

type ConstantPacer struct {
	Freq uint64 // Frequency of hits per second
	Max  uint64 // Optional maximum allowed hits
}

A ConstantPacer defines a constant rate of hits.

func (*ConstantPacer) Pace

func (cp *ConstantPacer) Pace(elapsed time.Duration, hits uint64) (time.Duration, bool)

Pace determines the length of time to sleep until the next hit is sent.

func (*ConstantPacer) Rate

func (cp *ConstantPacer) Rate(elapsed time.Duration) float64

Rate returns a ConstantPacer's instantaneous hit rate (i.e. requests per second) at the given elapsed duration of an attack. Since it's constant, the return value is independent of the given elapsed duration.

func (*ConstantPacer) String

func (cp *ConstantPacer) String() string

String returns a pretty-printed description of the ConstantPacer's behaviour:

ConstantPacer{Freq: 1} => Constant{1 hits / 1s}

type LineWorkerTicker

type LineWorkerTicker struct {
	C chan TickValue // The tick value channel

	Start       uint          // Starting number of workers
	Slope       int           // Slope value to adjust the number of workers
	Stop        uint          // Final number of workers
	MaxDuration time.Duration // Maximum adjustment duration
	// contains filtered or unexported fields
}

LineWorkerTicker is the worker ticker that implements line adjustments to concurrency. Essentially this is same as step worker with 1s step duration.

func (*LineWorkerTicker) Finish

func (c *LineWorkerTicker) Finish()

Finish closes the internal tick value channel.

func (*LineWorkerTicker) Run

func (c *LineWorkerTicker) Run()

Run runs the ticker.

func (*LineWorkerTicker) Ticker

func (c *LineWorkerTicker) Ticker() <-chan TickValue

Ticker returns the ticker channel.

type LinearPacer

type LinearPacer struct {
	Start        ConstantPacer // Constant start rate
	Slope        int64         // Slope value to change the rate
	Stop         ConstantPacer // Constant stop rate
	LoadDuration time.Duration // Total maximum load duration
	Max          uint64        // Maximum number of hits
	// contains filtered or unexported fields
}

LinearPacer paces the hit rate by starting at a given request rate and increasing linearly with the given slope at 1s interval.

func (*LinearPacer) Pace

func (p *LinearPacer) Pace(elapsed time.Duration, hits uint64) (time.Duration, bool)

Pace determines the length of time to sleep until the next hit is sent.

func (*LinearPacer) Rate

func (p *LinearPacer) Rate(elapsed time.Duration) float64

Rate returns a LinearPacer's instantaneous hit rate (i.e. requests per second) at the given elapsed duration.

func (*LinearPacer) String

func (p *LinearPacer) String() string

String returns a pretty-printed description of the LinearPacer's behaviour:

LinearPacer{Slope: 1} => Linear{1 hits / 1s}

type Pacer

type Pacer interface {
	// Pace returns the duration the attacker should wait until
	// making next hit, given an already elapsed duration and
	// completed hits. If the second return value is true, an attacker
	// should stop sending hits.
	Pace(elapsed time.Duration, hits uint64) (wait time.Duration, stop bool)

	// Rate returns a Pacer's instantaneous hit rate (per seconds)
	// at the given elapsed duration of an attack.
	Rate(elapsed time.Duration) float64
}

Pacer defines the interface to control the rate of hit.

type StepPacer

type StepPacer struct {
	Start        ConstantPacer // Constant start rate
	Step         int64         // Step value
	StepDuration time.Duration // Step duration
	Stop         ConstantPacer // Optional constant stop value
	LoadDuration time.Duration // Optional maximum load duration
	Max          uint64        // Optional maximum allowed hits
	// contains filtered or unexported fields
}

StepPacer paces an attack by starting at a given request rate and increasing or decreasing with steps at a given step interval and duration.

func (*StepPacer) Pace

func (p *StepPacer) Pace(elapsed time.Duration, hits uint64) (time.Duration, bool)

Pace determines the length of time to sleep until the next hit is sent.

func (*StepPacer) Rate

func (p *StepPacer) Rate(elapsed time.Duration) float64

Rate returns a StepPacer's instantaneous hit rate (i.e. requests per second) at the given elapsed duration.

func (*StepPacer) String

func (p *StepPacer) String() string

String returns a pretty-printed description of the StepPacer's behaviour:

StepPacer{Step: 1, StepDuration: 5s} => Step{Step:1 hits / 5s}

type StepWorkerTicker

type StepWorkerTicker struct {
	C chan TickValue // The tick value channel

	Start        uint          // Starting number of workers
	Step         int           // Step change
	StepDuration time.Duration // Duration to apply the step change
	Stop         uint          // Final number of workers
	MaxDuration  time.Duration // Maximum duration
}

StepWorkerTicker is the worker ticker that implements step adjustments to worker concurrency.

func (*StepWorkerTicker) Finish

func (c *StepWorkerTicker) Finish()

Finish closes the channel.

func (*StepWorkerTicker) Run

func (c *StepWorkerTicker) Run()

Run runs the ticker.

func (*StepWorkerTicker) Ticker

func (c *StepWorkerTicker) Ticker() <-chan TickValue

Ticker returns the ticker channel.

type TickValue

type TickValue struct {
	Delta int  // Delta value representing worker increase or decrease
	Done  bool // A flag representing whether the ticker is done running. Once true no more values should be received over the ticker channel.
}

TickValue is the tick value sent over the ticker channel.

type WorkerTicker

type WorkerTicker interface {
	// Ticker returns a channel which sends TickValues
	// When a value is received the number of workers should be appropriately
	// increased or decreased given by the delta property.
	Ticker() <-chan TickValue

	// Run starts the worker ticker
	Run()

	// Finish closes the channel
	Finish()
}

WorkerTicker is the interface controlling worker parallelism.

Jump to

Keyboard shortcuts

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