berf

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 45 Imported by: 0

README

berf

berf framework for local methods.

Features

  1. support @var in URL like berf :9335/pingoo/@ksuid -u imgs -d60s -v, 2021-12-29
  2. support httpie like args berf :10014/query q="show databases" -n1, 2021-12-23
  3. berf :5003/api/demo -n20 -pA to print all details instead of realtime statistics on terminal, 2021-12-22.
  4. 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 生成一个.

Documentation

Index

Constants

View Source
const (
	ViewTpl = `
$(function () {
{{ .SetInterval }}(views_sync, {{ .Interval }}); });
let views = {{.ViewsMap}};
{{.ViewSyncJS}}
`
	PageTpl = `` /* 358-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 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 StartBench

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

StartBench starts a benchmark.

Types

type BenchEmpty

type BenchEmpty struct{}

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
}

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
}

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 {
	RPS                util.Float64
	Latency            []util.Float64
	LatencyPercentiles []util.Float64
	Concurrent         int64
}

type Config

type Config struct {
	N          int
	Goroutines int
	Duration   time.Duration
	Incr       util.GoroutineIncr

	GoMaxProcs   int
	Qps          float64
	FeaturesConf string
	Verbose      int
	ThinkTime    string
	ChartPort    int

	util.Features
	CountingName string
	OkStatus     string
	PlotsFile    string
	PlotsHandle  *util.JSONLogFile

	Desc string
}

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

func (c *Config) NewRequester(ctx context.Context, fn Benchable) *Requester

func (*Config) Setup

func (c *Config) Setup()

Setup setups the environment by the config.

type ConfigFn

type ConfigFn func(*Config)

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 {
	Time   string                 `json:"time"`
	Values map[string]interface{} `json:"values"`
}

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 {
	SummaryReport    `json:"Summary"`
	StatsReport      `json:"Stats"`
	PercentileReport `json:"Percentile"`
}

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
}

type Result

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

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 {
	Elapsed                         time.Duration
	Codes, Errors                   map[string]int64
	RPS, ElapseInSec                float64
	ReadThroughput, WriteThroughput float64
	Count, Counting                 int64

	Stats       *SnapshotStats
	RpsStats    *SnapshotRpsStats
	Percentiles []*SnapshotPercentile
	Histograms  []*SnapshotHistogram
}

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(records <-chan *ReportRecord)

func (*StreamReport) Done

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

func (*StreamReport) Snapshot

func (s *StreamReport) Snapshot() *SnapshotReport

type SummaryReport

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

type Views

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

func NewViews

func NewViews(size string, dryPlots bool) *Views

Directories

Path Synopsis
cmd
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