Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

buffer

v1.51.4
github.com/lfch/grpc/internal/profiling/buffer

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

5 matches

Top ↑

Package buffer provides a high-performant lock free implementation of a circular buffer used by the profiling code.

Types

CircularBuffer

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

CircularBuffer is a lock-free data structure that supports Push and Drain operations.

Note that CircularBuffer is built for performance more than reliability. That is, some Push operations may fail without retries in some situations (such as during a Drain operation). Order of pushes is not maintained either; that is, if A was pushed before B, the Drain operation may return an array with B before A. These restrictions are acceptable within gRPC's profiling, but if your use-case does not permit these relaxed constraints or if performance is not a primary concern, you should probably use a lock-based data structure such as internal/buffer.UnboundedBuffer.

NewCircularBuffer

func NewCircularBuffer(size uint32) (*CircularBuffer, error)

NewCircularBuffer allocates a circular buffer of size size and returns a reference to the struct. Only circular buffers of size 2^k are allowed (saves us from having to do expensive modulo operations).

CircularBuffer.Drain

func (cb *CircularBuffer) Drain() []interface{}

Drain allocates and returns an array of things Pushed in to the circular buffer. Push order is not maintained; that is, if B was Pushed after A, drain may return B at a lower index than A in the returned array.

CircularBuffer.Push

func (cb *CircularBuffer) Push(x interface{})

Push pushes an element in to the circular buffer. Guaranteed to complete in a finite number of steps (also lock-free). Does not guarantee that push order will be retained. Does not guarantee that the operation will succeed if a Drain operation concurrently begins execution.

Dependency graph