berf

package module
v0.0.0-...-4282750 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 42 Imported by: 0

README

berf

berf framework for local methods.

Features

  1. LOCAL_IP=ip1,ip2 berf ... 指定网卡 IP 运行 berf
  2. support vars substitution like berf -opt eval -n1 192.168.126.5:9200/person/doc/@ksuid -b '{"addr":"@地址","idcard":"@身份证","name":"@姓名","sex":"@性别"}'
  3. support -u rand.png,rand.jpg,rand.json random image and json uploading content.
  4. support @var in URL like berf :9335/pingoo/@ksuid -u imgs -d60s -v, 2021-12-29
  5. support httpie like args berf :10014/query q="show databases" -n1, 2021-12-23
  6. berf :5003/api/demo -n20 -pA to print all details instead of realtime statistics on terminal, 2021-12-22.
  7. Add a TPS-0 comparing series to the TPS plots, 2021-12-02.

Demo

$ berf -f demo -v -ci 1 -c10
Benchmarking demo using max 10 goroutine(s), 12 GoMaxProcs.
@Real-time charts is on http://127.0.0.1:28888

Summary:
  Concurrent              0
  Elapsed          1m0.001s
  Count/RPS   24753 412.537
    200       22362 372.688
    500         2391 39.849

Statistics   Min     Mean    StdDev     Max
  Latency    1µs   13.328ms  5.154ms  31.093ms
  RPS       68.94   412.53   219.73    761.04

Latency Percentile:
  P50         P75       P90       P95       P99      P99.9     P99.99
  14.147ms  17.102ms  18.559ms  19.153ms  19.579ms  20.199ms  30.011ms

Latency Histogram:
  17µs      2159   8.72%  ■■■■■■■■■■■■■■■■■■■■
  9.789ms   2840  11.47%  ■■■■■■■■■■■■■■■■■■■■■■■■■■
  11.773ms  3839  15.51%  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  13.504ms  3965  16.02%  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  15.073ms  3269  13.21%  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  16.908ms  4279  17.29%  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  18.55ms   4347  17.56%  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  19.462ms    55   0.22%  ■

img.png

部署

  1. 上传 berf 到 /usr/local/bin 目录
  2. 建一个 berf 目录,放入 berf 程序: mkdir berf; cd berf
  3. 在 berf 目录中创建 ctl 脚本: berf -init
  4. ./ctl start -f nop 启动硬件监控采点后台进程
  5. 下载目录中最新的形如 berf_202111301122.log.gz 采点日志
  6. 本地使用命令 berf berf_202111301122.log.gz 在浏览器中查看采点曲线,进行分析
  7. 参数
    • export BERF_TICK=1s 每 1s 生成一个点,默认 5s 生成一个.

Profile 支持

  1. 生成 Profile 示例: berf -P demo.http:new

  2. 编辑新生成的 demo.http 文件,如下所示

    ### 生产环境 env: prod
    export baseURL=http://1.2.3.4:5004
    ### 测试环境 env: test
    export baseURL=http://192.168.0.1:5004
    ### 本地环境 env: local
    export baseURL=http://127.0.0.1:5004
    
    ### [tag=1]
    GET ${baseURL}/status
    
    ### [tag=2]
    POST ${baseURL}/dynamic/demo
    
    {"name": "bingoo"}
    
  3. 使用 Profile 中的 test 环境变量 跑压测 berf -P demo.http -env test

    1. 或者指定 tag 跑压测 berf -P demo.http:tag1
    2. 或者指定多个 tag 跑压测 berf -P demo.http:tag1,tag2
    3. 或者指定 tag 范围 跑压测 berf -P demo.http:tag1-tag3
    4. 混合模式 berf -P demo.http:tag1-tag3,tag5,tag7-tag9

Similar tools

  1. fortio
  2. 字节跳动 cloudwego/hertz
  3. Vegeta is a versatile HTTP load testing tool built out of a need to drill HTTP services with a constant request rate. It can be used both as a command line utility and a library.

测试最大并发连接数

  1. MAX_GREEDY_CONNS_PER_HOST=30000 MAX_IDLE_CONN_DURATION=1h berf --qps 1000 --url 192.168.126.224:12123 -v MAX_IDLE_CONN_DURATION 默认10s, qps 过低时,会导致空闲连接超过 10s 被释放
  2. 大量报错 connect: cannot assign requested address 时,增加可用端口范围, 参考 文章
    # 确认port_range范围
    # sysctl -a |grep port_range
    net.ipv4.ip_local_port_range = 50000    65000
    # 修改配置
    # vi /etc/sysctl.conf
    net.ipv4.ip_local_port_range = 1024     65535
    # 改完后,执行命令“sysctl -p”使参数生效。
    
  3. netstat -ant | grep 12123 | grep ESTABLISHED | wc -l

Documentation

Index

Constants

View Source
const (
	ViewTpl = `
$(function () {
{{ .SetInterval }}(views_sync, {{ .Interval }}); });
let views = {{.ViewsMap}};
{{.ViewSyncJS}}
`
	PageTpl = `` /* 362-byte string literal not displayed */

)
View Source
const (
	FgBlackColor int = iota + 30
	FgRedColor
	FgGreenColor
	FgYellowColor
	FgBlueColor
	FgMagentaColor
	FgCyanColor
	FgWhiteColor
)
View Source
const (
	AlignLeft = iota
	AlignRight
	AlignCenter
)

Variables

View Source
var Demo = false

Demo tells the underlying benchmark is only a demo.

View Source
var ErrNoop = errors.New("noop")

ErrNoop means there is no operation defined.

View Source
var (
	IsStdoutTerminal = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
)

Functions

func New

func New[T any](t T) *T

func StartBench

func StartBench(ctx context.Context, fn Benchable, fns ...ConfigFn)

StartBench starts a benchmark.

Types

type BenchEmpty

type BenchEmpty struct{}

BenchEmpty is an empty benchmark.

func (*BenchEmpty) Final

func (f *BenchEmpty) Final(context.Context, *Config) error

func (*BenchEmpty) Init

func (f *BenchEmpty) Init(context.Context, *Config) error

func (*BenchEmpty) Invoke

func (f *BenchEmpty) Invoke(context.Context, *Config) (*Result, error)

func (*BenchEmpty) Name

func (f *BenchEmpty) Name(context.Context, *Config) string

type BenchOption

type BenchOption struct {
	NoReport bool
}

BenchOption defines the bench option.

type Benchable

type Benchable interface {
	Name(context.Context, *Config) string
	Init(context.Context, *Config) (*BenchOption, error)
	Invoke(context.Context, *Config) (*Result, error)
	Final(context.Context, *Config) error
}

Benchable abstract interface for benchmark.

type Charts

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

func NewCharts

func NewCharts(chartsData func() *ChartsReport, config *Config) *Charts

func (*Charts) Handler

func (c *Charts) Handler(ctx *fasthttp.RequestCtx)

func (*Charts) Serve

func (c *Charts) Serve(ln net.Listener, port int)

type ChartsReport

type ChartsReport struct {
	Latency            []util.Float64
	LatencyPercentiles []util.Float64
	RPS                util.Float64
	Concurrent         int64
}

type Config

type Config struct {
	util.Features
	PlotsHandle util.JSONLogger

	OkStatus string

	Desc         string
	PlotsFile    string
	FeaturesConf string
	CountingName string
	ThinkTime    string
	Incr         util.GoroutineIncr

	ChartPort int

	Duration   time.Duration
	Verbose    int
	N          int
	QPS        float64
	Goroutines int

	GoMaxProcs int
}

Config defines the bench configuration.

func (*Config) Description

func (c *Config) Description(benchableName string) string

func (*Config) IsDryPlots

func (c *Config) IsDryPlots() bool

func (*Config) Setup

func (c *Config) Setup()

Setup setups the environment by the config.

type ConfigFn

type ConfigFn func(*Config)

ConfigFn defines the config function.

func WithConfig

func WithConfig(v *Config) ConfigFn

WithConfig with customized config.

func WithCounting

func WithCounting(name string) ConfigFn

WithCounting with customized config.

func WithOkStatus

func WithOkStatus(okStatus string) ConfigFn

WithOkStatus set the status which represents OK.

type F

type F func(context.Context, *Config) (*Result, error)

func (F) Final

func (f F) Final(context.Context, *Config) error

func (F) Init

func (f F) Init(context.Context, *Config) (*BenchOption, error)

func (F) Invoke

func (f F) Invoke(ctx context.Context, c *Config) (*Result, error)

func (F) Name

func (f F) Name(context.Context, *Config) string

type Metrics

type Metrics struct {
	Values map[string]interface{} `json:"values"`
	Time   string                 `json:"time"`
}

type PercentileReport

type PercentileReport map[string]string

type Printer

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

func (*Printer) PrintLoop

func (p *Printer) PrintLoop(snapshot func() *SnapshotReport, doneChan <-chan struct{}, requests int)

type Report

type Report struct {
	PercentileReport `json:"Percentile"`
	StatsReport      `json:"Stats"`
	SummaryReport    `json:"Summary"`
}

type ReportRecord

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

func (*ReportRecord) Reset

func (r *ReportRecord) Reset()

type Requester

type Requester struct {

	// QPS is the rate limit in queries per second.
	QPS float64
	// contains filtered or unexported fields
}

Requester is request structure.

type Result

type Result struct {
	Status     []string
	Counting   []string
	ReadBytes  int64
	WriteBytes int64
	Cost       time.Duration
	AssertFail int64
}

Result defines the benchmark result.

type SnapshotHistogram

type SnapshotHistogram struct {
	Mean  time.Duration
	Count int
}

type SnapshotPercentile

type SnapshotPercentile struct {
	Percentile float64
	Latency    time.Duration
}

type SnapshotReport

type SnapshotReport struct {
	Stats            *SnapshotStats
	Codes, Errors    map[string]int64
	RpsStats         *SnapshotRpsStats
	Histograms       []*SnapshotHistogram
	Percentiles      []*SnapshotPercentile
	RPS, ElapseInSec float64
	Count, Counting  int64

	ReadBytes, WriteBytes int64
	AssertFail            int64
	Elapsed               time.Duration
}

type SnapshotRpsStats

type SnapshotRpsStats struct {
	Min, Mean, StdDev, Max float64
}

type SnapshotStats

type SnapshotStats struct {
	Min, Mean, StdDev, Max time.Duration
}

type StatItem

type StatItem struct {
	Min, Max, StdDev, Mean string
}

type Stats

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

func (*Stats) Mean

func (s *Stats) Mean() float64

func (*Stats) Reset

func (s *Stats) Reset()

func (*Stats) Stddev

func (s *Stats) Stddev() float64

func (*Stats) Update

func (s *Stats) Update(v float64)

type StatsReport

type StatsReport struct {
	Latency StatItem
	RPS     StatItem
}

type StreamReport

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

func NewStreamReport

func NewStreamReport(requester *Requester) *StreamReport

func (*StreamReport) Charts

func (s *StreamReport) Charts() *ChartsReport

func (*StreamReport) Collect

func (s *StreamReport) Collect(recordChan <-chan *ReportRecord)

func (*StreamReport) Done

func (s *StreamReport) Done() <-chan struct{}

func (*StreamReport) Snapshot

func (s *StreamReport) Snapshot() *SnapshotReport

type SummaryReport

type SummaryReport struct {
	Elapsed     string
	RPS         string
	ReadsWrites string
	Count       int64
	Counting    int64
}

type Views

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

func NewViews

func NewViews(size string, dryPlots bool) *Views

Directories

Path Synopsis
cmd
fgrpc
pkg
blow/lossy
Package lossy simulates bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces.
Package lossy simulates bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces.
all
mem
net

Jump to

Keyboard shortcuts

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