mempool

package
v3.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator interface {
	Get(size int) ([]byte, error)
	Put([]byte) bool
}

Allocator handles byte slices for bloom queriers. It exists to reduce the cost of allocations and allows to re-use already allocated memory.

type Bucket

type Bucket struct {
	Size     int    // Number of buffers
	Capacity uint64 // Size of a buffer
}

func (Bucket) Parse

func (b Bucket) Parse(s string) (any, error)

func (Bucket) String

func (b Bucket) String() string

type Buckets

type Buckets []Bucket

func (Buckets) String

func (b Buckets) String() string

type BytePool

type BytePool struct {
	// contains filtered or unexported fields
}

BytePool uses a sync.Pool to re-cycle already allocated buffers.

func NewBytePoolAllocator

func NewBytePoolAllocator(minSize, maxSize int, factor float64) *BytePool

func (*BytePool) Get

func (p *BytePool) Get(size int) ([]byte, error)

Get implements Allocator

func (*BytePool) Put

func (p *BytePool) Put(b []byte) bool

Put implements Allocator

type MemPool

type MemPool struct {
	// contains filtered or unexported fields
}

MemPool is an Allocator implementation that uses a fixed size memory pool that is split into multiple slabs of different buffer sizes. Buffers are re-cycled and need to be returned back to the pool, otherwise the pool runs out of available buffers.

func New

func New(name string, buckets []Bucket, r prometheus.Registerer) *MemPool

func (*MemPool) Get

func (a *MemPool) Get(size int) ([]byte, error)

Get satisfies Allocator interface Allocating a buffer from an exhausted pool/slab, or allocating a buffer that exceeds the largest slab size will return an error.

func (*MemPool) Put

func (a *MemPool) Put(buffer []byte) bool

Put satisfies Allocator interface Every buffer allocated with Get(size int) needs to be returned to the pool using Put(buffer []byte) so it can be re-cycled.

type SimpleHeapAllocator

type SimpleHeapAllocator struct{}

SimpleHeapAllocator allocates a new byte slice every time and does not re-cycle buffers.

func (*SimpleHeapAllocator) Get

func (a *SimpleHeapAllocator) Get(size int) ([]byte, error)

func (*SimpleHeapAllocator) Put

func (a *SimpleHeapAllocator) Put([]byte) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL