mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
app/vmselect/netstorage: pre-allocate 4 block references per each time series during querying
Usually the number of blocks returned per each time series during queries is around 4. So it is a good idea to pre-allocate 4 block references per time series in order to reduce the number of memory allocations.
This commit is contained in:
parent
2483c67579
commit
abbac2c27c
1 changed files with 10 additions and 3 deletions
|
@ -1233,7 +1233,14 @@ type tmpBlocksFileWrapper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type blockAddrs struct {
|
type blockAddrs struct {
|
||||||
addrs []tmpBlockAddr
|
addrsPrealloc [4]tmpBlockAddr
|
||||||
|
addrs []tmpBlockAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBlockAddrs() *blockAddrs {
|
||||||
|
ba := &blockAddrs{}
|
||||||
|
ba.addrs = ba.addrsPrealloc[:0]
|
||||||
|
return ba
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTmpBlocksFileWrapper(sns []*storageNode) *tmpBlocksFileWrapper {
|
func newTmpBlocksFileWrapper(sns []*storageNode) *tmpBlocksFileWrapper {
|
||||||
|
@ -1265,7 +1272,7 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
|
||||||
m := tbfw.ms[workerID]
|
m := tbfw.ms[workerID]
|
||||||
addrs := m[metricName]
|
addrs := m[metricName]
|
||||||
if addrs == nil {
|
if addrs == nil {
|
||||||
addrs = &blockAddrs{}
|
addrs = newBlockAddrs()
|
||||||
}
|
}
|
||||||
addrs.addrs = append(addrs.addrs, addr)
|
addrs.addrs = append(addrs.addrs, addr)
|
||||||
if len(addrs.addrs) == 1 {
|
if len(addrs.addrs) == 1 {
|
||||||
|
@ -1295,7 +1302,7 @@ func (tbfw *tmpBlocksFileWrapper) Finalize() ([]string, map[string]*blockAddrs,
|
||||||
dstAddrs, ok := addrsByMetricName[metricName]
|
dstAddrs, ok := addrsByMetricName[metricName]
|
||||||
if !ok {
|
if !ok {
|
||||||
orderedMetricNames = append(orderedMetricNames, metricName)
|
orderedMetricNames = append(orderedMetricNames, metricName)
|
||||||
dstAddrs = &blockAddrs{}
|
dstAddrs = newBlockAddrs()
|
||||||
addrsByMetricName[metricName] = dstAddrs
|
addrsByMetricName[metricName] = dstAddrs
|
||||||
}
|
}
|
||||||
dstAddrs.addrs = append(dstAddrs.addrs, m[metricName].addrs...)
|
dstAddrs.addrs = append(dstAddrs.addrs, m[metricName].addrs...)
|
||||||
|
|
Loading…
Reference in a new issue