/
test.go
108 lines (93 loc) · 1.84 KB
/
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
//go:generate msgp
package main
import (
"fmt"
"github.com/codahale/hdrhistogram"
)
func record(h *hdrhistogram.Histogram, i int) {
if err := h.RecordValue(int64(i)); err != nil {
panic(err)
}
}
func main() {
// 0.1 ms to 600s= 6M 0.1ms
// 1ms to 60s = 60k ms
// 6M, 3 -> 0values: 14k 10M values: 17500
// 6M, 2 -> 0values: 2300 10M values: 2700
// 60k, 3 -> 0values: 7k 10M values: 10500
// 60k, 2 -> 0values: 1400 10M values: 1800
// for comparison: maxuint16 (2B) is 65k
// every second, 1h worth = 3600 vals * 2 Bytes/val =7kB
h := hdrhistogram.New(1, int64(60000), 2)
// for i := 0; i < M6; i++ {
// record(h, i)
// }
//for i := 0; i < 2000000; i++ {
// record(h, 1234567/100)
// }
// for i := 0; i < 2000000; i++ {
// record(h, 1000/100)
// }
// for i := 0; i < 2000000; i++ {
// record(h, 200/100)
// }
// 4M
// for i := 2000000; i < 6000000; i++ {
// record(h, i/100)
// }
// 10 200
// 20 200
// 30 1000
// 40 1000
// 50 1M
// 60 1M
// 70 3M
// 80 4M
// 90
// 100
qs := []float64{
10,
20,
30,
40,
50,
60,
70,
//75,
80,
90,
//95,
//99,
//99.9,
//99.99,
100,
}
fmt.Println("value at requested quantiltes:")
for _, q := range qs {
fmt.Println(q, h.ValueAtQuantile(q))
}
actual := h.CumulativeDistribution()
fmt.Println("returned cumulative distribution:")
for _, b := range actual {
fmt.Printf("Count %10.d Quantile %4.f ValueAt %10.d\n", b.Count, b.Quantile, b.ValueAt)
}
s := h.Export()
snap := Snap{
s.LowestTrackableValue,
s.HighestTrackableValue,
s.SignificantFigures,
s.Counts,
}
in := make([]byte, 0)
bin, err := snap.MarshalMsg(in)
if err != nil {
panic(err)
}
fmt.Println("serialized size", len(bin))
}
type Snap struct {
LowestTrackableValue int64
HighestTrackableValue int64
SignificantFigures int64
Counts []int64
}