Giter Site home page Giter Site logo

redbench's Introduction

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.

redbench's People

Contributors

tidwall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.