mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/netstorage: cache canonical MetricName for time series returned from the storage
This reduces memory allocations for repeated queries, which return (almost) the same set of time series.
This commit is contained in:
parent
7afcca0c51
commit
c5e0f527bc
1 changed files with 4 additions and 6 deletions
|
@ -1090,8 +1090,8 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin
|
||||||
putStorageSearch(sr)
|
putStorageSearch(sr)
|
||||||
return nil, fmt.Errorf("cannot write %d bytes to temporary file: %w", len(buf), err)
|
return nil, fmt.Errorf("cannot write %d bytes to temporary file: %w", len(buf), err)
|
||||||
}
|
}
|
||||||
metricName := sr.MetricBlockRef.MetricName
|
metricName := bytesutil.InternBytes(sr.MetricBlockRef.MetricName)
|
||||||
brs := m[string(metricName)]
|
brs := m[metricName]
|
||||||
if brs == nil {
|
if brs == nil {
|
||||||
brs = &blockRefs{}
|
brs = &blockRefs{}
|
||||||
}
|
}
|
||||||
|
@ -1100,10 +1100,8 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin
|
||||||
addr: addr,
|
addr: addr,
|
||||||
})
|
})
|
||||||
if len(brs.brs) == 1 {
|
if len(brs.brs) == 1 {
|
||||||
// An optimization for big number of time series with long metricName values:
|
orderedMetricNames = append(orderedMetricNames, metricName)
|
||||||
// use only a single copy of metricName for both orderedMetricNames and m.
|
m[metricName] = brs
|
||||||
orderedMetricNames = append(orderedMetricNames, string(metricName))
|
|
||||||
m[orderedMetricNames[len(orderedMetricNames)-1]] = brs
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := sr.Error(); err != nil {
|
if err := sr.Error(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue