grpc: google.golang.org/grpc/internal/profiling/buffer Index | Files

package buffer

import "google.golang.org/grpc/internal/profiling/buffer"

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

Index

Package Files

buffer.go

type CircularBuffer Uses

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.

func NewCircularBuffer Uses

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).

func (*CircularBuffer) Drain Uses

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.

func (*CircularBuffer) Push Uses

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.

Package buffer imports 6 packages (graph) and is imported by 2 packages. Updated 2020-02-08. Refresh now. Tools for package owners.