-
Notifications
You must be signed in to change notification settings - Fork 70
/
benchmark_test.go
117 lines (108 loc) · 2.48 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package redis
import (
"testing"
"fmt"
"math/rand"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
)
var zone string = "example.com."
var benchmarkEntries = [][]string{
{"@",
"{\"a\":[{\"ttl\":300, \"ip\":\"2.2.2.2\"}]}",
},
{"x",
"{\"a\":[{\"ttl\":300, \"ip\":\"3.3.3.3\"}]}",
},
{"y",
"{\"a\":[{\"ttl\":300, \"ip\":\"4.4.4.4\"}]}",
},
{"z",
"{\"a\":[{\"ttl\":300, \"ip\":\"5.5.5.5\"}]}",
},
}
var testCasesHit = []test.Case {
{
Qname: "example.com.", Qtype: dns.TypeA,
Answer: []dns.RR{
test.A("example.com. 300 IN A 2.2.2.2"),
},
},
{
Qname: "x.example.com.", Qtype: dns.TypeA,
Answer: []dns.RR{
test.A("x.example.com. 300 IN A 3.3.3.3"),
},
},
{
Qname: "y.example.com.", Qtype: dns.TypeA,
Answer: []dns.RR{
test.A("y.example.com. 300 IN A 4.4.4.4"),
},
},
{
Qname: "z.example.com.", Qtype: dns.TypeA,
Answer: []dns.RR{
test.A("z.example.com. 300 IN A 5.5.5.5"),
},
},
}
var testCasesMiss = []test.Case {
{
Qname: "q.example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
},
{
Qname: "w.example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
},
{
Qname: "e.example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
},
{
Qname: "r.example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
},
}
func BenchmarkHit(b *testing.B) {
fmt.Println("benchmark test")
r := newRedisPlugin()
conn := r.Pool.Get()
defer conn.Close()
conn.Do("EVAL", "return redis.call('del', unpack(redis.call('keys', ARGV[1])))", 0, r.keyPrefix + "*" + r.keySuffix)
for _, cmd := range benchmarkEntries {
err := r.save(zone, cmd[0], cmd[1])
if err != nil {
fmt.Println("error in redis", err)
}
}
b.ResetTimer()
for i :=0; i<b.N; i++ {
j := rand.Intn(len(testCasesHit))
m := testCasesHit[j].Msg()
rec := dnstest.NewRecorder(&test.ResponseWriter{})
r.ServeDNS(ctxt, rec, m)
}
}
func BenchmarkMiss(b *testing.B) {
fmt.Println("benchmark test")
r := newRedisPlugin()
conn := r.Pool.Get()
defer conn.Close()
conn.Do("EVAL", "return redis.call('del', unpack(redis.call('keys', ARGV[1])))", 0, r.keyPrefix + "*" + r.keySuffix)
for _, cmd := range benchmarkEntries {
err := r.save(zone, cmd[0], cmd[1])
if err != nil {
fmt.Println("error in redis", err)
}
}
b.ResetTimer()
for i :=0; i<b.N; i++ {
j := rand.Intn(len(testCasesMiss))
m := testCasesMiss[j].Msg()
rec := dnstest.NewRecorder(&test.ResponseWriter{})
r.ServeDNS(ctxt, rec, m)
}
}