mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
app/vmselect: reduce memory usage when querying big number of time series with long labels
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/646
This commit is contained in:
parent
9257eee982
commit
34563916f7
1 changed files with 10 additions and 3 deletions
|
@ -572,10 +572,17 @@ func ProcessSearchQuery(sq *storage.SearchQuery, fetchData bool, deadline Deadli
|
||||||
}
|
}
|
||||||
metricName := sr.MetricBlockRef.MetricName
|
metricName := sr.MetricBlockRef.MetricName
|
||||||
brs := m[string(metricName)]
|
brs := m[string(metricName)]
|
||||||
if len(brs) == 0 {
|
brs = append(brs, *sr.MetricBlockRef.BlockRef)
|
||||||
orderedMetricNames = append(orderedMetricNames, string(metricName))
|
if len(brs) > 0 {
|
||||||
|
// An optimization: do not allocate a string for already existing metricName key in m
|
||||||
|
m[string(metricName)] = brs
|
||||||
|
} else {
|
||||||
|
// An optimization for big number of time series with long metricName values:
|
||||||
|
// use only a single copy of metricName for both orderedMetricNames and m.
|
||||||
|
metricNameStr := string(metricName)
|
||||||
|
orderedMetricNames = append(orderedMetricNames, metricNameStr)
|
||||||
|
m[metricNameStr] = brs
|
||||||
}
|
}
|
||||||
m[string(metricName)] = append(brs, *sr.MetricBlockRef.BlockRef)
|
|
||||||
}
|
}
|
||||||
if err := sr.Error(); err != nil {
|
if err := sr.Error(); err != nil {
|
||||||
return nil, fmt.Errorf("search error after reading %d data blocks: %w", blocksRead, err)
|
return nil, fmt.Errorf("search error after reading %d data blocks: %w", blocksRead, err)
|
||||||
|
|
Loading…
Reference in a new issue