Skip to content

Instantly share code, notes, and snippets.

@tylertreat
Last active January 24, 2017 22:20
Show Gist options
  • Save tylertreat/0084df75eebf9950fe18 to your computer and use it in GitHub Desktop.
Save tylertreat/0084df75eebf9950fe18 to your computer and use it in GitHub Desktop.
Redis and NATS Benchmark
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/gocql/gocql"
"github.com/nats-io/nats"
"github.com/tylertreat/bench"
"github.com/tylertreat/bench/requester"
)
func main() {
var (
system = flag.String("s", "", "[nats, redis, redis-pubsub, kafka, cassandra]")
rate = flag.Uint64("r", 14000, "requests per second")
size = flag.Int("sz", 200, "message size")
duration = flag.Duration("d", 30*time.Second, "benchmark runtime")
connections = flag.Uint64("c", 1, "connections")
output = flag.String("o", "benchmark.txt", "Output file name")
)
flag.Parse()
var factory bench.RequesterFactory
switch *system {
case "nats":
factory = &requester.NATSRequesterFactory{
URL: nats.DefaultURL,
PayloadSize: *size,
Subject: "foo",
}
case "redis":
factory = &requester.RedisRequesterFactory{URL: ":6379"}
case "redis-pubsub":
factory = &requester.RedisPubSubRequesterFactory{
URL: ":6379",
PayloadSize: *size,
Channel: "foo",
}
case "kafka":
factory = &requester.KafkaRequesterFactory{
URLs: []string{"localhost:9092"},
PayloadSize: 200,
Topic: "foo",
}
case "cassandra":
factory = &requester.CassandraRequesterFactory{
URLs: []string{"localhost"},
Keyspace: "benchmark",
Consistency: gocql.One,
Statement: "SELECT * FROM event",
Values: []interface{}{},
}
default:
fmt.Printf("Unknown system '%s'\n", *system)
os.Exit(1)
}
run(factory, *rate, *connections, *duration, *output)
}
func run(factory bench.RequesterFactory, rate, conns uint64, duration time.Duration,
output string) {
benchmark := bench.NewBenchmark(factory, rate, conns, duration)
summary, err := benchmark.Run()
if err != nil {
panic(err)
}
if err := summary.GenerateLatencyDistribution(nil, output); err != nil {
panic(err)
}
fmt.Println(summary)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment