mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/mergeset: remove a pool for inmemoryBlock structs
The pool for inmemoryBlock struct doesn't give any performance gains in production workloads, while it may result in excess memory usage for inmemoryBlock structs inside the pool during background merge of indexdb.
This commit is contained in:
parent
60341722d5
commit
793fe39921
3 changed files with 7 additions and 19 deletions
|
@ -540,17 +540,6 @@ func putLensBuffer(lb *lensBuffer) {
|
||||||
lensBufferPool.Put(lb)
|
lensBufferPool.Put(lb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInmemoryBlock() *inmemoryBlock {
|
func newInmemoryBlock() *inmemoryBlock {
|
||||||
v := ibPool.Get()
|
return &inmemoryBlock{}
|
||||||
if v == nil {
|
|
||||||
return &inmemoryBlock{}
|
|
||||||
}
|
|
||||||
return v.(*inmemoryBlock)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func putInmemoryBlock(ib *inmemoryBlock) {
|
|
||||||
ib.Reset()
|
|
||||||
ibPool.Put(ib)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ibPool sync.Pool
|
|
||||||
|
|
|
@ -316,7 +316,7 @@ func (ps *partSearch) readInmemoryBlock(bh *blockHeader) (*inmemoryBlock, error)
|
||||||
ps.sb.lensData = bytesutil.Resize(ps.sb.lensData, int(bh.lensBlockSize))
|
ps.sb.lensData = bytesutil.Resize(ps.sb.lensData, int(bh.lensBlockSize))
|
||||||
ps.p.lensFile.MustReadAt(ps.sb.lensData, int64(bh.lensBlockOffset))
|
ps.p.lensFile.MustReadAt(ps.sb.lensData, int64(bh.lensBlockOffset))
|
||||||
|
|
||||||
ib := getInmemoryBlock()
|
ib := newInmemoryBlock()
|
||||||
if err := ib.UnmarshalData(&ps.sb, bh.firstItem, bh.commonPrefix, bh.itemsCount, bh.marshalType); err != nil {
|
if err := ib.UnmarshalData(&ps.sb, bh.firstItem, bh.commonPrefix, bh.itemsCount, bh.marshalType); err != nil {
|
||||||
return nil, fmt.Errorf("cannot unmarshal storage block with %d items: %w", bh.itemsCount, err)
|
return nil, fmt.Errorf("cannot unmarshal storage block with %d items: %w", bh.itemsCount, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,16 +182,15 @@ func (ris *rawItemsShard) addItems(tb *Table, items [][]byte) error {
|
||||||
ris.mu.Lock()
|
ris.mu.Lock()
|
||||||
ibs := ris.ibs
|
ibs := ris.ibs
|
||||||
if len(ibs) == 0 {
|
if len(ibs) == 0 {
|
||||||
ib := getInmemoryBlock()
|
ib := newInmemoryBlock()
|
||||||
ibs = append(ibs, ib)
|
ibs = append(ibs, ib)
|
||||||
ris.ibs = ibs
|
ris.ibs = ibs
|
||||||
}
|
}
|
||||||
ib := ibs[len(ibs)-1]
|
ib := ibs[len(ibs)-1]
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if !ib.Add(item) {
|
if !ib.Add(item) {
|
||||||
ib = getInmemoryBlock()
|
ib = newInmemoryBlock()
|
||||||
if !ib.Add(item) {
|
if !ib.Add(item) {
|
||||||
putInmemoryBlock(ib)
|
|
||||||
err = fmt.Errorf("cannot insert an item %q into an empty inmemoryBlock; it looks like the item is too large? len(item)=%d", item, len(item))
|
err = fmt.Errorf("cannot insert an item %q into an empty inmemoryBlock; it looks like the item is too large? len(item)=%d", item, len(item))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -675,13 +674,13 @@ func (tb *Table) mergeRawItemsBlocks(blocksToMerge []*inmemoryBlock) {
|
||||||
func (tb *Table) mergeInmemoryBlocks(blocksToMerge []*inmemoryBlock) *partWrapper {
|
func (tb *Table) mergeInmemoryBlocks(blocksToMerge []*inmemoryBlock) *partWrapper {
|
||||||
// Convert blocksToMerge into inmemoryPart's
|
// Convert blocksToMerge into inmemoryPart's
|
||||||
mps := make([]*inmemoryPart, 0, len(blocksToMerge))
|
mps := make([]*inmemoryPart, 0, len(blocksToMerge))
|
||||||
for _, ib := range blocksToMerge {
|
for i, ib := range blocksToMerge {
|
||||||
if len(ib.items) == 0 {
|
if len(ib.items) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mp := getInmemoryPart()
|
mp := getInmemoryPart()
|
||||||
mp.Init(ib)
|
mp.Init(ib)
|
||||||
putInmemoryBlock(ib)
|
blocksToMerge[i] = nil
|
||||||
mps = append(mps, mp)
|
mps = append(mps, mp)
|
||||||
}
|
}
|
||||||
if len(mps) == 0 {
|
if len(mps) == 0 {
|
||||||
|
|
Loading…
Reference in a new issue