wfq

package module
v0.0.0-...-623b093 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2014 License: Apache-2.0 Imports: 2 Imported by: 0

README

Weighted Fair Queue

This go package provides a queue that implements a weighted fair queue algorithm.

See the package documentation for details: [http://godoc.org/github.com/tadglines/wfq]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Key returns the identity of the flow for the item.
	// All items with the same key are placed in the same flow.
	//
	Key(item interface{}) uint64

	// Size returns the size of the item.
	// The value returned can be any unit but all items in a queue must be
	// sized according to the same unit (e.g. bytes).
	Size(item interface{}) uint64

	// The weight/priority of the item. A higher value represents a higher
	// priority. All items with a specific key should (but are not required to)
	// have the same weight. Internally the Queue add 1 to the weight so that
	// weight range is shifted from 0-255 to 1-256.
	Weight(item interface{}) uint8
}

An implementation of this interface is passed to NewQueue and used to obtain properties of items passed to Queue(). Each method will be called only once per Queue()/item call

type Queue

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

A queue that implements a version of the weighted fair queue algorithm. When all items have the same weight then each flow's throughput will be <total throughput>/<number of flows>.

If items have different weights, then all flows with the same weight will share their portion of the throughput evenly. Each weight "class" receives a portion of the total throughput according to the following the formula RWi/W1 + W2 ... + WN where R = total throughput and W1 through WN are the weights of the individual flows. If the total size of all items that passed through the queue was 10,000, and the weights of each of 3 flows was 1, 4 and 18, then the portion of the total that was dedicated to each flow would be 10000*1/(1+4+18) = 435 (4.35%), 10000*4/(1+4+18) = 1739 (17.39%) and 10000*18/(1+4+18) = 7826 (78.26%).

func NewQueue

func NewQueue(maxQueueSize, maxFlowSize uint64, helper Interface) *Queue

Create a new Queue instance. If maxFlowSize > maxQueueSize or if helper is nil then it will panic. The maxFlowSize value limits the total size of all items that can be queued in a single flow. The maxQueueSize value limits the total size of all items that can be in the queue. It is recomeneded that maxQueueSize be set to maxFlowSize*<Max # of expected flows>, and that maxFlowSize be at least twice the largest expected item size.

func (*Queue) Close

func (q *Queue) Close()

func (*Queue) DeQueue

func (q *Queue) DeQueue() (interface{}, bool)

DeQueue removes the next item from the queue. DeQueue will not return (i.e. block) until an item can be returned or the queue is empty and closed. DeQueue will return an item and true if an item could be removed from the queue or nil and false, if the queue is empty and closed. DeQueue is safe for concurrent use.

func (*Queue) Queue

func (q *Queue) Queue(item interface{}) bool

Place on item on the queue. Queue will not return (i.e. block) until the item can be placed on the queue or the queue was closed. If Queue returns true, then DeQueue will eventually return the item. If Queue returns false, then the item was not placed on the queue because the queue has been closed. Queue will panic if the size of the item is greater then maxFlowSize (set in NewQueue). Queue is safe for concurrent use.

Jump to

Keyboard shortcuts

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