mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/netstorage: remove superflouos map lookup at ProcessSearchQuery
This should reduce CPU usage a bit during querying
This commit is contained in:
parent
eb784ff399
commit
61736e4a1d
1 changed files with 17 additions and 10 deletions
|
@ -1125,19 +1125,23 @@ func SeriesCount(qt *querytracer.Tracer, accountID, projectID uint32, denyPartia
|
|||
|
||||
type tmpBlocksFileWrapper struct {
|
||||
tbfs []*tmpBlocksFile
|
||||
ms []map[string][]tmpBlockAddr
|
||||
ms []map[string]*blockAddrs
|
||||
orderedMetricNamess [][]string
|
||||
}
|
||||
|
||||
type blockAddrs struct {
|
||||
addrs []tmpBlockAddr
|
||||
}
|
||||
|
||||
func newTmpBlocksFileWrapper(sns []*storageNode) *tmpBlocksFileWrapper {
|
||||
n := len(sns)
|
||||
tbfs := make([]*tmpBlocksFile, n)
|
||||
for i := range tbfs {
|
||||
tbfs[i] = getTmpBlocksFile()
|
||||
}
|
||||
ms := make([]map[string][]tmpBlockAddr, n)
|
||||
ms := make([]map[string]*blockAddrs, n)
|
||||
for i := range ms {
|
||||
ms[i] = make(map[string][]tmpBlockAddr)
|
||||
ms[i] = make(map[string]*blockAddrs)
|
||||
}
|
||||
return &tmpBlocksFileWrapper{
|
||||
tbfs: tbfs,
|
||||
|
@ -1157,10 +1161,11 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
|
|||
metricName := mb.MetricName
|
||||
m := tbfw.ms[workerID]
|
||||
addrs := m[string(metricName)]
|
||||
addrs = append(addrs, addr)
|
||||
if len(addrs) > 1 {
|
||||
m[string(metricName)] = addrs
|
||||
} else {
|
||||
if addrs == nil {
|
||||
addrs = &blockAddrs{}
|
||||
}
|
||||
addrs.addrs = append(addrs.addrs, addr)
|
||||
if len(addrs.addrs) == 1 {
|
||||
// An optimization for big number of time series with long names: store only a single copy of metricNameStr
|
||||
// in both tbfw.orderedMetricNamess and tbfw.ms.
|
||||
orderedMetricNames := tbfw.orderedMetricNamess[workerID]
|
||||
|
@ -1172,7 +1177,7 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (tbfw *tmpBlocksFileWrapper) Finalize() ([]string, map[string][]tmpBlockAddr, uint64, error) {
|
||||
func (tbfw *tmpBlocksFileWrapper) Finalize() ([]string, map[string]*blockAddrs, uint64, error) {
|
||||
var bytesTotal uint64
|
||||
for i, tbf := range tbfw.tbfs {
|
||||
if err := tbf.Finalize(); err != nil {
|
||||
|
@ -1188,8 +1193,10 @@ func (tbfw *tmpBlocksFileWrapper) Finalize() ([]string, map[string][]tmpBlockAdd
|
|||
dstAddrs, ok := addrsByMetricName[metricName]
|
||||
if !ok {
|
||||
orderedMetricNames = append(orderedMetricNames, metricName)
|
||||
dstAddrs := &blockAddrs{}
|
||||
addrsByMetricName[metricName] = dstAddrs
|
||||
}
|
||||
addrsByMetricName[metricName] = append(dstAddrs, m[metricName]...)
|
||||
dstAddrs.addrs = append(dstAddrs.addrs, m[metricName].addrs...)
|
||||
}
|
||||
}
|
||||
return orderedMetricNames, addrsByMetricName, bytesTotal, nil
|
||||
|
@ -1349,7 +1356,7 @@ func ProcessSearchQuery(qt *querytracer.Tracer, denyPartialResponse bool, sq *st
|
|||
for i, metricName := range orderedMetricNames {
|
||||
pts[i] = packedTimeseries{
|
||||
metricName: metricName,
|
||||
addrs: addrsByMetricName[metricName],
|
||||
addrs: addrsByMetricName[metricName].addrs,
|
||||
}
|
||||
}
|
||||
rss.packedTimeseries = pts
|
||||
|
|
Loading…
Reference in a new issue