mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/{storage,mergeset}: do not create index blocks with sizes exceeding 64Kb in common case
This should reduce memory fragmentation and memory usage for indexdb/indexBlocks and storage/indexBlocks caches
This commit is contained in:
parent
1c3eac5c1e
commit
950b126a09
2 changed files with 11 additions and 5 deletions
|
@ -148,12 +148,15 @@ func (bsw *blockStreamWriter) WriteBlock(ib *inmemoryBlock) {
|
|||
bsw.lensBlockOffset += uint64(bsw.bh.lensBlockSize)
|
||||
|
||||
// Write blockHeader
|
||||
unpackedIndexBlockBufLen := len(bsw.unpackedIndexBlockBuf)
|
||||
bsw.unpackedIndexBlockBuf = bsw.bh.Marshal(bsw.unpackedIndexBlockBuf)
|
||||
if len(bsw.unpackedIndexBlockBuf) > maxIndexBlockSize {
|
||||
bsw.unpackedIndexBlockBuf = bsw.unpackedIndexBlockBuf[:unpackedIndexBlockBufLen]
|
||||
bsw.flushIndexData()
|
||||
bsw.unpackedIndexBlockBuf = bsw.bh.Marshal(bsw.unpackedIndexBlockBuf)
|
||||
}
|
||||
bsw.bh.Reset()
|
||||
bsw.mr.blockHeadersCount++
|
||||
if len(bsw.unpackedIndexBlockBuf) >= maxIndexBlockSize {
|
||||
bsw.flushIndexData()
|
||||
}
|
||||
}
|
||||
|
||||
// The maximum size of index block with multiple blockHeaders.
|
||||
|
|
|
@ -143,11 +143,14 @@ func (bsw *blockStreamWriter) WriteExternalBlock(b *Block, ph *partHeader, rowsM
|
|||
atomic.AddUint64(×tampsBlocksMerged, 1)
|
||||
atomic.AddUint64(×tampsBytesSaved, uint64(len(timestampsData)))
|
||||
}
|
||||
indexDataLen := len(bsw.indexData)
|
||||
bsw.indexData = append(bsw.indexData, headerData...)
|
||||
bsw.mr.RegisterBlockHeader(&b.bh)
|
||||
if len(bsw.indexData) >= maxBlockSize {
|
||||
if len(bsw.indexData) > maxBlockSize {
|
||||
bsw.indexData = bsw.indexData[:indexDataLen]
|
||||
bsw.flushIndexData()
|
||||
bsw.indexData = append(bsw.indexData, headerData...)
|
||||
}
|
||||
bsw.mr.RegisterBlockHeader(&b.bh)
|
||||
if !usePrevTimestamps {
|
||||
bsw.prevTimestampsData = append(bsw.prevTimestampsData[:0], timestampsData...)
|
||||
bsw.prevTimestampsBlockOffset = bsw.timestampsBlockOffset
|
||||
|
|
Loading…
Reference in a new issue