boomer

package
v0.0.0-...-b652da8 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

README

boomer

This module is initially forked from myzhan/boomer@v1.6.0 and made a lot of changes.

Documentation

Index

Constants

View Source
const (
	StateInit     = iota + 1 // initializing
	StateSpawning            // spawning
	StateRunning             // running
	StateStopping            // stopping
	StateStopped             // stopped
	StateQuitting            // quitting
	StateMissing             // missing
)

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.

Functions

func GetCurrentCPUPercent

func GetCurrentCPUPercent() float64

GetCurrentCPUPercent get the percentage of current cpu used

func GetCurrentMemoryPercent

func GetCurrentMemoryPercent() float64

GetCurrentMemoryPercent get the percentage of current memory used

func GetCurrentPidCPUPercent

func GetCurrentPidCPUPercent() float64

GetCurrentPidCPUPercent get the percentage of current pid cpu used

func GetCurrentPidCPUUsage

func GetCurrentPidCPUUsage() float64

GetCurrentPidCPUUsage get current pid CPU usage

func GetCurrentPidMemoryUsage

func GetCurrentPidMemoryUsage() float64

GetCurrentPidMemoryUsage get current Memory usage

func ProfileToBytes

func ProfileToBytes(profile *Profile) []byte

func SetUlimit

func SetUlimit(limit uint64)

set resource limit ulimit -n 10240

Types

type Boomer

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

A Boomer is used to run tasks.

func NewMasterBoomer

func NewMasterBoomer(masterBindHost string, masterBindPort int) *Boomer

NewMasterBoomer returns a new Boomer.

func NewStandaloneBoomer

func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *Boomer

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

func NewWorkerBoomer

func NewWorkerBoomer(masterHost string, masterPort int) *Boomer

NewWorkerBoomer returns a new Boomer.

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

func (b *Boomer) EnableGracefulQuit(ctx context.Context) context.Context

EnableGracefulQuit catch SIGINT and SIGTERM signals to quit gracefully

func (*Boomer) EnableMemoryProfile

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

EnableMemoryProfile will start memory profiling after run.

func (*Boomer) GetCloseChan

func (b *Boomer) GetCloseChan() chan bool

func (*Boomer) GetDisableCompression

func (b *Boomer) GetDisableCompression() bool

func (*Boomer) GetDisableKeepAlive

func (b *Boomer) GetDisableKeepAlive() bool

func (*Boomer) GetMasterHost

func (b *Boomer) GetMasterHost() string

GetMasterHost returns master IP

func (*Boomer) GetMasterInfo

func (b *Boomer) GetMasterInfo() map[string]interface{}

GetMasterInfo gets master information

func (*Boomer) GetMode

func (b *Boomer) GetMode() string

GetMode returns boomer operating mode

func (*Boomer) GetProfile

func (b *Boomer) GetProfile() *Profile

func (*Boomer) GetRebalanceChan

func (b *Boomer) GetRebalanceChan() chan bool

func (*Boomer) GetSpawnCount

func (b *Boomer) GetSpawnCount() int

func (*Boomer) GetSpawnDoneChan

func (b *Boomer) GetSpawnDoneChan() chan struct{}

func (*Boomer) GetState

func (b *Boomer) GetState() int32

GetState gets worker state

func (*Boomer) GetTasksChan

func (b *Boomer) GetTasksChan() chan *task

GetTasksChan getsTasks chan

func (*Boomer) GetTestCaseBytes

func (b *Boomer) GetTestCaseBytes() []byte

func (*Boomer) GetTestCasesPath

func (b *Boomer) GetTestCasesPath() []string

func (*Boomer) GetWorkersInfo

func (b *Boomer) GetWorkersInfo() []WorkerNode

GetWorkersInfo gets workers information

func (*Boomer) ParseTestCasesChan

func (b *Boomer) ParseTestCasesChan() chan bool

func (*Boomer) Quit

func (b *Boomer) Quit()

Quit will send a quit message to the master.

func (*Boomer) ReBalance

func (b *Boomer) ReBalance(Args *Profile) error

ReBalance starts to rebalance load test

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

func (b *Boomer) RecordTransaction(name string, success bool, elapsedTime int64, contentSize int64)

RecordTransaction reports a transaction stat.

func (*Boomer) ResetStartTime

func (b *Boomer) ResetStartTime()

func (*Boomer) Run

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

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

func (*Boomer) RunMaster

func (b *Boomer) RunMaster()

RunMaster start to run master runner

func (*Boomer) RunWorker

func (b *Boomer) RunWorker()

RunWorker start to run worker runner

func (*Boomer) SetAutoStart

func (b *Boomer) SetAutoStart()

SetAutoStart auto start to load testing

func (*Boomer) SetDisableCompression

func (b *Boomer) SetDisableCompression(disableCompression bool)

SetDisableCompression disable compression to prevent the Transport from requesting compression with an "Accept-Encoding: gzip"

func (*Boomer) SetDisableKeepAlive

func (b *Boomer) SetDisableKeepAlive(disableKeepalive bool)

SetDisableKeepAlive disable keep-alive for tcp

func (*Boomer) SetExpectWorkers

func (b *Boomer) SetExpectWorkers(expectWorkers int, expectWorkersMaxWait int)

SetExpectWorkers sets expect workers while load testing

func (*Boomer) SetIgnoreQuit

