Documentation ¶
Index ¶
- Constants
- Variables
- func GetCurrentCPUUsage() float64
- func MD5(slice ...string) string
- func Now() int64
- func RecordFailure(requestType, name string, responseTime int64, exception string)
- func RecordSuccess(requestType, name string, responseTime int64, responseLength int64)
- func Run(config *UserConfig)
- func StartCPUProfile(file string, duration time.Duration) (err error)
- func StartMemoryProfile(file string, duration time.Duration) (err error)
- type Boomer
- func (b *Boomer) AddOutput(o Output)
- func (b *Boomer) EnableCPUProfile(cpuProfileFile string, duration time.Duration)
- func (b *Boomer) EnableMemoryProfile(memoryProfileFile string, duration time.Duration)
- func (b *Boomer) Quit()
- func (b *Boomer) RecordFailure(requestType, name string, responseTime int64, exception string)
- func (b *Boomer) RecordSuccess(requestType, name string, responseTime int64, responseLength int64)
- func (b *Boomer) Run(userConfig *UserConfig)
- func (b *Boomer) SendCustomMessage(messageType string, data interface{})
- func (b *Boomer) SetMode(mode Mode)
- func (b *Boomer) SetRateLimiter(rateLimiter RateLimiter)
- func (b *Boomer) WithLogger(logger *log.Logger) *Boomer
- type ConsoleOutput
- type CustomMessage
- type MockGomqDealer
- func (m *MockGomqDealer) AddConnection(*gomq.Connection)
- func (m *MockGomqDealer) Close()
- func (m *MockGomqDealer) Connect(add string) (err error)
- func (m *MockGomqDealer) Recv() ([]byte, error)
- func (m *MockGomqDealer) RecvChannel() chan *zmtp.Message
- func (m *MockGomqDealer) RecvMultipart() ([][]byte, error)
- func (m *MockGomqDealer) RemoveConnection(string)
- func (m *MockGomqDealer) RetryInterval() time.Duration
- func (m *MockGomqDealer) SecurityMechanism() zmtp.SecurityMechanism
- func (m *MockGomqDealer) Send(payload []byte) (err error)
- func (m *MockGomqDealer) SendChannel() chan []byte
- func (m *MockGomqDealer) SendMultipart(payload [][]byte) (err error)
- func (m *MockGomqDealer) SetConnectError(err error)
- func (m *MockGomqDealer) SocketIdentity() zmtp.SocketIdentity
- func (m *MockGomqDealer) SocketType() zmtp.SocketType
- type Mode
- type Output
- type PrometheusPusherOutput
- type RampUpRateLimiter
- type RateLimiter
- type StableRateLimiter
- type Task
- type User
- type UserConfig
- type UserStartFunc
- type UserStopFunc
- type WaitTimeFunc
Constants ¶
const ( EVENT_CONNECTED = "boomer:connected" EVENT_SPAWN = "boomer:spawn" EVENT_STOP = "boomer:stop" EVENT_QUIT = "boomer:quit" )
Variables ¶
var ErrParsingRampUpRate = errors.New("ratelimiter: invalid format of rampUpRate, try \"1\" or \"1/1s\"")
ErrParsingRampUpRate is the error returned if the format of rampUpRate is invalid.
var Events = EventBus.New()
Events is the global event bus instance.
Functions ¶
func GetCurrentCPUUsage ¶
func GetCurrentCPUUsage() float64
GetCurrentCPUUsage get current CPU usage
func RecordFailure ¶
RecordFailure reports a failure. It's a convenience function to use the defaultBoomer.
func RecordSuccess ¶
RecordSuccess reports a success. It's a convenience function to use the defaultBoomer.
func Run ¶
func Run(config *UserConfig)
Run accepts a slice of Task and connects to a locust master. It's a convenience function to use the defaultBoomer.
func StartCPUProfile ¶
StartCPUProfile starts cpu profiling and save the results in file.
Types ¶
type Boomer ¶
type Boomer struct {
// contains filtered or unexported fields
}
A Boomer is used to run tasks. This type is exposed, so users can create and control a Boomer instance programmatically. A non-nil logger is supposed to be set.
func NewStandaloneBoomer ¶
NewStandaloneBoomer returns a new Boomer, which can run without master.
func (*Boomer) EnableCPUProfile ¶
EnableCPUProfile will start cpu profiling after run.
func (*Boomer) EnableMemoryProfile ¶
EnableMemoryProfile will start memory profiling after run.
func (*Boomer) RecordFailure ¶
RecordFailure reports a failure.
func (*Boomer) RecordSuccess ¶
RecordSuccess reports a success.
func (*Boomer) Run ¶
func (b *Boomer) Run(userConfig *UserConfig)
Run accepts a slice of Task and connects to the locust master.
func (*Boomer) SendCustomMessage ¶
func (*Boomer) SetRateLimiter ¶
func (b *Boomer) SetRateLimiter(rateLimiter RateLimiter)
SetRateLimiter allows user to use their own rate limiter. It must be called before the test is started.
type ConsoleOutput ¶
type ConsoleOutput struct {
// contains filtered or unexported fields
}
ConsoleOutput is the default output for standalone mode.
func NewConsoleOutput ¶
func NewConsoleOutput() *ConsoleOutput
NewConsoleOutput returns a ConsoleOutput.
func (*ConsoleOutput) OnEvent ¶
func (o *ConsoleOutput) OnEvent(data map[string]interface{})
OnEvent will print to the console.
func (*ConsoleOutput) OnStart ¶
func (o *ConsoleOutput) OnStart()
OnStart of ConsoleOutput has nothing to do.
func (*ConsoleOutput) OnStop ¶
func (o *ConsoleOutput) OnStop()
OnStop of ConsoleOutput has nothing to do.
func (*ConsoleOutput) WithLogger ¶
func (o *ConsoleOutput) WithLogger(logger *log.Logger) *ConsoleOutput
WithLogger allows user to use their own logger. If the logger is nil, it will not take effect.
type CustomMessage ¶
type MockGomqDealer ¶
type MockGomqDealer struct {
// contains filtered or unexported fields
}
var MockGomqDealerInstance *MockGomqDealer = &MockGomqDealer{ sendChannel: make(chan []byte, 10), receiveChannel: make(chan *zmtp.Message, 10), }
func (*MockGomqDealer) AddConnection ¶
func (m *MockGomqDealer) AddConnection(*gomq.Connection)
func (*MockGomqDealer) Close ¶
func (m *MockGomqDealer) Close()
func (*MockGomqDealer) Connect ¶
func (m *MockGomqDealer) Connect(add string) (err error)
func (*MockGomqDealer) Recv ¶
func (m *MockGomqDealer) Recv() ([]byte, error)
func (*MockGomqDealer) RecvChannel ¶
func (m *MockGomqDealer) RecvChannel() chan *zmtp.Message
func (*MockGomqDealer) RecvMultipart ¶
func (m *MockGomqDealer) RecvMultipart() ([][]byte, error)
func (*MockGomqDealer) RemoveConnection ¶
func (m *MockGomqDealer) RemoveConnection(string)
func (*MockGomqDealer) RetryInterval ¶
func (m *MockGomqDealer) RetryInterval() time.Duration
func (*MockGomqDealer) SecurityMechanism ¶
func (m *MockGomqDealer) SecurityMechanism() zmtp.SecurityMechanism
func (*MockGomqDealer) Send ¶
func (m *MockGomqDealer) Send(payload []byte) (err error)
func (*MockGomqDealer) SendChannel ¶
func (m *MockGomqDealer) SendChannel() chan []byte
func (*MockGomqDealer) SendMultipart ¶
func (m *MockGomqDealer) SendMultipart(payload [][]byte) (err error)
func (*MockGomqDealer) SetConnectError ¶
func (m *MockGomqDealer) SetConnectError(err error)
func (*MockGomqDealer) SocketIdentity ¶
func (m *MockGomqDealer) SocketIdentity() zmtp.SocketIdentity
func (*MockGomqDealer) SocketType ¶
func (m *MockGomqDealer) SocketType() zmtp.SocketType
type Mode ¶
type Mode int
Mode is the running mode of boomer, both standalone and distributed are supported.
type Output ¶
type Output interface { // OnStart will be call before the test starts. OnStart() // By default, each output receive stats data from runner every three seconds. // OnEvent is responsible for dealing with the data. OnEvent(data map[string]interface{}) // OnStop will be called before the test ends. OnStop() }
Output is primarily responsible for printing test results to different destinations such as consoles, files. You can write you own output and add to boomer. When running in standalone mode, the default output is ConsoleOutput, you can add more. When running in distribute mode, test results will be reported to master with or without an output. All the OnXXX function will be call in a separated goroutine, just in case some output will block. But it will wait for all outputs return to avoid data lost.
type PrometheusPusherOutput ¶
type PrometheusPusherOutput struct {
// contains filtered or unexported fields
}
PrometheusPusherOutput pushes boomer stats to Prometheus Pushgateway.
func NewPrometheusPusherOutput ¶
func NewPrometheusPusherOutput(gatewayURL, jobName string) *PrometheusPusherOutput
NewPrometheusPusherOutput returns a PrometheusPusherOutput.
func (*PrometheusPusherOutput) OnEvent ¶
func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{})
OnEvent will push metric to Prometheus Pushgataway
func (*PrometheusPusherOutput) OnStart ¶
func (o *PrometheusPusherOutput) OnStart()
OnStart will register all prometheus metric collectors
func (*PrometheusPusherOutput) OnStop ¶
func (o *PrometheusPusherOutput) OnStop()
OnStop of PrometheusPusherOutput has nothing to do.
func (*PrometheusPusherOutput) WithLogger ¶
func (o *PrometheusPusherOutput) WithLogger(logger *log.Logger) *PrometheusPusherOutput
WithLogger allows user to use their own logger. If the logger is nil, it will not take effect.
type RampUpRateLimiter ¶
type RampUpRateLimiter struct {
// contains filtered or unexported fields
}
A RampUpRateLimiter uses the token bucket algorithm. the threshold is updated according to the warm up rate. the bucket is refilled according to the refill period, no burst is allowed.
func NewRampUpRateLimiter ¶
func NewRampUpRateLimiter(maxThreshold int64, rampUpRate string, refillPeriod time.Duration) (rateLimiter *RampUpRateLimiter, err error)
NewRampUpRateLimiter returns a RampUpRateLimiter. Valid formats of rampUpRate are "1", "1/1s".
func (*RampUpRateLimiter) Acquire ¶
func (limiter *RampUpRateLimiter) Acquire() (blocked bool)
Acquire a token from the bucket, returns true if the bucket is exhausted.
func (*RampUpRateLimiter) Start ¶
func (limiter *RampUpRateLimiter) Start()
Start to refill the bucket periodically.
type RateLimiter ¶
type RateLimiter interface { // Start is used to enable the rate limiter. // It can be implemented as a noop if not needed. Start() // Acquire() is called before executing a task.Fn function. // If Acquire() returns true, the task.Fn function will be executed. // If Acquire() returns false, the task.Fn function won't be executed this time, but Acquire() will be called very soon. // It works like: // for { // blocked := rateLimiter.Acquire() // if !blocked { // task.Fn() // } // } // Acquire() should block the caller until execution is allowed. Acquire() bool // Stop is used to disable the rate limiter. // It can be implemented as a noop if not needed. Stop() }
RateLimiter is used to put limits on task executions.
type StableRateLimiter ¶
type StableRateLimiter struct {
// contains filtered or unexported fields
}
A StableRateLimiter uses the token bucket algorithm. the bucket is refilled according to the refill period, no burst is allowed.
func NewStableRateLimiter ¶
func NewStableRateLimiter(threshold int64, refillPeriod time.Duration) (rateLimiter *StableRateLimiter)
NewStableRateLimiter returns a StableRateLimiter.
func (*StableRateLimiter) Acquire ¶
func (limiter *StableRateLimiter) Acquire() (blocked bool)
Acquire a token from the bucket, returns true if the bucket is exhausted.
func (*StableRateLimiter) Start ¶
func (limiter *StableRateLimiter) Start()
Start to refill the bucket periodically.
type Task ¶
type Task struct { // The weight is used to distribute goroutines over multiple tasks. Weight int // Fn is called by the goroutines allocated to this task, in a loop. Fn func(user *User) Name string }
Task is like the "Locust object" in locust, the python version. When boomer receives a start message from master, it will spawn several goroutines to run Task.Fn. But users can keep some information in the python version, they can't do the same things in boomer. Because Task.Fn is a pure function.
func GetNextTask ¶
type User ¶
type User struct {
// contains filtered or unexported fields
}
func NewUser ¶ added in v1.8.0
func NewUser(config *UserConfig) *User
type UserConfig ¶ added in v1.8.0
type UserConfig struct { Tasks []*Task StartFunc UserStartFunc StopFunc UserStopFunc WaitTime WaitTimeFunc }
type UserStartFunc ¶ added in v1.8.0
type UserStopFunc ¶ added in v1.8.0
type UserStopFunc func(*User)