Skip to content

esl/opuntia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 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

Releasing to Hex.pm

Creating a GitHub release (non-draft, non-prerelease) automatically publishes the package to Hex.pm via the Publish to Hex workflow. This workflow can also be triggered manually from the Actions tab — make sure to run it from the specific tag you want to publish.

To revert a published version, run the Revert published version from Hex workflow from the Actions tab, providing the version to revert. Hex.pm only allows reverting within 1 hour of publishing — after that, the version can only be retired.

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

 
 
 

Contributors

Languages