Documentation ¶
Overview ¶
Package launce is Locust worker library written in Go. The aim of this library is to write load test scenarios as simply as locustfile.py and to run load testing with better performance.
Index ¶
- Constants
- Variables
- func Wrap(err error) error
- type BaseUser
- type BaseUserImpl
- func (b *BaseUserImpl) Init(u User, r Runner, rep Reporter)
- func (b *BaseUserImpl) OnStart(ctx context.Context) error
- func (b *BaseUserImpl) OnStop(ctx context.Context) error
- func (b *BaseUserImpl) Report(requestType, name string, responseTime time.Duration, contentLength int64, ...)
- func (b *BaseUserImpl) Runner() Runner
- func (b *BaseUserImpl) Wait(ctx context.Context) error
- type LoadGenerator
- func (l *LoadGenerator) OnTestStart(f func(ctx context.Context) error)
- func (l *LoadGenerator) OnTestStop(f func(ctx context.Context))
- func (l *LoadGenerator) OnTestStopping(f func(ctx context.Context))
- func (l *LoadGenerator) RegisterUser(r Runner, name string, f func() User)
- func (l *LoadGenerator) Spawn(user string, count int) error
- func (l *LoadGenerator) Start() error
- func (l *LoadGenerator) Stats() <-chan *stats.Stats
- func (l *LoadGenerator) Stop()
- func (l *LoadGenerator) StopUsers()
- func (l *LoadGenerator) Users() map[string]int64
- type Message
- type MessageHandler
- type ParsedOptions
- type Reporter
- type Runner
- type Transport
- type UnknownUserError
- type User
- type WaitTimeFunc
- type Worker
- func (w *Worker) Host() string
- func (w *Worker) Index() int64
- func (w *Worker) Join() error
- func (w *Worker) OnConnect(f func())
- func (w *Worker) OnQuit(f func())
- func (w *Worker) OnQuitting(f func())
- func (w *Worker) OnTestStart(f func(ctx context.Context) error)
- func (w *Worker) OnTestStop(f func(ctx context.Context))
- func (w *Worker) OnTestStopping(f func(ctx context.Context))
- func (w *Worker) Options(v interface{}) error
- func (w *Worker) Quit()
- func (w *Worker) RegisterMessage(typ string, handler MessageHandler)
- func (w *Worker) RegisterUser(name string, f func() User)
- func (w *Worker) ReportException(err error)
- func (w *Worker) SendMessage(typ string, data any) error
- func (w *Worker) State() WorkerState
- func (w *Worker) Stop()
- func (w *Worker) Tags() (tags, excludeTags *[]string)
- type WorkerState
- type ZmqTransport
Constants ¶
const ( // Version is the version of launce. Version = "1.0.1" // LocustVersion is the version of locust that launce is compatible with. LocustVersion = "2.24.1" )
const ( // NoneResponseTime is a special value that represents no response time. NoneResponseTime = time.Duration(-1) )
Variables ¶
var (
ErrConnection = errors.New("failed to connect to master")
)
var ( // StopUser is an error that stops the user. StopUser = errors.New("stop user") )
Functions ¶
Types ¶
type BaseUser ¶
type BaseUser interface { User WaitTime() WaitTimeFunc }
BaseUser is the interface that structs must implement to use BaseUserImpl.
type BaseUserImpl ¶
type BaseUserImpl struct {
// contains filtered or unexported fields
}
BaseUserImpl is a base implementation of User.
func (*BaseUserImpl) Init ¶
func (b *BaseUserImpl) Init(u User, r Runner, rep Reporter)
Init initializes the user.
func (*BaseUserImpl) OnStart ¶
func (b *BaseUserImpl) OnStart(ctx context.Context) error
OnStart is called when the user starts.
func (*BaseUserImpl) OnStop ¶
func (b *BaseUserImpl) OnStop(ctx context.Context) error
OnStop is called when the user stops.
type LoadGenerator ¶
type LoadGenerator struct { // RestartMode is the mode of spawning users. RestartMode spawner.RestartMode // StatsNotifyInterval is the interval to notify stats. StatsNotifyInterval time.Duration // contains filtered or unexported fields }
LoadGenerator is an instance of load test generator.
func NewLoadGenerator ¶
func NewLoadGenerator() *LoadGenerator
NewLoadGenerator returns a new LoadGenerator.
func (*LoadGenerator) OnTestStart ¶
func (l *LoadGenerator) OnTestStart(f func(ctx context.Context) error)
OnTestStart registers a function to be called when the load test starts.
func (*LoadGenerator) OnTestStop ¶
func (l *LoadGenerator) OnTestStop(f func(ctx context.Context))
OnTestStop registers a function to be called when the load test stops.
func (*LoadGenerator) OnTestStopping ¶
func (l *LoadGenerator) OnTestStopping(f func(ctx context.Context))
OnTestStopping registers a function to be called when the load test start stopping.
func (*LoadGenerator) RegisterUser ¶
func (l *LoadGenerator) RegisterUser(r Runner, name string, f func() User)
RegisterUser registers a user class.
func (*LoadGenerator) Spawn ¶
func (l *LoadGenerator) Spawn(user string, count int) error
Spawn spawns users.
func (*LoadGenerator) Stats ¶
func (l *LoadGenerator) Stats() <-chan *stats.Stats
Stats returns the stats channel.
func (*LoadGenerator) Users ¶
func (l *LoadGenerator) Users() map[string]int64
Users returns the number of running users.
type Message ¶
func (*Message) DecodePayload ¶
type MessageHandler ¶
type MessageHandler func(msg Message)
MessageHandler defines a function to handle custom messages from the master.
type ParsedOptions ¶
type ParsedOptions struct { // Common Options Locustfile string `msgpack:"locustfile"` // --locustfile Config string `msgpack:"config"` // --config Host string `msgpack:"host"` // --host NumUsers *int64 `msgpack:"num_users"` // --users SpawnRate *float64 `msgpack:"spawn_rate"` // --spawn-rate HatchRate int64 `msgpack:"hatch_rate"` // --hatch-rate RunTime *int64 `msgpack:"run_time"` // --run-time ListCommands bool `msgpack:"list_commands"` // --list ConfigUsers *[]string `msgpack:"config_users"` // --config-users // Web UI Options WebHost string `msgpack:"web_host"` // --web-host WebPort int64 `msgpack:"web_port"` // --web-port Headless bool `msgpack:"headless"` // --headless Autostart bool `msgpack:"autostart"` // --autostart Autoquit int64 `msgpack:"autoquit"` // --autoquit Headful bool `msgpack:"headful"` // --headful WebAuth *string `msgpack:"web_auth"` // --web-auth WebLogin bool `msgpack:"web_login"` // --web-login TLSCert string `msgpack:"tls_cert"` // --tls-key TLSKey string `msgpack:"tls_key"` // --tls-cert ClassPicker bool `msgpack:"class_picker"` // --class-picker LegacyUI bool `msgpack:"legacy_ui"` // --legacy-ui // Master Options Master bool `msgpack:"master"` // --master MasterBindHost string `msgpack:"master_bind_host"` // --master-bind-host MasterBindPort int64 `msgpack:"master_bind_port"` // --master-bind-port ExpectWorkers int64 `msgpack:"expect_workers"` // --expect-workers ExpectWorkersMaxWait int64 `msgpack:"expect_workers_max_wait"` // --expect-worker-max-wait EnableRebalancing bool `msgpack:"enable_rebalancing"` // --enable-rebalancing ExpectSlaves bool `msgpack:"expect_slaves"` // --expect-slaves // Worker Options Worker bool `msgpack:"worker"` // --worker Processes *int64 `msgpack:"processes"` // --processes Slave bool `msgpack:"slave"` // --slave MasterHost string `msgpack:"master_host"` // --master-host MasterPort int `msgpack:"master_port"` // --master-port // Tag Options Tags *[]string `msgpack:"tags"` // --tags ExcludeTags *[]string `msgpack:"exclude_tags"` // --exclude-tags // Stats Options CsvPrefix *string `msgpack:"csv_prefix"` // --csv StatsHistoryEnabled bool `msgpack:"stats_history_enabled"` // --csv-full-history PrintStats bool `msgpack:"print_stats"` // --print-stats OnlySummary bool `msgpack:"only_summary"` // --only-summary ResetStats bool `msgpack:"reset_stats"` // --reset-stats HtmlFile *string `msgpack:"html_file"` // --html Json bool `msgpack:"json"` // --json // Log Options SkipLogSetup bool `msgpack:"skip_log_setup"` // --skip-log-setup Loglevel string `msgpack:"loglevel"` // --loglevel Logfile *string `msgpack:"logfile"` // --logfile // Other Options ShowTaskRatio bool `msgpack:"show_task_ratio"` // --show-task-ratio ShowTaskRatioJson bool `msgpack:"show_task_ratio_json"` // --show-task-ratio-json ExitCodeOnError int64 `msgpack:"exit_code_on_error"` // --exit-code-on-error StopTimeout int64 `msgpack:"stop_timeout"` // --stop-timeout EqualWeights bool `msgpack:"equal_weights"` // --equal-weights // User Classes Options UserClasses []string `msgpack:"user_classes"` // <UserClass1 UserClass2> // contains filtered or unexported fields }
ParsedOptions is the command line options of locust.
func (*ParsedOptions) DecodeMsgpack ¶
func (p *ParsedOptions) DecodeMsgpack(dec *msgpack.Decoder) error
DecodeMsgpack decodes the msgpack data.
func (*ParsedOptions) Extract ¶
func (p *ParsedOptions) Extract(v interface{}) error
Extract extracts the parsed options to the given value.
type Reporter ¶
type Reporter interface {
Report(requestType, name string, responseTime time.Duration, contentLength int64, err error)
}
Reporter is the interface that reports the result of a request.
type Runner ¶
type Runner interface { Host() string Tags() (tags, excludeTags *[]string) Options(v interface{}) error RegisterMessage(typ string, handler MessageHandler) SendMessage(typ string, data any) error ReportException(err error) }
Runner is interface for load test runner.
type Transport ¶
type Transport interface { // Open opens the connection to the master. Open(ctx context.Context, clientID string) error // Close closes the connection to the master. Close() error // Send sends a message to the master. Send(msg []byte) error // Receive receives a message from the master. Receive() ([]byte, error) }
Transport is the interface that communicates with the master.
type UnknownUserError ¶
type UnknownUserError struct {
User string
}
UnknownUserError is an error that trying to spawn unregistered user.
func (*UnknownUserError) Error ¶
func (e *UnknownUserError) Error() string
type User ¶
type User interface { Reporter Init(u User, r Runner, rep Reporter) Runner() Runner OnStart(ctx context.Context) error OnStop(ctx context.Context) error Process(ctx context.Context) error Wait(ctx context.Context) error }
User is the interface that behaves as a locust user.
type WaitTimeFunc ¶
WaitTimeFunc represents a wait time function for users or tasks.
func Between ¶
func Between(min, max time.Duration) WaitTimeFunc
Between returns a WaitTimeFunc that returns a random wait time between min and max.
func Constant ¶
func Constant(d time.Duration) WaitTimeFunc
Constant returns a WaitTimeFunc that returns the constant wait time.
func ConstantPacing ¶
func ConstantPacing(d time.Duration) WaitTimeFunc
ConstantPacing returns a WaitTimeFunc that calculates wait time to ensure the interval between task executions is d.
func ConstantThroughput ¶
func ConstantThroughput(taskRunsPerSecond float64) WaitTimeFunc
ConstantThroughput returns a WaitTimeFunc that returns wait time that makes the number of task executions per second equal to taskRunsPerSecond.
type Worker ¶
type Worker struct { // Version is the version of the worker Version string // ClientID is the unique identifier of the worker. ClientID string // HeartbeatInterval is the interval at which the worker sends a heartbeat message to the master. HeartbeatInterval time.Duration // MasterHeartbeatTimeout is the timeout for the heartbeat from the master. MasterHeartbeatTimeout time.Duration // MetricsMonitorInterval is the interval at which the worker monitors the process metrics. MetricsMonitorInterval time.Duration // StatsReportInterval is the interval at which the worker sends statistics to the master. StatsReportInterval time.Duration // StatsAggregateInterval is the interval at which the worker aggregates statistics of users. StatsAggregateInterval time.Duration // contains filtered or unexported fields }
Worker provides the functionality of a Locust worker.
func (*Worker) OnConnect ¶
func (w *Worker) OnConnect(f func())
OnConnect registers function to be called when the worker connects to the master.
func (*Worker) OnQuit ¶
func (w *Worker) OnQuit(f func())
OnQuit registers function to be called when the worker quits.
func (*Worker) OnQuitting ¶
func (w *Worker) OnQuitting(f func())
OnQuitting registers function to be called when the worker starts quitting.
func (*Worker) OnTestStart ¶
OnTestStart registers function to be called when the test starts.
func (*Worker) OnTestStop ¶
OnTestStop registers function to be called when the test stops.
func (*Worker) OnTestStopping ¶
OnTestStopping registers function to be called when the load test start stopping.
func (*Worker) RegisterMessage ¶
func (w *Worker) RegisterMessage(typ string, handler MessageHandler)
RegisterMessage registers custom message handler.
func (*Worker) RegisterUser ¶
RegisterUser registers user.
func (*Worker) ReportException ¶
func (*Worker) SendMessage ¶
SendMessage sends message to the master.
type WorkerState ¶
type WorkerState = int64
const ( WorkerStateInit WorkerState = iota WorkerStateSpawning WorkerStateRunning WorkerStateCleanup WorkerStateStopped )
type ZmqTransport ¶
ZmqTransport is transport that uses ZeroMQ.
func NewZmqTransport ¶
func NewZmqTransport(host string, port int, opts ...zmq4.Option) *ZmqTransport
NewZmqTransport returns a new ZmqTransport.
func (*ZmqTransport) Close ¶
func (t *ZmqTransport) Close() error
Close closes the connection to the master.
func (*ZmqTransport) Open ¶
func (t *ZmqTransport) Open(ctx context.Context, clientID string) error
Open opens the connection to the master.
func (*ZmqTransport) Receive ¶
func (t *ZmqTransport) Receive() ([]byte, error)
Receive receives a message from the master.
func (*ZmqTransport) Send ¶
func (t *ZmqTransport) Send(msg []byte) error
Send sends a message to the master.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
Package spawner implements dynamic goroutine management.
|
Package spawner implements dynamic goroutine management. |
Package stats implements statistics for Locust.
|
Package stats implements statistics for Locust. |
Package taskset implements utilities for structured test scenarios.
|
Package taskset implements utilities for structured test scenarios. |