periodic

package
v1.36.0-pre4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 12 Imported by: 26

Documentation

Overview

Package periodic for fortio (from greek for load) is a set of utilities to run a given task at a target rate (qps) and gather statistics - for instance http requests.

The main executable using the library is fortio but there is also ../histogram to use the stats from the command line and ../echosrv as a very light http server that can be used to test proxies etc like the Istio components.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRunnerOptions = RunnerOptions{
	QPS:         8,
	Duration:    5 * time.Second,
	NumThreads:  4,
	Percentiles: []float64{90.0},
	Resolution:  0.001,
}

DefaultRunnerOptions are the default values for options (do not mutate!). This is only useful for initializing flag default values. You do not need to use this directly, you can pass a newly created RunnerOptions and 0 valued fields will be reset to these defaults.

Functions

This section is empty.

Types

type Aborter added in v0.6.8

type Aborter struct {
	sync.Mutex
	StopChan  chan struct{}
	StartChan chan bool // Used to signal actual start of the run. Also (re)used in rapi/ to signal completion of the Run().
	// contains filtered or unexported fields
}

Aborter is the object controlling Abort() of the runs.

func NewAborter added in v0.6.8

func NewAborter() *Aborter

NewAborter makes a new Aborter and initialize its StopChan. The pointer should be shared. The structure is NoCopy.

func (*Aborter) Abort added in v0.6.8

func (a *Aborter) Abort(wait bool)

Abort signals all the go routine of this run to stop. Implemented by closing the shared channel. The lock is to make sure we close it exactly once to avoid go panic. If wait is true, waits for the run to be started before closing.

func (*Aborter) Reset added in v1.35.0

func (a *Aborter) Reset()

Reset returns the aborter to original state, for (unit test) reuse. Note that it doesn't recreate the closed stop chan.

func (*Aborter) String added in v1.35.0

func (a *Aborter) String() string

type AccessLogger added in v1.21.0

type AccessLogger interface {
	// Report logs a single request to a file.
	Report(thread int, time int64, latency float64, status bool, details string)
	Info() string
}

AccessLogger defines an interface to report a single request.

func NewFileAccessLogger added in v1.21.0

func NewFileAccessLogger(filePath, format string) (AccessLogger, error)

NewFileAccessLogger creates an AccessLogger that writes to the provided file in the provided format.

func NewFileAccessLoggerByType added in v1.21.0

func NewFileAccessLoggerByType(filePath string, accessType AccessLoggerType) (AccessLogger, error)

NewFileAccessLoggerByType creates an AccessLogger that writes to the file in the AccessLoggerType enum format.

type AccessLoggerType added in v1.21.0

type AccessLoggerType int

AccessLoggerType is the possible formats of the access logger (ACCESS_JSON or ACCESS_INFLUX).

const (
	// AccessJSON for json format of access log: {"latency":%f,"timestamp":%d,"thread":%d}.
	AccessJSON AccessLoggerType = iota
	// AccessInflux of influx format of access log.
	// https://docs.influxdata.com/influxdb/v2.2/reference/syntax/line-protocol/
	AccessInflux
)

func (AccessLoggerType) String added in v1.21.0

func (t AccessLoggerType) String() string

type HasRunnerResult

type HasRunnerResult interface {
	Result() *RunnerResults
}

HasRunnerResult is the interface implictly implemented by HTTPRunnerResults and GrpcRunnerResults so the common results can ge extracted irrespective of the type.

type PeriodicRunner

type PeriodicRunner interface {
	// Starts the run. Returns actual QPS and Histogram of function durations.
	Run() RunnerResults
	// Returns the options normalized by constructor - do not mutate
	// (where is const when you need it...)
	Options() *RunnerOptions
}

PeriodicRunner let's you exercise the Function at the given QPS and collect statistics and histogram about the run.

func NewPeriodicRunner

func NewPeriodicRunner(params *RunnerOptions) PeriodicRunner

NewPeriodicRunner constructs a runner from input parameters/options. The options will be moved and normalized to the returned object, do not use the original options after this call, call Options() instead. Abort() must be called if Run() is not called. You can also keep a pointer to the original Aborter and use it, if needed.

type Runnable added in v0.4.2

type Runnable interface {
	// Run returns a boolean, true for normal/success, false otherwise.
	// with details being an optional string that can be put in the access logs.
	// Statistics are split into two sets.
	Run(tid int) (status bool, details string)
}

Runnable are the function to run periodically.

type RunnerOptions

