-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathstats_test.go
More file actions
123 lines (108 loc) · 2.98 KB
/
stats_test.go
File metadata and controls
123 lines (108 loc) · 2.98 KB
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
118
119
120
121
122
123
package fastdns
import (
"net/netip"
"testing"
"time"
)
// BenchmarkServerUpdateStats measures the bookkeeping for incoming requests.
func BenchmarkServerUpdateStats(b *testing.B) {
payload := []byte{
0x8e, 0x52, // Transaction ID
0x81, 0x80, // Flags: standard response
0x00, 0x01, // Questions
0x00, 0x02, // Answer RRs
0x00, 0x00, // Authority RRs
0x00, 0x00, // Additional RRs
0x04, 'p', 'h', 'u', 's',
0x03, 'c', 'o', 'm',
0x00,
0x00, 0x02, // QTYPE NS
0x00, 0x01, // QCLASS IN
0xc0, 0x0c, // NAME pointer to question
0x00, 0x02, // TYPE NS
0x00, 0x01, // CLASS IN
0x00, 0x00, 0x54, 0x5f, // TTL 0x545f
0x00, 0x14, // RDLENGTH 20
0x03, 's', 'u', 'e',
0x02, 'n', 's',
0x0a, 'c', 'l', 'o', 'u', 'd', 'f', 'l', 'a', 'r', 'e',
0xc0, 0x11, // pointer to label "com"
0xc0, 0x0c, // NAME pointer to question
0x00, 0x02, // TYPE NS
0x00, 0x01, // CLASS IN
0x00, 0x00, 0x54, 0x5f, // TTL 0x545f
0x00, 0x07, // RDLENGTH 7
0x04, 'j', 'a', 'k', 'e',
0xc0, 0x2a, // pointer to "ns.cloudflare.com"
}
resp := AcquireMessage()
defer ReleaseMessage(resp)
err := ParseMessage(resp, payload, true)
if err != nil {
b.Errorf("ParseMessage(%+v) error: %+v", payload, err)
}
stats := &CoreStats{
Prefix: "coredns_",
Family: "1",
Proto: "udp",
Server: "dns://:53",
Zone: ".",
}
addr := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), 12345)
b.ResetTimer()
for i := 0; i < b.N; i++ {
stats.UpdateStats(addr, resp, time.Millisecond)
}
}
// BenchmarkServerAppendOpenMetrics measures metrics rendering throughput.
func BenchmarkServerAppendOpenMetrics(b *testing.B) {
payload := []byte{
0x8e, 0x52, // Transaction ID
0x81, 0x80, // Flags: standard response
0x00, 0x01, // Questions
0x00, 0x02, // Answer RRs
0x00, 0x00, // Authority RRs
0x00, 0x00, // Additional RRs
0x04, 'p', 'h', 'u', 's',
0x03, 'c', 'o', 'm',
0x00,
0x00, 0x02, // QTYPE NS
0x00, 0x01, // QCLASS IN
0xc0, 0x0c, // NAME pointer to question
0x00, 0x02, // TYPE NS
0x00, 0x01, // CLASS IN
0x00, 0x00, 0x54, 0x5f, // TTL 0x545f
0x00, 0x14, // RDLENGTH 20
0x03, 's', 'u', 'e',
0x02, 'n', 's',
0x0a, 'c', 'l', 'o', 'u', 'd', 'f', 'l', 'a', 'r', 'e',
0xc0, 0x11, // pointer to label "com"
0xc0, 0x0c, // NAME pointer to question
0x00, 0x02, // TYPE NS
0x00, 0x01, // CLASS IN
0x00, 0x00, 0x54, 0x5f, // TTL 0x545f
0x00, 0x07, // RDLENGTH 7
0x04, 'j', 'a', 'k', 'e',
0xc0, 0x2a, // pointer to "ns.cloudflare.com"
}
resp := AcquireMessage()
defer ReleaseMessage(resp)
err := ParseMessage(resp, payload, true)
if err != nil {
b.Errorf("ParseMessage(%+v) error: %+v", payload, err)
}
stats := &CoreStats{
Prefix: "coredns_",
Family: "1",
Proto: "udp",
Server: "dns://:53",
Zone: ".",
}
addr := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), 12345)
stats.UpdateStats(addr, resp, time.Millisecond)
buf := make([]byte, 0, 32*1024)
b.ResetTimer()
for i := 0; i < b.N; i++ {
stats.AppendOpenMetrics(buf[:0])
}
}