-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
99 lines (87 loc) · 2.07 KB
/
benchmark_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"drcache-client/consistent_hashing"
"github.com/bradfitz/gomemcache/memcache"
"google.golang.org/grpc"
"log"
"testing"
pb "drcache-client/grpc"
)
func BenchmarkAdd(b *testing.B) {
ring := consistent_hashing.NewRing(servers)
clients := make(map[string]pb.DrcacheClient)
for address := range servers {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
c := pb.NewDrcacheClient(conn)
clients[address] = c
}
for n := 0; n < b.N; n++ {
item1 := pb.Item{Key: string(n + 100), Value: []byte("11331"), LastUpdate: 1, Expiration: 100}
_, err := add(clients, item1, ring)
if err != nil {
log.Fatalf("could not greet: %v", err)
}
//log.Printf("key: %s", r.Message)
}
}
//qq
func BenchmarkGet(b *testing.B) {
ring := consistent_hashing.NewRing(servers)
clients := make(map[string]pb.DrcacheClient)
for address := range servers {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
c := pb.NewDrcacheClient(conn)
clients[address] = c
}
for n := 0; n < b.N; n++ {
go func() {
r, err := get(clients, string(n+100), ring)
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("key: %s", r.Message)
}()
}
}
func BenchmarkGetMemcache(b *testing.B) {
var clients [10]*memcache.Client
for i := 0; i < 10; i++ {
clients[i] = memcache.New("localhost:11211")
}
for n := 0; n < b.N; n++ {
go func() {
_, _ = clients[n%10].Get(string(n))
}()
}
}
func BenchmarkAddMemcache(b *testing.B) {
var clients [10]*memcache.Client
for i := 0; i < 10; i++ {
clients[i] = memcache.New("localhost:11211")
}
var items [100000]*memcache.Item
for i := 0; i < 100000; i++ {
items[i] = &memcache.Item{
Key: string(i),
Value: []byte(string(i % 4)),
Flags: 0,
Expiration: 0,
}
}
for n := 0; n < b.N; n++ {
go func() {
_ = clients[n%10].Add(&memcache.Item{
Key: "id",
Value: nil,
Flags: 0,
Expiration: 0,
})
}()
}
}