pool

package
v0.0.0-...-b8a1a0e Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const INIT_FULL_POOL_SIZE = OptionInitFullPoolSize(256)
View Source
const OPTIMAL_BLOCK_SIZE = 1 << 16
View Source
const POOL_SIZE_PER_CPU = OptionPoolSizePerCPU(256)

Variables

This section is empty.

Functions

func SetCounterRegisterCallback

func SetCounterRegisterCallback(callback CounterRegisterCallback)

Types

type Counter

type Counter struct {
	Name             string
	ObjectSize       uint64
	PoolSizePerCPU   uint32
	InitFullPoolSize uint32

	InUseObjects uint64 `statsd:"in_use_objects,gauge"`
	InUseBytes   uint64 `statsd:"in_use_bytes,gauge"`
	// contains filtered or unexported fields
}

func (*Counter) Closed

func (c *Counter) Closed() bool

func (*Counter) GetCounter

func (c *Counter) GetCounter() interface{}

type CounterRegisterCallback

type CounterRegisterCallback func(*Counter)

此Callback可用于为Counter添加statsd监控

type LockFreePool

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

sync.Pool对于每一个系统线程,能够无锁提取存放一个元素, 其余元素会通过锁追加到数组中。为了能够尽可能避免锁的使用, 我们需要利用好这一个元素的位置,所以在这个元素上放置slice指针 作为实际的pool使用,每次Get/Put时,先拿到slice,弹出/推入元素后再 将slice放回,以尽可能无锁分配释放资源

func NewLockFreePool

func NewLockFreePool(alloc func() interface{}, options ...Option) *LockFreePool

注意OptionInitFullPoolSize不能大于OptionPoolSizePerCPU,且不能小于等于0

func (*LockFreePool) Get

func (p *LockFreePool) Get() interface{}

func (*LockFreePool) Put

func (p *LockFreePool) Put(x interface{})

type Option

type Option = interface{}

type OptionCounterNameSuffix

type OptionCounterNameSuffix string

type OptionInitFullPoolSize

type OptionInitFullPoolSize int // 太大会导致Get操作卡顿,太小会导致创建过多的slice

type OptionPoolSizePerCPU

type OptionPoolSizePerCPU int

type ReferenceCount

type ReferenceCount int32

func (*ReferenceCount) AddReferenceCount

func (r *ReferenceCount) AddReferenceCount()

func (*ReferenceCount) AddReferenceCountN

func (r *ReferenceCount) AddReferenceCountN(n int32)

func (*ReferenceCount) GetReferenceCount

func (r *ReferenceCount) GetReferenceCount() int32

func (*ReferenceCount) Reset

func (r *ReferenceCount) Reset()

func (*ReferenceCount) SubReferenceCount

func (r *ReferenceCount) SubReferenceCount() bool

Jump to

Keyboard shortcuts

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