forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.go
58 lines (44 loc) · 1021 Bytes
/
bench.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"log"
"strconv"
"github.com/coreos/go-etcd/etcd"
)
func write(requests int, end chan int) {
client := etcd.NewClient(nil)
for i := 0; i < requests; i++ {
key := strconv.Itoa(i)
client.Set(key, key, 0)
}
end <- 1
}
func watch(key string) {
client := etcd.NewClient(nil)
receiver := make(chan *etcd.Response)
go client.Watch(key, 0, true, receiver, nil)
log.Printf("watching: %s", key)
received := 0
for {
<-receiver
received++
}
}
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")
flag.Parse()
for i := 0; i < *watches; i++ {
key := strconv.Itoa(i)
go watch(key)
}
wChan := make(chan int, *cWrites)
for i := 0; i < *cWrites; i++ {
go write((*rWrites / *cWrites), wChan)
}
for i := 0; i < *cWrites; i++ {
<-wChan
log.Printf("Completed %d writes", (*rWrites / *cWrites))
}
}