Skip to content
/ opuntia Public

Opuntia is a basic set of tools for traffic shaping for erlang and elixir. Because if you touch it too fast, it stings you.

License

Notifications You must be signed in to change notification settings

esl/opuntia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opuntia

Actions Status codecov Hex

opuntia is a basic set of tools for traffic shaping for erlang and elixir

It implements the token bucket algorithm.

There are two ways to use it, checking availability a priori or accepting a penalisation.

After creating a bucket

Bucket = opuntia:new(#{bucket_size => 10, rate => 1, time_unit => millisecond, start_full => true}),

you can either consume all tokens queued and see the suggested delay, considering that this might allow you to consume at once much more than the bucket size:

{NewShaper, Delay} = opuntia:update(Shaper, 50),
timer:sleep(Delay), %% Will suggest to sleep 40ms

or you can first how many tokens are available for you to consume before doing so:

Allowed = opuntia:peek(Shaper),
consume_tokens(Allowed),
{NewShaper, 0} = opuntia:update(Shaper), %% Will suggest no delay if you were diligent and consume less that adviced

About

Opuntia is a basic set of tools for traffic shaping for erlang and elixir. Because if you touch it too fast, it stings you.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages