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(tasks ...*Task)
- func Sort(tasks []*Task)
- 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(tasks ...*Task)
- func (b *Boomer) SendCustomMessage(messageType string, data interface{})
- func (b *Boomer) SetMode(mode Mode)
- func (b *Boomer) SetRateLimiter(rateLimiter RateLimiter)
- type By
- type ConsoleOutput
- type Context
- func (m Context) Count() int
- func (m Context) Get(key string) (interface{}, bool)
- func (m Context) GetInt(key string) (value int, ok bool)
- func (m Context) GetInt16(key string) (value int16, ok bool)
- func (m Context) GetInt32(key string) (value int32, ok bool)
- func (m Context) GetInt64(key string) (value int64, ok bool)
- func (m Context) GetInt8(key string) (value int8, ok bool)
- func (m Context) GetShard(key string) *ContextShared
- func (m Context) GetString(key string) (value string, ok bool)
- func (m Context) GetUint(key string) (value uint, ok bool)
- func (m Context) GetUint16(key string) (value uint16, ok bool)
- func (m Context) GetUint32(key string) (value uint32, ok bool)
- func (m Context) GetUint64(key string) (value uint64, ok bool)
- func (m Context) GetUint8(key string) (value uint8, ok bool)
- func (m Context) Has(key string) bool
- func (m Context) IsEmpty() bool
- func (m Context) Items() map[string]interface{}
- func (m Context) Iter() <-chan Tupledeprecated
- func (m Context) IterBuffered() <-chan Tuple
- func (m Context) IterCb(fn IterCb)
- func (m Context) Keys() []string
- func (m Context) MSet(data map[string]interface{})
- func (m Context) MarshalJSON() ([]byte, error)
- func (m Context) Pop(key string) (v interface{}, exists bool)
- func (m Context) PopInt(key string) (value int, ok bool)
- func (m Context) PopInt16(key string) (value int16, ok bool)
- func (m Context) PopInt32(key string) (value int32, ok bool)
- func (m Context) PopInt64(key string) (value int64, ok bool)
- func (m Context) PopInt8(key string) (value int8, ok bool)
- func (m Context) PopString(key string) (value string, ok bool)
- func (m Context) PopUint(key string) (value uint, ok bool)
- func (m Context) PopUint16(key string) (value uint16, ok bool)
- func (m Context) PopUint32(key string) (value uint32, ok bool)
- func (m Context) PopUint64(key string) (value uint64, ok bool)
- func (m Context) PopUint8(key string) (value uint8, ok bool)
- func (m Context) Remove(key string)
- func (m Context) RemoveCb(key string, cb RemoveCb) bool
- func (m Context) Set(key string, value interface{})
- func (m Context) SetIfAbsent(key string, value interface{}) bool
- func (m Context) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})
- type ContextShared
- type CustomMessage
- type IterCb
- type Mode
- type Output
- type PrometheusPusherOutput
- type RampUpRateLimiter
- type RateLimiter
- type RemoveCb
- type SmoothRoundRobinTaskSet
- type StableRateLimiter
- type Task
- type TaskSet
- type Tuple
- type UpsertCb
- type WeighingTaskSetdeprecated
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(tasks ...*Task)
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.
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) 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 { }
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.
type Context ¶
type Context []*ContextShared
A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (_shardCount) map shards.
func NewContext ¶
func NewContext() Context
func (Context) GetShard ¶
func (m Context) GetShard(key string) *ContextShared
GetShard returns shard under given key
func (Context) IterBuffered ¶
IterBuffered returns a buffered iterator which could be used in a for range loop.
func (Context) MarshalJSON ¶
Reviles Context "private" variables to json marshal.
func (Context) RemoveCb ¶
RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)
func (Context) SetIfAbsent ¶
Sets the given value under the specified key if no value was associated with it.
type ContextShared ¶
type ContextShared struct { // contains filtered or unexported fields }
A "thread" safe string to anything map.
type CustomMessage ¶
type IterCb ¶
type IterCb func(key string, v interface{})
Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards
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.
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 RemoveCb ¶
RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map
type SmoothRoundRobinTaskSet ¶
type SmoothRoundRobinTaskSet struct {
// contains filtered or unexported fields
}
Smooth weighted round-robin balancing algorithm as seen in Nginx. See aslo: https://github.com/linnik/roundrobin/blob/master/roundrobin/smooth_rr.py
func NewSmoothRoundRobinTaskSet ¶
func NewSmoothRoundRobinTaskSet() *SmoothRoundRobinTaskSet
NewSmoothRoundRobinTaskSet returns a new SmoothRoundRobinTaskSet.
func (*SmoothRoundRobinTaskSet) AddTask ¶
func (ts *SmoothRoundRobinTaskSet) AddTask(task *Task)
AddTask add a Task to the Smooth RoundRobin TaskSet. If the task's weight is <= 0, it will be ignored.
func (*SmoothRoundRobinTaskSet) GetTask ¶
func (ts *SmoothRoundRobinTaskSet) GetTask() (task *Task)
func (*SmoothRoundRobinTaskSet) GetWeight ¶
func (ts *SmoothRoundRobinTaskSet) GetWeight() (weight int)
GetWeight returns the weight of the task set.
func (*SmoothRoundRobinTaskSet) Run ¶
func (ts *SmoothRoundRobinTaskSet) Run(ctx Context)
Run will pick up a task in the task set smoothly and run. It can is used as a Task.Fn.
func (*SmoothRoundRobinTaskSet) SetWeight ¶
func (ts *SmoothRoundRobinTaskSet) SetWeight(weight int)
SetWeight sets the weight of the task set.
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 Order is used to keep the tasks order. Order int // The weight is used to distribute goroutines over multiple tasks. Weight int // The Name is used to mark the task name. Name string // Fn is called by the goroutines allocated to this task, in a loop. Fn func(Context) }
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.
type TaskSet ¶
type TaskSet interface { // Add a Task to the TaskSet. AddTask(task *Task) // Set the weight of the TaskSet. SetWeight(weight int) // Get the weight of the TaskSet. GetWeight() (weight int) // Run will pick up a Task from the TaskSet and run. Run() }
TaskSet is an experimental feature, the API is not stabilized. It needs to be more considered and tested.
type Tuple ¶
type Tuple struct { Key string Val interface{} }
Used by the Iter & IterBuffered functions to wrap two variables together over a channel,
type UpsertCb ¶
type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}
Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant
type WeighingTaskSet
deprecated
type WeighingTaskSet struct {
// contains filtered or unexported fields
}
Deprecated: Boomer use task's weight to calculate the probability to be called now.
func NewWeighingTaskSet ¶
func NewWeighingTaskSet() *WeighingTaskSet
NewWeighingTaskSet returns a new WeighingTaskSet.
func (*WeighingTaskSet) AddTask ¶
func (ts *WeighingTaskSet) AddTask(task *Task)
AddTask add a Task to the Weighing TaskSet. If the task's weight is <= 0, it will be ignored.
func (*WeighingTaskSet) GetTask ¶
func (ts *WeighingTaskSet) GetTask(roll int) (task *Task)
GetTask returns a task in the task set.
func (*WeighingTaskSet) GetWeight ¶
func (ts *WeighingTaskSet) GetWeight() (weight int)
GetWeight returns the weight of the task set.
func (*WeighingTaskSet) Run ¶
func (ts *WeighingTaskSet) Run()
Run will pick up a task in the task set randomly and run. It can is used as a Task.Fn.
func (*WeighingTaskSet) SetWeight ¶
func (ts *WeighingTaskSet) SetWeight(weight int)
SetWeight sets the weight of the task set.