forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark.go
77 lines (64 loc) · 1.78 KB
/
benchmark.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
package victoriametrics
import (
"bufio"
"bytes"
"errors"
"github.com/blagojts/viper"
"github.com/benchant/tsbs/load"
"github.com/benchant/tsbs/pkg/data/source"
"github.com/benchant/tsbs/pkg/targets"
"sync"
)
type SpecificConfig struct {
ServerURLs []string `yaml:"urls" mapstructure:"urls"`
}
func parseSpecificConfig(v *viper.Viper) (*SpecificConfig, error) {
var conf SpecificConfig
if err := v.Unmarshal(&conf); err != nil {
return nil, err
}
return &conf, nil
}
// loader.Benchmark interface implementation
type benchmark struct {
serverURLs []string
dataSource targets.DataSource
}
func NewBenchmark(vmSpecificConfig *SpecificConfig, dataSourceConfig *source.DataSourceConfig) (targets.Benchmark, error) {
if dataSourceConfig.Type != source.FileDataSourceType {
return nil, errors.New("only FILE data source type is supported for VictoriaMetrics")
}
br := load.GetBufferedReader(dataSourceConfig.File.Location)
return &benchmark{
dataSource: &fileDataSource{
scanner: bufio.NewScanner(br),
},
serverURLs: vmSpecificConfig.ServerURLs,
}, nil
}
func (b *benchmark) GetDataSource() targets.DataSource {
return b.dataSource
}
func (b *benchmark) GetBatchFactory() targets.BatchFactory {
bufPool := sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(make([]byte, 0, 16*1024*1024))
},
}
return &factory{bufPool: &bufPool}
}
func (b *benchmark) GetPointIndexer(maxPartitions uint) targets.PointIndexer {
return &targets.ConstantIndexer{}
}
func (b *benchmark) GetProcessor() targets.Processor {
return &processor{vmURLs: b.serverURLs}
}
func (b *benchmark) GetDBCreator() targets.DBCreator {
return &dbCreator{}
}
type factory struct {
bufPool *sync.Pool
}
func (f *factory) New() targets.Batch {
return &batch{buf: f.bufPool.Get().(*bytes.Buffer)}
}