boomer

package module
v0.0.0-...-387a907 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 28 Imported by: 0

README

根据官网 https://github.com/myzhan/boomer 定制化的boomer

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var Events = EventBus.New()

Events is the global event bus instance.

View Source
var SpawnWithInitFunc = false

Functions

func GetCurrentCPUUsage

func GetCurrentCPUUsage() float64

GetCurrentCPUUsage get current CPU usage

func MD5

func MD5(slice ...string) string

MD5 returns the md5 hash of strings.

func Now

func Now() int64

Now returns the current timestamp in milliseconds.

func RecordFailure

func RecordFailure(requestType, name string, responseTime int64, exception string)

RecordFailure reports a failure. It's a convenience function to use the defaultBoomer.

func RecordSuccess

func RecordSuccess(requestType, name string, responseTime int64, responseLength int64)

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

func StartCPUProfile(file string, duration time.Duration) (err error)

StartCPUProfile starts cpu profiling and save the results in file.

func StartMemoryProfile

func StartMemoryProfile(file string, duration time.Duration) (err error)

StartMemoryProfile starts memory 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 NewBoomer

func NewBoomer(masterHost string, masterPort int) *Boomer

NewBoomer returns a new Boomer.

func NewStandaloneBoomer

func NewStandaloneBoomer(spawnCount int, spawnRate float64) *Boomer

NewStandaloneBoomer returns a new Boomer, which can run without master.

func (*Boomer) AddOutput

func (b *Boomer) AddOutput(o Output)

AddOutput accepts outputs which implements the boomer.Output interface.

func (*Boomer) EnableCPUProfile

func (b *Boomer) EnableCPUProfile(cpuProfile string, duration time.Duration)

EnableCPUProfile will start cpu profiling after run.

func (*Boomer) EnableMemoryProfile

func (b *Boomer) EnableMemoryProfile(memoryProfile string, duration time.Duration)

EnableMemoryProfile will start memory profiling after run.

func (*Boomer) Quit

func (b *Boomer) Quit()

Quit will send a quit message to the master.

func (*Boomer) RecordFailure

func (b *Boomer) RecordFailure(requestType, name string, responseTime int64, exception string)

RecordFailure reports a failure.

func (*Boomer) RecordSuccess

func (b *Boomer) RecordSuccess(requestType, name string, responseTime int64, responseLength int64)

RecordSuccess reports a success.

func (*Boomer) Run

func (b *Boomer) Run(tasks ...*Task)

Run accepts a slice of Task and connects to the locust master.

func (*Boomer) SetMode

func (b *Boomer) SetMode(mode Mode)

SetMode only accepts boomer.DistributedMode and boomer.StandaloneMode.

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 Mode

type Mode int

Mode is the running mode of boomer, both standalone and distributed are supported.

const (
	// DistributedMode requires connecting to a master.
	DistributedMode Mode = iota
	// StandaloneMode will run without a master.
	StandaloneMode
)

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 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.

func (*RampUpRateLimiter) Stop

func (limiter *RampUpRateLimiter) Stop()

Stop the rate limiter.

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.

func (*StableRateLimiter) Stop

func (limiter *StableRateLimiter) Stop()

Stop the rate limiter.

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()
	FnArgs  func(args interface{})
	SpawnFn func() (args interface{})
	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.

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 WeighingTaskSet

type WeighingTaskSet struct {
	// contains filtered or unexported fields
}

WeighingTaskSet is a implementation of the TaskSet interface. When a Task is added to WeighingTaskSet, it's weight is used to calculate the probability to be called.

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) RunWithArgs

func (ts *WeighingTaskSet) RunWithArgs(args interface{})

func (*WeighingTaskSet) SetWeight

func (ts *WeighingTaskSet) SetWeight(weight int)

SetWeight sets the weight of the task set.

Jump to

Keyboard shortcuts

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