limiter v0.1.2 Limiter

Rate limiter implementation based on Generic Cell Rate Algorithm (GCRA).

The limiter checks if a given key exceeded a rate limit and returns the result with additional info.

For more details, see the below links:

Example usage:

Limiter.checkout({Limiter.Storage.ConCache, :storage}, "key", 10_000, 5)

Summary

Types

The key associated with an action which is rate limited

The number of actions (in case the quantity is 1) that along with the period defines the rate limit

The period of time that along with limit defines the rate limit

The weight of an action. Typically it’s set to 1. The more expensive actions may use greater value

Tuple that contains the module used for storage and options for the given storage

Storage module that implements Limiter.Storage behaviour

Options for a storage module. These options may differ for different storage implementations

Functions

Checks if an action associated with a key is allowed

Resets the value associated with the key

Types

key()
key() :: term

The key associated with an action which is rate limited.

limit()
limit() :: non_neg_integer

The number of actions (in case the quantity is 1) that along with the period defines the rate limit.

period()
period() :: pos_integer

The period of time that along with limit defines the rate limit.

quantity()
quantity() :: pos_integer

The weight of an action. Typically it’s set to 1. The more expensive actions may use greater value.

storage()

Tuple that contains the module used for storage and options for the given storage.

storage_module()
storage_module() :: module

Storage module that implements Limiter.Storage behaviour.

storage_options()
storage_options() :: term

Options for a storage module. These options may differ for different storage implementations.

Functions

checkout(storage, key, quantity \\ 1, period, limit)

Checks if an action associated with a key is allowed.

reset(arg, key)
reset(storage, key) :: :ok

Resets the value associated with the key.