File: server_bench_test.go

package info (click to toggle)
influxdb 1.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,296 kB
  • ctags: 7,599
  • sloc: sh: 1,231; python: 804; ruby: 118; makefile: 88
file content (90 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download
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
package run_test

import (
	"bytes"
	"fmt"
	"net/url"
	"testing"
)

func BenchmarkServer_Query_Count_1(b *testing.B) {
	benchmarkServerQueryCount(b, 1)
}

func BenchmarkServer_Query_Count_1K(b *testing.B) {
	benchmarkServerQueryCount(b, 1000)
}

func BenchmarkServer_Query_Count_100K(b *testing.B) {
	benchmarkServerQueryCount(b, 100000)
}

func BenchmarkServer_Query_Count_1M(b *testing.B) {
	benchmarkServerQueryCount(b, 1000000)
}

func benchmarkServerQueryCount(b *testing.B, pointN int) {
	s := OpenDefaultServer(NewConfig())
	defer s.Close()

	// Write data into server.
	var buf bytes.Buffer
	for i := 0; i < pointN; i++ {
		fmt.Fprintf(&buf, `cpu value=100 %d`, i+1)
		if i != pointN-1 {
			fmt.Fprint(&buf, "\n")
		}
	}
	s.MustWrite("db0", "rp0", buf.String(), nil)

	// Query simple count from server.
	b.ResetTimer()
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		if results, err := s.Query(`SELECT count(value) FROM db0.rp0.cpu`); err != nil {
			b.Fatal(err)
		} else if results != fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["1970-01-01T00:00:00Z",%d]]}]}]}`, pointN) {
			b.Fatalf("unexpected result: %s", results)
		}
	}
}

func BenchmarkServer_ShowSeries_1(b *testing.B) {
	benchmarkServerShowSeries(b, 1)
}

func BenchmarkServer_ShowSeries_1K(b *testing.B) {
	benchmarkServerShowSeries(b, 1000)
}

func BenchmarkServer_ShowSeries_100K(b *testing.B) {
	benchmarkServerShowSeries(b, 100000)
}

func BenchmarkServer_ShowSeries_1M(b *testing.B) {
	benchmarkServerShowSeries(b, 1000000)
}

func benchmarkServerShowSeries(b *testing.B, pointN int) {
	s := OpenDefaultServer(NewConfig())
	defer s.Close()

	// Write data into server.
	var buf bytes.Buffer
	for i := 0; i < pointN; i++ {
		fmt.Fprintf(&buf, `cpu,host=server%d value=100 %d`, i, i+1)
		if i != pointN-1 {
			fmt.Fprint(&buf, "\n")
		}
	}
	s.MustWrite("db0", "rp0", buf.String(), nil)

	// Query simple count from server.
	b.ResetTimer()
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		if _, err := s.QueryWithParams(`SHOW SERIES`, url.Values{"db": {"db0"}}); err != nil {
			b.Fatal(err)
		}
	}
}