mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/promql: intern output series names inside timeseriesToResult()
This reduces the number of memory allocations for repeated queries, which return (almost) the same set of time series.
This commit is contained in:
parent
562d6bca08
commit
4f0c11ee93
1 changed files with 4 additions and 2 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/querystats"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/querystats"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
||||||
|
@ -121,10 +122,11 @@ func timeseriesToResult(tss []*timeseries, maySort bool) ([]netstorage.Result, e
|
||||||
bb := bbPool.Get()
|
bb := bbPool.Get()
|
||||||
for i, ts := range tss {
|
for i, ts := range tss {
|
||||||
bb.B = marshalMetricNameSorted(bb.B[:0], &ts.MetricName)
|
bb.B = marshalMetricNameSorted(bb.B[:0], &ts.MetricName)
|
||||||
if _, ok := m[string(bb.B)]; ok {
|
k := bytesutil.InternBytes(bb.B)
|
||||||
|
if _, ok := m[k]; ok {
|
||||||
return nil, fmt.Errorf(`duplicate output timeseries: %s`, stringMetricName(&ts.MetricName))
|
return nil, fmt.Errorf(`duplicate output timeseries: %s`, stringMetricName(&ts.MetricName))
|
||||||
}
|
}
|
||||||
m[string(bb.B)] = struct{}{}
|
m[k] = struct{}{}
|
||||||
|
|
||||||
rs := &result[i]
|
rs := &result[i]
|
||||||
rs.MetricName.CopyFrom(&ts.MetricName)
|
rs.MetricName.CopyFrom(&ts.MetricName)
|
||||||
|
|
Loading…
Reference in a new issue