app/vmselect/netstorage: limit the maximum brsPool size to 32Kb at ProcessSearchQuery()

This avoids slow path in Go runtime for allocating objects bigger than 32Kb -
see 704401ffa0/src/runtime/malloc.go (L11)

This also reduces memory usage a bit for vmselect and single-node VictoriaMetrics
after the commit 5dd37ad836 .

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5527
This commit is contained in:
Aliaksandr Valialkin 2024-01-23 14:04:45 +02:00
parent fe4ea30a79
commit cfc1193d15
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB

View File

@ -1425,6 +1425,12 @@ func (tbfw *tmpBlocksFileWrapper) RegisterAndWriteBlock(mb *storage.MetricBlock,
addrs := &tbfwLocal.addrssPool[addrsIdx]
addrsPool := tbfwLocal.addrsPool
if uintptr(cap(addrsPool)) >= maxFastAllocBlockSize/unsafe.Sizeof(tmpBlockAddr{}) && len(addrsPool) == cap(addrsPool) {
// Allocate a new addrsPool in order to avoid slow allocation of an object
// bigger than maxFastAllocBlockSize bytes at append() below.
addrsPool = make([]tmpBlockAddr, 0, maxFastAllocBlockSize/unsafe.Sizeof(tmpBlockAddr{}))
tbfwLocal.addrsPool = addrsPool
}
if addrs.addrs == nil || haveSameBlockAddrTails(addrs.addrs, addrsPool) {
// It is safe appending addr to addrsPool, since there are no other items added there yet.
addrsPool = append(addrsPool, addr)