sbroker_timeout_queue (sbroker v1.1.1)

Implements a head or tail drop queue with a timeout queue management algorithm

sbroker_timeout_queue can be used as an sbroker_queue in a sbroker or sregulator. It will provide a FIFO or LIFO queue thats drops requests that remain in the queue for longer than a timeout when the minimum size is exceeded, and drops the head or tail request from the queue when a maximum size is exceeded. Its argument, spec(), is of the form:
  #{out     => Out :: out | out_r, % default: out
    timeout => Timeout :: timeout(), % default: 5000
    drop    => Drop :: drop | drop_r, % default: drop_r
    min     => Min :: non_neg_integer(), % default: 0
    max     => Max :: non_neg_integer() | infinity} % default: infinity

Out is either out for a FIFO queue (the default) or out_r for a LIFO queue. Timeout is timeout time in milliseconds or infinity (defaults to 5000) when requests are dropped from the queue when above the minimum size Min (defaults to 0). Drop is either drop_r for tail drop (the default) where the last request is droppped, or drop for head drop, where the first request is dropped. Dropping occurs when queue is above the maximum size Max (defaults to infinity).

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.

Link to this section Summary

Link to this section Types

Specs

spec() ::
    #{out => Out :: out | out_r,
      timeout => Timeout :: timeout(),
      drop => Drop :: drop | drop_r,
      min => Min :: non_neg_integer(),
      max => Max :: non_neg_integer() | infinity}.