ghz: github.com/bojand/ghz/load Index | Files

package load

import "github.com/bojand/ghz/load"

Index

Package Files

pacer.go worker_ticker.go

type ConstWorkerTicker Uses

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 Uses

func (c *ConstWorkerTicker) Finish()

Finish closes the channel.

func (*ConstWorkerTicker) Run Uses

func (c *ConstWorkerTicker) Run()

Run runs the ticker.

func (*ConstWorkerTicker) Ticker Uses

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

Ticker returns the ticker channel.

type ConstantPacer Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (c *LineWorkerTicker) Finish()

Finish closes the internal tick value channel.

func (*LineWorkerTicker) Run Uses

func (c *LineWorkerTicker) Run()

Run runs the ticker.

func (*LineWorkerTicker) Ticker Uses

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

Ticker returns the ticker channel.

type LinearPacer Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (c *StepWorkerTicker) Finish()

Finish closes the channel.

func (*StepWorkerTicker) Run Uses

func (c *StepWorkerTicker) Run()

Run runs the ticker.

func (*StepWorkerTicker) Ticker Uses

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

Ticker returns the ticker channel.

type TickValue Uses

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 Uses

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.

Package load imports 4 packages (graph) and is imported by 1 packages. Updated 2020-11-21. Refresh now. Tools for package owners.