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:
Aliaksandr Valialkin 2024-02-22 17:37:43 +02:00
parent bf07e2ac87
commit 3f9022bc08
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 5 additions and 31 deletions

View file

@ -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)
}
tb.flushBlocksToInmemoryParts(ibsToFlush, false)
return tailItems
}

View file

@ -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