-
Notifications
You must be signed in to change notification settings - Fork 2
Misc
Daniel Pepper edited this page Mar 7, 2023
·
4 revisions
Synchronize work across systems using a mutex mixin.
class Counter
include Berater::Mutex
def incr
synchronize { ... }
end
def incr_key(key)
synchronize(key) { ... }
end
end
What's the difference between a rate limiter and a concurrency limiter? Can you build one with the other?
Both enforce limits, but differ with respect to time and memory. A rate limiter can be implemented using a concurrency limiter, by allowing every lock to timeout rather than be released. It wastes memory, but is functionally equivalent. A concurrency limiter can nearly be implemented using a rate limiter, by decrementing the used capacity when a lock is released. The order of locks, however, is lost and thus a timeout will not properly function.
An example is worth a thousand words :)
Experimental...
using Berater::DSL
Berater(:key) { 1.per second } do
...
end
Berater(:key) { 3.at_once } do
...
end