-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
93 lines (75 loc) · 2.19 KB
/
main.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
// run_queries_influx speed tests InfluxDB using requests from stdin.
//
// It reads encoded Query objects from stdin, and makes concurrent requests
// to the provided HTTP endpoint. This program has no knowledge of the
// internals of the endpoint.
package main
import (
"fmt"
"log"
"strings"
"github.com/blagojts/viper"
"github.com/spf13/pflag"
"github.com/cnosdb/tsdb-comparisons/internal/utils"
"github.com/cnosdb/tsdb-comparisons/pkg/query"
)
// Program option vars:
var (
daemonUrls []string
chunkSize uint64
)
// Global vars:
var (
runner *query.BenchmarkRunner
)
// Parse args:
func init() {
var config query.BenchmarkRunnerConfig
config.AddToFlagSet(pflag.CommandLine)
var csvDaemonUrls string
pflag.String("urls", "http://localhost:8086", "Daemon URLs, comma-separated. Will be used in a round-robin fashion.")
pflag.Uint64("chunk-response-size", 0, "Number of series to chunk results into. 0 means no chunking.")
pflag.Parse()
err := utils.SetupConfigFile()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
if err := viper.Unmarshal(&config); err != nil {
panic(fmt.Errorf("unable to decode config: %s", err))
}
csvDaemonUrls = viper.GetString("urls")
chunkSize = viper.GetUint64("chunk-response-size")
daemonUrls = strings.Split(csvDaemonUrls, ",")
if len(daemonUrls) == 0 {
log.Fatal("missing 'urls' flag")
}
runner = query.NewBenchmarkRunner(config)
}
func main() {
runner.Run(&query.HTTPPool, newProcessor)
}
type processor struct {
w *HTTPClient
opts *HTTPClientDoOptions
}
func newProcessor() query.Processor { return &processor{} }
func (p *processor) Init(workerNumber int) {
p.opts = &HTTPClientDoOptions{
Debug: runner.DebugLevel(),
PrettyPrintResponses: runner.DoPrintResponses(),
chunkSize: chunkSize,
database: runner.DatabaseName(),
}
url := daemonUrls[workerNumber%len(daemonUrls)]
p.w = NewHTTPClient(url)
}
func (p *processor) ProcessQuery(q query.Query, _ bool) ([]*query.Stat, error) {
hq := q.(*query.HTTP)
lag, err := p.w.Do(hq, p.opts)
if err != nil {
return nil, err
}
stat := query.GetStat()
stat.Init(q.HumanLabelName(), lag)
return []*query.Stat{stat}, nil
}