mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
lib/storage: do not pool rawRowsBlock when flushing rawRows to in-memory blocks
The pooled rawRowsBlock objects occupies big amounts of memory between flushes, and the flushes are relatively rare. So it is better to don't use the pool and to allocate rawRow blocks on demand. This should reduce the average memory usage between flushes.
This commit is contained in:
parent
b7dfe9894c
commit
aec9cd4316
@ -255,9 +255,7 @@ func (ris *rawItemsShard) addItems(tb *Table, items [][]byte) [][]byte {
|
||||
ris.ibs = ibs
|
||||
ris.mu.Unlock()
|
||||
|
||||
if len(ibsToFlush) > 0 {
|
||||
tb.flushBlocksToInmemoryParts(ibsToFlush, false)
|
||||
}
|
||||
|
||||
return tailItems
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ func (rrs *rawRowsShard) Len() int {
|
||||
}
|
||||
|
||||
func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) []rawRow {
|
||||
var rrb *rawRowsBlock
|
||||
var rowsToFlush []rawRow
|
||||
|
||||
rrs.mu.Lock()
|
||||
if cap(rrs.rows) == 0 {
|
||||
@ -499,8 +499,8 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) []rawRow {
|
||||
rrs.rows = rrs.rows[:len(rrs.rows)+n]
|
||||
rows = rows[n:]
|
||||
if len(rows) > 0 {
|
||||
rrb = getRawRowsBlock()
|
||||
rrb.rows, rrs.rows = rrs.rows, rrb.rows
|
||||
rowsToFlush = rrs.rows
|
||||
rrs.rows = newRawRows()
|
||||
n = copy(rrs.rows[:cap(rrs.rows)], rows)
|
||||
rrs.rows = rrs.rows[:n]
|
||||
rows = rows[n:]
|
||||
@ -508,40 +508,16 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) []rawRow {
|
||||
}
|
||||
rrs.mu.Unlock()
|
||||
|
||||
if rrb != nil {
|
||||
pt.flushRowsToInmemoryParts(rrb.rows)
|
||||
putRawRowsBlock(rrb)
|
||||
}
|
||||
pt.flushRowsToInmemoryParts(rowsToFlush)
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
type rawRowsBlock struct {
|
||||
rows []rawRow
|
||||
}
|
||||
|
||||
func newRawRows() []rawRow {
|
||||
n := getMaxRawRowsPerShard()
|
||||
return make([]rawRow, 0, n)
|
||||
}
|
||||
|
||||
func getRawRowsBlock() *rawRowsBlock {
|
||||
v := rawRowsBlockPool.Get()
|
||||
if v == nil {
|
||||
return &rawRowsBlock{
|
||||
rows: newRawRows(),
|
||||
}
|
||||
}
|
||||
return v.(*rawRowsBlock)
|
||||
}
|
||||
|
||||
func putRawRowsBlock(rrb *rawRowsBlock) {
|
||||
rrb.rows = rrb.rows[:0]
|
||||
rawRowsBlockPool.Put(rrb)
|
||||
}
|
||||
|
||||
var rawRowsBlockPool sync.Pool
|
||||
|
||||
func (pt *partition) flushRowsToInmemoryParts(rows []rawRow) {
|
||||
if len(rows) == 0 {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user