tile38/vendor/github.com/tidwall/redbench
tidwall cfc65a13f6 Refactor repository and build scripts
This commit includes updates that affects the build, testing, and
deployment of Tile38.

- The root level build.sh has been broken up into multiple scripts
  and placed in the "scripts" directory.

- The vendor directory has been updated to follow the Go modules
  rules, thus `make` should work on isolated environments. Also
  some vendored packages may have been updated to a later
  version, if needed.

- The Makefile has been updated to allow for making single
  binaries such as `make tile38-server`. There is some scaffolding
  during the build process, so from now on all binaries should be
  made using make. For example, to run a development version of
  the tile38-cli binary, do this:
     make tile38-cli && ./tile38-cli
  not this:
     go run cmd/tile38-cli/main.go

- Travis.CI docker push script has been updated to address a
  change to Docker's JSON repo meta output, which in turn fixes
  a bug where new Tile38 versions were not being properly pushed
  to Docker
2019-11-18 10:33:15 -07:00
..
LICENSE Refactor repository and build scripts 2019-11-18 10:33:15 -07:00
README.md Refactor repository and build scripts 2019-11-18 10:33:15 -07:00
bench.go Refactor repository and build scripts 2019-11-18 10:33:15 -07:00

README.md

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.