stress

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2014 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAttacker = NewAttacker()

DefaultAttacker is the default Attacker used by Attack

Functions

func ReportJSON

func ReportJSON(results []Result) ([]byte, error)

ReportJSON writes a computed Metrics struct to as JSON

func ReportPlot

func ReportPlot(results []Result) ([]byte, error)

ReportPlot builds up a self contained HTML page with an interactive plot of the latencies of the requests. Built with http://dygraphs.com/

func ReportText

func ReportText(results []Result) ([]byte, error)

ReportText returns a computed Metrics struct as aligned, formatted text

Types

type Attacker

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

Attacker is an attack executor, wrapping an http.Client

func NewAttacker

func NewAttacker() *Attacker

NewAttacker returns a pointer to a new Attacker

func (Attacker) AttackConcy

func (a Attacker) AttackConcy(tgts Targets, concurrency uint64, number uint64) Results

func (Attacker) AttackRate

func (a Attacker) AttackRate(tgts Targets, rate uint64, du time.Duration) Results

Attack attacks the passed Targets (http.Requests) at the rate specified for duration time and then waits for all the requests to come back. The results of the attack are put into a slice which is returned.

func (*Attacker) SetRedirects

func (a *Attacker) SetRedirects(redirects int)

SetRedirects sets the max amount of redirects the attacker's http client will follow.

func (*Attacker) SetTimeout

func (a *Attacker) SetTimeout(timeout time.Duration)

SetTimeout sets the client side timeout for each request the attacker makes.

type Metrics

type Metrics struct {
	Latencies struct {
		Mean time.Duration `json:"mean"`
		P50  time.Duration `json:"50th"` // P50 is the 50th percentile upper value
		P95  time.Duration `json:"95th"` // P95 is the 95th percentile upper value
		P99  time.Duration `json:"99th"` // P99 is the 99th percentile upper value
		Max  time.Duration `json:"max"`
	} `json:"latencies"`

	BytesIn struct {
		Total uint64  `json:"total"`
		Mean  float64 `json:"mean"`
	} `json:"bytes_in"`

	BytesOut struct {
		Total uint64  `json:"total"`
		Mean  float64 `json:"mean"`
	} `json:"bytes_out"`

	Duration    time.Duration  `json:"duration"`
	Requests    uint64         `json:"requests"`
	Qps         float64        `json:"qps"`
	Success     float64        `json:"success"`
	StatusCodes map[string]int `json:"status_codes"`
	Errors      []string       `json:"errors"`
}

Metrics holds the stats computed out of a slice of Results that is used for some of the Reporters

func NewMetrics

func NewMetrics(results []Result) *Metrics

NewMetrics computes and returns a Metrics struct out of a slice of Results

type Reporter

type Reporter func([]Result) ([]byte, error)

Reporter represents any function which takes a slice of Results and generates a report returned as a slice of bytes and an error in case of failure

type Result

type Result struct {
	Code      uint16
	Timestamp time.Time
	Latency   time.Duration
	BytesOut  uint64
	BytesIn   uint64
	Error     string
}

Result represents the metrics defined out of an http.Response generated by each target hit

type Results

type Results []Result

Results is a slice of Result structs with encoding, decoding and sorting behavior attached

func AttackConcy

func AttackConcy(tgts Targets, concurrency uint64, number uint64) Results

func AttackRate

func AttackRate(tgts Targets, rate uint64, du time.Duration) Results

Attack hits the passed Targets (http.Requests) at the rate specified for duration time and then waits for all the requests to come back. The results of the attack are put into a slice which is returned.

Attack is a wrapper around DefaultAttacker.Attack

func (*Results) Decode

func (r *Results) Decode(in io.Reader) error

Decode reads data from an io.Reader and decodes it into a Results struct returning an error in case of failure

func (Results) Encode

func (r Results) Encode(out io.Writer) error

Encode encodes the results and writes it to an io.Writer returning an error in case of failure

func (Results) Len

func (r Results) Len() int

func (Results) Less

func (r Results) Less(i, j int) bool

func (Results) Sort

func (r Results) Sort() Results

Sort sorts Results by Timestamp in ascending order and returns the sorted slice

func (Results) Swap

func (r Results) Swap(i, j int)

type Target

type Target struct {
	Method string
	URL    string
	Body   []byte
	File   string
	Header headers
}

Target is a HTTP request blueprint

func (*Target) Request

func (t *Target) Request() (*http.Request, error)

Request creates an *http.Request out of Target and returns it along with an error in case of failure.

type Targets

type Targets []Target

Targets is a slice of Targets which can be shuffled

func NewTargets

func NewTargets(lines []string, body []byte, header http.Header) (Targets, error)

NewTargets instantiates Targets from a slice of strings. It sets the passed body and http.Header on all targets.

func NewTargetsFrom

func NewTargetsFrom(source io.Reader, body []byte, header http.Header) (Targets, error)

NewTargetsFrom reads targets out of a line separated source skipping empty lines It sets the passed body and http.Header on all targets.

func (Targets) Shuffle

func (t Targets) Shuffle(seed int64)

Shuffle randomly alters the order of Targets with the provided seed

Jump to

Keyboard shortcuts

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