framework

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoadGenerator

func NewLoadGenerator(config *LgConfig, client HttpClient) (l *loadGenerator, err error)

NewLoadGenerator creates a new Load Generator based on the configuration and the client It will generate the Request based on LgConfig.RequestConfig and then call HttpClient.Init once call HttpClient.CreateUser with LgConfig.Connections times finally return the load generator instance TODO: add default values for each configuration here

Types

type HttpClient

type HttpClient interface {
	// The name for the HttpClient
	Name() string
	// Init will be called once, with the config it should use and the request it should use
	// It's expected to store essential field in the implementation for the future user creation
	Init(config *LgConfig, request *Request) (err error)
	// CreateUser will be called LgConfig.Connections times
	// Each User object will be used in a separate goroutine, the HttpClient should initialize goroutine specific
	// variables to the User
	CreateUser() (user User, err error)
}

HttpClient should store essential parameters, initialize globally shared read only states if needed, and create Users with dedicated state for separate goroutines

type LgConfig

type LgConfig struct {
	// RequestConfig is the configuration of the request a load generation test
	RequestConfig RequestConfig
	// The duration of the entire load generation test
	Duration time.Duration
	// The concurrency level (number of goroutines to be used)
	Connections int
	// The timeout value. Once a connection timeout occurs, that goroutine will be terminated
	Timeout time.Duration
	// the receive buffer size, should be large enough for status line and headers if `raw` is used
	RecvBufSize int
	// the verbose level for debugging
	Verbose bool
}

LgConfig is the configuration for a load generation test

type Request

type Request struct {
	HttpRequest *http.Request
	RawBytes    []byte
}

Request contains a net.http.Request as well the raw bytes

type RequestConfig

type RequestConfig struct {
	// The HTTP method to be used
	Method string
	// The URL to be used, e.g http://xyz.com/abc?de=fg&hi=jklmn
	URL string
	// The headers to be used
	Headers map[string]string
	// The body to be used. nil if no body is required
	Body []byte
}

LgConfig is the configuration for a load generation test

type Response

type Response struct {
	// StatusCode is the Http Status code
	// Size is the total size of the response
	StatusCode int
	Size       int
}

type Stats

type Stats struct {
	// RequestsSent is the total number of requests sent
	// ResponsesRecv is the total number of responses received
	RequestsSent  int64
	ResponsesRecv int64
	// BytesSent is the total number of bytes sent
	// BytesRecv is the total number of bytes received
	BytesSent int64
	BytesRecv int64

	// MinLatency is the min latency, in microseconds (us, 1/1000ms)
	// MaxLatency is the max latency, in microseconds (us, 1/1000ms)
	Latencies  []int64
	MinLatency int64
	MaxLatency int64

	StatusErrors     int64 // error responses status  > 399
	TimeoutErrors    int64 // timeouts
	ConnectionErrors int64 // connections
	// contains filtered or unexported fields
}

func (*Stats) LatencyMean

func (s *Stats) LatencyMean() float64

func (*Stats) LatencyPercentageWithinStdev

func (s *Stats) LatencyPercentageWithinStdev(n int) float64

func (*Stats) LatencyPercentile

func (s *Stats) LatencyPercentile(percent float64) int64

func (*Stats) LatencyStdev

func (s *Stats) LatencyStdev() float64

type User

type User interface {
	// DoStaticRequest is used for a request that will not change (immutable)
	// the framework will ask the User to perform the request and the result should be updated
	// in the Response object directly
	// The User should have a reference to the request, instead of creating a new one every time.
	// That's why this interface method don't pass the request object in
	DoStaticRequest(response *Response) (err error)
}

In each goroutine, a dedicated User will call DoStaticRequest continuously once the previous one finished successfully. Since the request is unchanged, HttpClient has the responsibility to put the unchanged request as a global read only state so that each User can reference it without creating a new one every time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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