Module sbroker_fair_queue

Implements a fair queue containing multiple sbroker_queue queues.

Behaviours: sbroker_queue.

This module defines the sbroker_fair_queue behaviour.
Required callback functions: handle_fq_out/2.

References

Description

Implements a fair queue containing multiple sbroker_queue queues.

Its argument is of the form:
  {Module :: module(), Args :: any(), Index :: index()}

Module and Args are the module and arguments of the underlying sbroker_queue. Module must implement the sbroker_fair_queue behaviour.

Index is the method of choosing the queue to store a request in. To use the application of the sender: application. If the application can not be determined uses undefined. To use the node of the sender: node. To use the pid of the sender: pid. To use the value of the request: value. To use the Nth element of a tuple value: {element, N}. If the value is not a tuple of at least size N uses undefined.

One queue is used per key and so the number of possible keys should be bounded. If the underlying queue limits the size of its queue this only applies to the queue for that key. Requests with a different key will be in a different queue and be part of a separate limit. To limit the number of queues by hashing the key: {hash, Index2, Range}, where Index2 is any index() except another hash and Range is the number of queues, from 1 to 2^32.

Queues are chosen using a simple round robin strategy. Request are dequeued and empty queues removed using the handle_fq_out/2 callback, instead of the usual handle_out/2:
  -callback handle_fq_out(Time :: integer(), State :: any()) ->
      {SendTime :: integer(), From :: {Sender :: pid(), Tag :: any()},
       Value:: any(), Ref :: reference, NState :: any(),
       TimeoutTime :: integer() | infinity} |
      {empty, NState :: any(), RemoveTime :: integer() | infinity}.
The variables are equivalent to those of the sbroker_queue callback handle_out/2 with the addition of RemoveTime, which is the time (or infinity for never) to remove the empty queue from the fair queue for that index.

Data Types

index()

index() = key() | {hash, key(), 1..4294967296}

key()

key() = application | node | pid | value | {element, pos_integer()}


Generated by EDoc, Sep 29 2016, 17:17:28.