redbench

Benchmarking for custom Redis commands and modules

Github星跟踪图

Redbench

GoDoc

Redbench is a Go package that allows for bootstrapping benchmarks
for servers using a custom implementation of the Redis protocol. It provides
the same inputs and outputs as the
redis-benchmark tool.

The purpose of this library is to provide benchmarking for
Redcon compatible servers such as
Tile38, but also works well for Redis
operations that are not covered by the redis-benchmark tool such as the
GEO* commands, custom lua scripts, or Redis Modules.

Getting Started

Installing

To start using Redbench, install Go and run go get:

$ go get -u github.com/tidwall/redbench

This will retrieve the library.

Example

The following example will run a benchmark for the PING,SET,GET,GEOADD,GEORADIUS
commands on a server at 127.0.0.1:6379.

package main

import (
	"math/rand"
	"strconv"
	"time"

	"github.com/tidwall/redbench"
)

func main() {
	redbench.Bench("PING", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte {
		return redbench.AppendCommand(buf, "PING")
	})
	redbench.Bench("SET", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte {
		return redbench.AppendCommand(buf, "SET", "key:string", "val")
	})
	redbench.Bench("GET", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte {
		return redbench.AppendCommand(buf, "GET", "key:string")
	})
	rand.Seed(time.Now().UnixNano())
	redbench.Bench("GEOADD", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte {
		return redbench.AppendCommand(buf, "GEOADD", "key:geo",
			strconv.FormatFloat(rand.Float64()*360-180, 'f', 7, 64),
			strconv.FormatFloat(rand.Float64()*170-85, 'f', 7, 64),
			strconv.Itoa(rand.Int()))
	})
	redbench.Bench("GEORADIUS", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte {
		return redbench.AppendCommand(buf, "GEORADIUS", "key:geo",
			strconv.FormatFloat(rand.Float64()*360-180, 'f', 7, 64),
			strconv.FormatFloat(rand.Float64()*170-85, 'f', 7, 64),
			"10", "km")
	})
}

Which is similar to executing:

$ redis-benchmark -t PING,SET,GET

For a more complete example, check out tile38-benchmark from the Tile38 project.

Custom Options

type Options struct {
	Requests int
	Clients  int
	Pipeline int
	Quiet    bool
	CSV      bool
	Stdout   io.Writer
	Stderr   io.Writer
}

Contact

Josh Baker @tidwall

License

Redbench source code is available under the MIT License.

主要指标

概览
名称与所有者tidwall/redbench
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-03-31 15:23:01
推送于2021-01-25 22:06:56
最后一次提交2018-11-10 10:37:44
发布数1
最新版本名称v0.1.0 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数33
关注者数3
派生数9
提交数5
已启用问题?
问题数0
打开的问题数0
拉请求数0
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?