queue

package module
v0.0.0-...-66c6898 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentQueue

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

ConcurrentQueue is a concurrent-safe FIFO queue with unbounded capacity. Clients interact with the queue by pushing items into the in channel and popping items from the out channel. There is a goroutine that manages moving items from the in channel to the out channel in the correct order that must be started by calling Start().

func NewConcurrentQueue

func NewConcurrentQueue(bufferSize int) *ConcurrentQueue

NewConcurrentQueue constructs a ConcurrentQueue. The bufferSize parameter is the capacity of the output channel. When the size of the queue is below this threshold, pushes do not incur the overhead of the less efficient overflow structure.

func (*ConcurrentQueue) ChanIn

func (cq *ConcurrentQueue) ChanIn() chan<- interface{}

ChanIn returns a channel that can be used to push new items into the queue.

func (*ConcurrentQueue) ChanOut

func (cq *ConcurrentQueue) ChanOut() <-chan interface{}

ChanOut returns a channel that can be used to pop items from the queue.

func (*ConcurrentQueue) Start

func (cq *ConcurrentQueue) Start()

Start begins a goroutine that manages moving items from the in channel to the out channel. The queue tries to move items directly to the out channel minimize overhead, but if the out channel is full it pushes items to an overflow queue. This must be called before using the queue.

func (*ConcurrentQueue) Stop

func (cq *ConcurrentQueue) Stop()

Stop ends the goroutine that moves items from the in channel to the out channel. This does not clear the queue state, so the queue can be restarted without dropping items.

type GCQueue

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

GCQueue is garbage collecting queue, which dynamically grows and contracts based on load. If the queue has items which have been returned, the queue will check every gcInterval amount of time to see if any elements are eligible to be released back to the runtime. Elements that have been in the queue for a duration of least expiryInterval will be released upon the next iteration of the garbage collection, thus the maximum amount of time an element remain in the queue is expiryInterval+gcInterval. The gc ticker will be disabled after all items in the queue have been taken or released to ensure that the GCQueue becomes quiescent, and imposes minimal overhead in the steady state.

func NewGCQueue

func NewGCQueue(newItem func() interface{}, returnQueueSize int,
	gcInterval, expiryInterval time.Duration) *GCQueue

NewGCQueue creates a new garbage collecting queue, which dynamically grows and contracts based on load. If the queue has items which have been returned, the queue will check every gcInterval amount of time to see if any elements are eligible to be released back to the runtime. Elements that have been in the queue for a duration of least expiryInterval will be released upon the next iteration of the garbage collection, thus the maximum amount of time an element remain in the queue is expiryInterval+gcInterval. The gc ticker will be disabled after all items in the queue have been taken or released to ensure that the GCQueue becomes quiescent, and imposes minimal overhead in the steady state. The returnQueueSize parameter is used to size the maximal number of items that can be returned without being dropped during large bursts in attempts to return items to the GCQUeue.

func (*GCQueue) Return

func (q *GCQueue) Return(item interface{})

Return adds the returned item to freelist if the queue's returnBuffer has available capacity. Under load, items may be dropped to ensure this method does not block.

func (*GCQueue) Take

func (q *GCQueue) Take() interface{}

Take returns either a recycled element from the queue, or creates a new item if none are available.

Jump to

Keyboard shortcuts

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