Limiter

Build Status

Rate limiter implementation of Generic Cell Rate Algorithm (GCRA).

For detailed information on how the algorithm works, please check the following links:

The implementation is similar to Go throttled library:

Installation

If available in Hex, the package can be installed as:

  1. Add limiter to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:limiter, "~> 0.1.1"}]
end
```
  1. Ensure limiter is started before your application:
```elixir
def application do
  [applications: [:limiter]]
end
```

Usage

First off, a storage must be configured and started. Currently, the rate limiter supports one implementation of the storage, which is Limiter.Storage.ConCache. Each implementation of the storage can have different options.

The storage can be started in two ways:

The Limiter module exports checkout/5 with the following arguments:

Example:

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

The Limiter.checkout/5 functions returns a struct (Limiter.Result) with the following information: