app/vmselect: reduce memory allocations by pre-allocatin memory for time series map and for a list of time series names

This commit is contained in:
Aliaksandr Valialkin 2020-08-06 19:17:51 +03:00
parent 8e44fba76d
commit bc8381613d
2 changed files with 8 additions and 5 deletions

View file

@ -594,10 +594,10 @@ func ProcessSearchQuery(sq *storage.SearchQuery, fetchData bool, deadline Deadli
defer vmstorage.WG.Done()
sr := getStorageSearch()
sr.Init(vmstorage.Storage, tfss, tr, *maxMetricsPerSearch, deadline.deadline)
maxSeriesCount := sr.Init(vmstorage.Storage, tfss, tr, *maxMetricsPerSearch, deadline.deadline)
m := make(map[string][]storage.BlockRef)
var orderedMetricNames []string
m := make(map[string][]storage.BlockRef, maxSeriesCount)
orderedMetricNames := make([]string, 0, maxSeriesCount)
blocksRead := 0
for sr.NextMetricBlock() {
blocksRead++

View file

@ -90,7 +90,9 @@ func (s *Search) reset() {
// Init initializes s from the given storage, tfss and tr.
//
// MustClose must be called when the search is done.
func (s *Search) Init(storage *Storage, tfss []*TagFilters, tr TimeRange, maxMetrics int, deadline uint64) {
//
// Init returns the upper bound on the number of found time series.
func (s *Search) Init(storage *Storage, tfss []*TagFilters, tr TimeRange, maxMetrics int, deadline uint64) int {
if s.needClosing {
logger.Panicf("BUG: missing MustClose call before the next call to Init")
}
@ -110,10 +112,11 @@ func (s *Search) Init(storage *Storage, tfss []*TagFilters, tr TimeRange, maxMet
if err != nil {
s.err = err
return
return 0
}
s.storage = storage
return len(tsids)
}
// MustClose closes the Search.