• Stars
    star
    3
  • Rank 3,847,146 (Top 78 %)
  • Language
    Julia
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Julia package for limiting the rate at which events occur.

Test Register Document Compat Helper Tagbot

RateLimiter.jl

Julia package for limiting the rate at which expressions are evaluated. This can be useful for rate limiting access to network resources (e.g. websites). All methods are thread safe.

This example uses the Token-Bucket algorithm to limit how quickly the functions can be called.

using RateLimiter

tokens_per_second = 2
max_tokens = 100
initial_tokens = 0

limiter = TokenBucketRateLimiter(tokens_per_second, max_tokens, initial_tokens)

function f_cheap()
    println("cheap")
    return 1
end

function f_costly()
    println("costly")
    return 2
end

result = 0

for i in 1:10
    result += @rate_limit limiter 1 f_cheap()
    result += @rate_limit limiter 10 f_costly()
end

println("RESULT: $result")

Documentation

See https://chipkent.github.io/RateLimiter.jl/dev/.

Pull requests will publish documentation to https://chipkent.github.io/RateLimiter.jl/previews/PR##.