Skip to content

Commit

Permalink
Merge pull request etcd-io#635 from metaflow/benchmarking
Browse files Browse the repository at this point in the history
feat(benchmark) fix of flag arguments and updated logging
  • Loading branch information
philips committed Apr 4, 2014
2 parents bec7d7f + 803aeb8 commit d8a53ca
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions bench/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import (
"flag"
"log"
"strconv"
"time"

"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
)

var (
// output debug to log
verbose *bool
)

func write(endpoint string, requests int, end chan int) {
client := etcd.NewClient([]string{endpoint})

Expand All @@ -27,7 +33,9 @@ func watch(endpoint string, key string) {
receiver := make(chan *etcd.Response)
go client.Watch(key, 0, true, receiver, nil)

log.Printf("watching: %s", key)
if *verbose {
log.Printf("watching: %s", key)
}

received := 0
for {
Expand All @@ -41,11 +49,15 @@ func main() {

rWrites := flag.Int("write-requests", 50000, "number of writes")
cWrites := flag.Int("concurrent-writes", 500, "number of concurrent writes")

watches := flag.Int("watches", 500, "number of writes")
watches := flag.Int("watches", 500, "number of concurrent watches")
verbose = flag.Bool("verbose", false, "output debug info")

flag.Parse()

log.Printf("Benchmarking %v", *endpoint)
log.Printf("%v writes with %v concurrent writers and %v watches", *rWrites, *cWrites, *watches)

t := time.Now()
for i := 0; i < *watches; i++ {
key := strconv.Itoa(i)
go watch(*endpoint, key)
Expand All @@ -58,6 +70,10 @@ func main() {

for i := 0; i < *cWrites; i++ {
<-wChan
log.Printf("Completed %d writes", (*rWrites / *cWrites))
if *verbose {
log.Printf("Completed %d writes", (*rWrites / *cWrites))
}
}

log.Printf("Took %v", time.Now().Sub(t))
}

0 comments on commit d8a53ca

Please sign in to comment.