forked from grafana-cold-storage/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_test.go
More file actions
94 lines (80 loc) · 2.54 KB
/
Copy pathinput_test.go
File metadata and controls
94 lines (80 loc) · 2.54 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
package input
import (
"fmt"
"testing"
"time"
"github.com/benbjohnson/clock"
"github.com/raintank/metrictank/cluster"
"github.com/raintank/metrictank/conf"
"github.com/raintank/metrictank/idx/memory"
"github.com/raintank/metrictank/mdata"
"github.com/raintank/metrictank/mdata/cache"
"github.com/raintank/metrictank/usage"
"gopkg.in/raintank/schema.v1"
)
func BenchmarkProcessUniqueMetrics(b *testing.B) {
cluster.Init("default", "test", time.Now(), "http", 6060)
store := mdata.NewDevnullStore()
mdata.SetSingleSchema(conf.NewRetentionMT(10, 10000, 600, 10, true))
mdata.SetSingleAgg(conf.Avg, conf.Min, conf.Max)
aggmetrics := mdata.NewAggMetrics(store, &cache.MockCache{}, false, 800, 8000, 0)
metricIndex := memory.New()
metricIndex.Init()
usage := usage.New(300, aggmetrics, metricIndex, clock.New())
in := NewDefaultHandler(aggmetrics, metricIndex, usage, "BenchmarkProcess")
// timestamps start at 10 and go up from there. (we can't use 0, see AggMetric.Add())
datas := make([]*schema.MetricData, b.N)
for i := 0; i < b.N; i++ {
name := fmt.Sprintf("fake.metric.%d", i)
metric := &schema.MetricData{
Id: "some.id.of.a.metric",
OrgId: 500,
Name: name,
Metric: name,
Interval: 10,
Value: 1234.567,
Unit: "ms",
Time: int64((i + 1) * 10),
Mtype: "gauge",
Tags: []string{"some_tag", "ok"},
}
datas[i] = metric
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
in.Process(datas[i], 1)
}
}
func BenchmarkProcessSameMetric(b *testing.B) {
cluster.Init("default", "test", time.Now(), "http", 6060)
store := mdata.NewDevnullStore()
mdata.SetSingleSchema(conf.NewRetentionMT(10, 10000, 600, 10, true))
mdata.SetSingleAgg(conf.Avg, conf.Min, conf.Max)
aggmetrics := mdata.NewAggMetrics(store, &cache.MockCache{}, false, 800, 8000, 0)
metricIndex := memory.New()
metricIndex.Init()
usage := usage.New(300, aggmetrics, metricIndex, clock.New())
in := NewDefaultHandler(aggmetrics, metricIndex, usage, "BenchmarkProcess")
// timestamps start at 10 and go up from there. (we can't use 0, see AggMetric.Add())
datas := make([]*schema.MetricData, b.N)
for i := 0; i < b.N; i++ {
name := "fake.metric.same"
metric := &schema.MetricData{
Id: "some.id.of.a.metric",
OrgId: 500,
Name: name,
Metric: name,
Interval: 10,
Value: 1234.567,
Unit: "ms",
Time: int64((i + 1) * 10),
Mtype: "gauge",
Tags: []string{"some_tag", "ok"},
}
datas[i] = metric
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
in.Process(datas[i], 1)
}
}