func (b *Boomer) SetIgnoreQuit()

SetIgnoreQuit not quit while master quit

func (*Boomer) SetLoopCount

func (b *Boomer) SetLoopCount(loopCount int64)

SetLoopCount set loop count for test.

func (*Boomer) SetMode

func (b *Boomer) SetMode(mode Mode)

SetMode only accepts boomer.DistributedMasterMode、boomer.DistributedWorkerMode and boomer.StandaloneMode.

func (*Boomer) SetProfile

func (b *Boomer) SetProfile(profile *Profile)

func (*Boomer) SetRateLimiter

func (b *Boomer) SetRateLimiter(maxRPS int64, requestIncreaseRate string)

SetRateLimiter creates rate limiter with the given limit and burst.

func (*Boomer) SetRunTime

func (b *Boomer) SetRunTime(runTime int64)

SetRunTime sets run time

func (*Boomer) SetSpawnCount

func (b *Boomer) SetSpawnCount(spawnCount int64)

SetSpawnCount sets spawn count

func (*Boomer) SetSpawnRate

func (b *Boomer) SetSpawnRate(spawnRate float64)

SetSpawnRate sets spawn rate

func (*Boomer) SetTasks

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

func (*Boomer) SetTestCasesPath

func (b *Boomer) SetTestCasesPath(paths []string)

func (*Boomer) Start

func (b *Boomer) Start(Args *Profile) error

Start starts to run

func (*Boomer) Stop

func (b *Boomer) Stop() error

Stop stops to load test

func (*Boomer) TestCaseBytesChan

func (b *Boomer) TestCaseBytesChan() chan []byte

TestCaseBytesChan gets test case bytes chan

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 Controller

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

type Loop

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

type Mode

type Mode int

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

const (
	// DistributedMasterMode requires being connected by each worker.
	DistributedMasterMode Mode = iota
	// DistributedWorkerMode requires connecting to a master.
	DistributedWorkerMode
	// 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 Profile

type Profile struct {
	SpawnCount               int64         `json:"spawn-count,omitempty" yaml:"spawn-count,omitempty" mapstructure:"spawn-count,omitempty"`
	SpawnRate                float64       `json:"spawn-rate,omitempty" yaml:"spawn-rate,omitempty" mapstructure:"spawn-rate,omitempty"`
	RunTime                  int64         `json:"run-time,omitempty" yaml:"run-time,omitempty" mapstructure:"run-time,omitempty"`
	MaxRPS                   int64         `json:"max-rps,omitempty" yaml:"max-rps,omitempty" mapstructure:"max-rps,omitempty"`
	LoopCount                int64         `json:"loop-count,omitempty" yaml:"loop-count,omitempty" mapstructure:"loop-count,omitempty"`
	RequestIncreaseRate      string        `json:"request-increase-rate,omitempty" yaml:"request-increase-rate,omitempty" mapstructure:"request-increase-rate,omitempty"`
	MemoryProfile            string        `json:"memory-profile,omitempty" yaml:"memory-profile,omitempty" mapstructure:"memory-profile,omitempty"`
	MemoryProfileDuration    time.Duration `` /* 130-byte string literal not displayed */
	CPUProfile               string        `json:"cpu-profile,omitempty" yaml:"cpu-profile,omitempty" mapstructure:"cpu-profile,omitempty"`
	CPUProfileDuration       time.Duration `json:"cpu-profile-duration,omitempty" yaml:"cpu-profile-duration,omitempty" mapstructure:"cpu-profile-duration,omitempty"`
	PrometheusPushgatewayURL string        `json:"prometheus-gateway,omitempty" yaml:"prometheus-gateway,omitempty" mapstructure:"prometheus-gateway,omitempty"`
	DisableConsoleOutput     bool          `` /* 127-byte string literal not displayed */
	DisableCompression       bool          `json:"disable-compression,omitempty" yaml:"disable-compression,omitempty" mapstructure:"disable-compression,omitempty"`
	DisableKeepalive         bool          `json:"disable-keepalive,omitempty" yaml:"disable-keepalive,omitempty" mapstructure:"disable-keepalive,omitempty"`
}

func BytesToProfile

func BytesToProfile(profileBytes []byte) *Profile

func NewProfile

func NewProfile() *Profile

type PrometheusPusherOutput

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

PrometheusPusherOutput pushes boomer stats to Prometheus Pushgateway.

func NewPrometheusPusherOutput

func NewPrometheusPusherOutput(gatewayURL, jobName string, mode 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.

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()
	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 WorkerNode

type WorkerNode struct {
	ID                string  `json:"id"`
	IP                string  `json:"ip"`
	OS                string  `json:"os"`
	Arch              string  `json:"arch"`
	State             int32   `json:"state"`
	Heartbeat         int32   `json:"heartbeat"`
	UserCount         int64   `json:"user_count"`
	WorkerCPUUsage    float64 `json:"worker_cpu_usage"`
	CPUUsage          float64 `json:"cpu_usage"`
	CPUWarningEmitted bool    `json:"cpu_warning_emitted"`
	WorkerMemoryUsage float64 `json:"worker_memory_usage"`
	MemoryUsage       float64 `json:"memory_usage"`
	// contains filtered or unexported fields
}

Directories

Path Synopsis
grpc

Jump to

Keyboard shortcuts

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