Created
January 10, 2016 04:43
-
-
Save tylertreat/f0ac872bf8f8249a96c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, do you have a repo with all the code together?