Skip to content

Instantly share code, notes, and snippets.

@tylertreat
Created January 10, 2016 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylertreat/f0ac872bf8f8249a96c9 to your computer and use it in GitHub Desktop.
Save tylertreat/f0ac872bf8f8249a96c9 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/tylertreat/bench"
"github.com/tylertreat/bench/requester"
)
func main() {
var (
system = flag.String("s", "", "[nats, redis, kafka, amqp]")
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")
url = flag.String("url", "", "broker url")
)
flag.Parse()
var factory bench.RequesterFactory
switch *system {
case "nats":
factory = &requester.NATSRequesterFactory{
URL: *url,
PayloadSize: *size,
Subject: "foo",
}
case "redis":
factory = &requester.RedisPubSubRequesterFactory{
URL: *url,
PayloadSize: *size,
Channel: "foo",
}
case "kafka":
factory = &requester.KafkaRequesterFactory{
URLs: []string{*url},
PayloadSize: 200,
Topic: "foo",
}
case "amqp":
factory = &requester.AMQPRequesterFactory{
URL: *url,
PayloadSize: 200,
Queue: "foo",
Exchange: "foo",
}
default:
fmt.Printf("Unknown system '%s'\n", *system)
os.Exit(1)
}
run(factory, *rate, *connections, *duration, fmt.Sprintf("%s_%d_%d.txt", *system, *rate, *size))
}
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)
}
@alexellis
Copy link

Hey, do you have a repo with all the code together?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment