Module sbroker_codel_queue

Implements a head or tail drop queue with queue management based roughly on CoDel (Controlling Queue Delay), see reference.

Behaviours: sbroker_fair_queue, sbroker_queue.

References

Description

Implements a head or tail drop queue with queue management based roughly on CoDel (Controlling Queue Delay), see reference.

sbroker_codel_queue can be used as an sbroker_queue module in sbroker. Its argument is of the form:
  {out | out_r, Target :: non_neg_integer(), Interval :: pos_integer(),
   drop | drop_r, Min :: non_neg_integer(),
   Max :: non_neg_integer() | infinity}.

The first element is out for a FIFO queue and out_r for a LIFO queue. Target is the target queue sojourn time and Interval is in the initial interval between drops when the queue is above the minimum size Min. The fourth element determines whether to drop from head (drop) or drop from the tail (drop_r) when the queue is above the maximum size Max.

Initial parameters are recommended to be between the 95th and 99th percentile round trip time for the interval and the target between 5% and 10% of the interval. The round trip should be that between the actual initiator of the request (e.g. a remote client) and the queue. For example, the reference suggests an interval of 100ms and a target of 5ms when queuing TCP packets in a kernel's buffer. A TCP connection handshake is 3 way or 1.5 round trips. A request and response might be a few more round trips at the packet level even if using a single :gen_tcp.send/2.

This implementation differs from the reference as enqueue and other functions can detect a slow queue and drop items. However once a slow item has been detected only handle_out/2 can detect the queue becoming fast again with the caveat that with out_r this can only be detected if the queue reaches the minimum size Min or less, and not a fast sojourn time. This means that it is possible to drop items without calling handle_out/2 but it is not possible to stop dropping unless a handle_out/2 dequeues an item to take the queue to or below the minimum size Min or out is used and a dequeued request is below target sojourn time. Therefore if handle_out/2 is not called for an extended period the queue will converge to dropping all items above the target sojourn time if a single item has a sojourn time above target. Whereas with the reference implementation no items would be dropped.

If it is possible for the counterparty in the broker to "disappear" for a period of time then setting a Min above 0 can leave Min items in the queue for an extended period of time as requests are only dropped when the queue size is above Min. This may be undesirable for client requests because the request could wait in the queue indefinitely if there are not enough requests to take the queue above Min. However it might be desired for database connections where it is ideal for a small number of connections to be waiting to handle a client request.

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