type RunnerOptions struct {
	// Type of run (to be copied into results)
	RunType string
	// Array of objects to run in each thread (use MakeRunners() to clone the same one)
	Runners []Runnable `json:"-"`
	// At which (target) rate to run the Runners across NumThreads.
	QPS float64
	// How long to run the test for. Unless Exactly is specified.
	Duration time.Duration
	// Note that this actually maps to gorountines and not actual threads
	// but threads seems like a more familiar name to use for non go users
	// and in a benchmarking context
	NumThreads  int
	Percentiles []float64
	Resolution  float64
	// Where to write the textual version of the results, defaults to stdout
	Out io.Writer `json:"-"`
	// Extra data to be copied back to the results (to be saved/JSON serialized)
	Labels string
	// Aborter to interrupt a run. Will be created if not set/left nil. Or you
	// can pass your own. It is very important this is a pointer and not a field
	// as RunnerOptions themselves get copied while the channel and lock must
	// stay unique (per run).
	Stop *Aborter `json:"-"`
	// Mode where an exact number of iterations is requested. Default (0) is
	// to not use that mode. If specified Duration is not used.
	Exactly int64
	// When multiple clients are used to generate requests, they tend to send
	// requests very close to one another, causing a thundering herd problem
	// Enabling jitter (+/-10%) allows these requests to be de-synchronized
	// When enabled, it is only effective in the '-qps' mode.
	Jitter bool
	// When multiple clients are used to generate requests, they tend to send
	// requests very close to one another, causing a thundering herd problem
	// Enabling uniform causes the requests between connections to be uniformly staggered.
	// When enabled, it is only effective in the '-qps' mode.
	Uniform bool
	// Optional run id; used by the server to identify runs.
	RunID int64
	// Optional Offset Duration; to offset the histogram function duration
	Offset time.Duration
	// Optional AccessLogger to log every request made. See AddAccessLogger.
	AccessLogger AccessLogger `json:"-"`
	// No catch-up: if true we will do exactly the requested QPS and not try to catch up if the target is temporarily slow.
	NoCatchUp bool
	// Unique 96 character ID used as reference to saved json file. Created during Normalize().
	ID string
	// contains filtered or unexported fields
}

RunnerOptions are the parameters to the PeriodicRunner.

func (*RunnerOptions) Abort added in v0.5.2

func (r *RunnerOptions) Abort()

Abort safely aborts the run by closing the channel and resetting that channel to nil under lock so it can be called multiple times and not create panic for already closed channel.

func (*RunnerOptions) AddAccessLogger added in v1.21.0

func (r *RunnerOptions) AddAccessLogger(filePath, format string) error

AddAccessLogger adds an AccessLogger that writes to the provided file in the provided format.

func (*RunnerOptions) GenID added in v1.35.0

func (r *RunnerOptions) GenID()

GenID creates and set the ID for the result: 96 bytes YYYY-MM-DD-HHmmSS_{RunID}_{alpha_labels} where RunID is the RunID if not 0. where alpha_labels is the filtered labels with only alphanumeric characters and all non alpha num replaced by _; truncated to 96 bytes.

func (*RunnerOptions) MakeRunners added in v0.4.2

func (r *RunnerOptions) MakeRunners(rr Runnable)

MakeRunners creates an array of NumThreads identical Runnable instances (for the (rare/test) cases where there is no unique state needed).

func (*RunnerOptions) Normalize added in v0.5.2

func (r *RunnerOptions) Normalize()

Normalize initializes and normalizes the runner options. In particular it sets up the channel that can be used to interrupt the run later. Once Normalize is called, if Run() is skipped, Abort() must be called to cleanup the watchers.

func (*RunnerOptions) ReleaseRunners added in v0.8.0

func (r *RunnerOptions) ReleaseRunners()

ReleaseRunners clear the runners state.

type RunnerResults

type RunnerResults struct {
	RunType           string
	Labels            string
	StartTime         time.Time
	RequestedQPS      string
	RequestedDuration string // String version of the requested duration or exact count
	ActualQPS         float64
	ActualDuration    time.Duration
	NumThreads        int
	Version           string
	// DurationHistogram all the Run. If you want to exclude the error cases; subtract ErrorsDurationHistogram to each bucket.
	DurationHistogram *stats.HistogramData
	// ErrorsDurationHistogram is the durations of the error (Run returning false) cases.
	ErrorsDurationHistogram *stats.HistogramData
	Exactly                 int64 // Echo back the requested count
	Jitter                  bool
	Uniform                 bool
	NoCatchUp               bool
	RunID                   int64 // Echo back the optional run id
	AccessLoggerInfo        string
	// Same as RunnerOptions ID:  Unique 96 character ID used as reference to saved json file. Created during Normalize().
	ID string
}

RunnerResults encapsulates the actual QPS observed and duration histogram.

func (*RunnerResults) Result

func (r *RunnerResults) Result() *RunnerResults

Result returns the common RunnerResults.

Jump to

Keyboard shortcuts

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