Functions to create and execute rate limiters.
Functions to create and execute rate limiters.
(acquire-permission! rate-limiter)
(acquire-permission! rate-limiter permits)
Attempts to acquire the specified number of permits from rate-limiter
.
Blocks until all permits are received or the rate limiter timeout duration is exceeded. Returns a value indicating success.
The default permit value is 1.
Attempts to acquire the specified number of permits from `rate-limiter`. Blocks until all permits are received or the rate limiter timeout duration is exceeded. Returns a value indicating success. The default permit value is 1.
(add-configuration! name config)
(add-configuration! registry name config)
Adds config
to the registry
under the name
.
Uses default-registry
if registry
is not provided.
Adds `config` to the `registry` under the `name`. Uses [[default-registry]] if `registry` is not provided.
(all-rate-limiters)
(all-rate-limiters registry)
Gets all the rate limiters in registry
.
Uses default-registry
if registry
is not provided.
Gets all the rate limiters in `registry`. Uses [[default-registry]] if `registry` is not provided.
(change-limit-for-period! rate-limiter limit-for-period)
Changes the number of allowable calls during a refresh period.
The new limit will take effect in the next refresh period. The current period is not affected.
Changes the number of allowable calls during a refresh period. The new limit will take effect in the next refresh period. The current period is not affected.
(change-timeout-duration! rate-limiter timeout-duration)
Changes the timeout duration milliseconds for the rate limiter.
The new timeout duration will not affect calls currently waiting for permission to execute.
Changes the timeout duration milliseconds for the rate limiter. The new timeout duration will not affect calls currently waiting for permission to execute.
The global ratelimiter and config registry.
The global ratelimiter and config registry.
(drain-permissions! rate-limiter)
Drains all the permits left in the current period.
Drains all the permits left in the current period.
(emit-events! rate-limiter out-chan & {:keys [only exclude] :or {exclude []}})
Offers events on rate-limiter
to out-chan
.
The event types are identified by event-types
.
This function also accepts :only
and :exclude
keyword params that are
sequences of the event types that should be included or excluded,
respectively.
Offers events on `rate-limiter` to `out-chan`. The event types are identified by [[event-types]]. This function also accepts `:only` and `:exclude` keyword params that are sequences of the event types that should be included or excluded, respectively.
(emit-registry-events! out-chan)
(emit-registry-events! registry
out-chan
&
{:keys [only exclude] :or {exclude []}})
Offers registry events to out-chan
.
The event types are identified by registry-event-types
.
This function also accepts :only
and :exclude
keyword params that are
sequences of the event types that should be included or excluded,
respectively.
Uses default-registry
if registry
is not provided.
Offers registry events to `out-chan`. The event types are identified by [[registry-event-types]]. This function also accepts `:only` and `:exclude` keyword params that are sequences of the event types that should be included or excluded, respectively. Uses [[default-registry]] if `registry` is not provided.
(execute rate-limiter f & args)
Apply args to f within a context protected by the rate limiter.
The function will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, this function will throw an exception.
Apply args to f within a context protected by the rate limiter. The function will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, this function will throw an exception.
(find name)
(find registry name)
Finds the rate limiter identified by name
in registry
.
Uses default-registry
if registry
is not provided.
Finds the rate limiter identified by `name` in `registry`. Uses [[default-registry]] if `registry` is not provided.
(name rate-limiter)
Gets the name of the rate limiter.
Gets the name of the rate limiter.
(rate-limiter name)
(rate-limiter name config)
Creates a rate limiter with the name
and config
.
Creates a rate limiter with the `name` and `config`.
(rate-limiter! name)
(rate-limiter! registry name)
(rate-limiter! registry name config)
Creates or fetches a rate limiter with the specified name and config and
stores it in registry
.
The config value can be either a config map or the name of a config map stored in the registry. If the rate limiter already exists in the registry, the config value is ignored.
Uses default-registry
if registry
is not provided.
Creates or fetches a rate limiter with the specified name and config and stores it in `registry`. The config value can be either a config map or the name of a config map stored in the registry. If the rate limiter already exists in the registry, the config value is ignored. Uses [[default-registry]] if `registry` is not provided.
(registry)
(registry configs-map)
Creates a registry with default values or a map of name/config-map pairs.
Creates a registry with default values or a map of name/config-map pairs.
The event types that can be raised by a registry.
The event types that can be raised by a registry.
(remove! name)
(remove! registry name)
Removes the rate limiter identified by name
from registry
.
Uses default-registry
if registry
is not provided.
Removes the rate limiter identified by `name` from `registry`. Uses [[default-registry]] if `registry` is not provided.
(replace! name rate-limiter)
(replace! registry name rate-limiter)
Replaces the rate limiter identified by name
in registry
with the specified rate-limiter
.
Uses default-registry
if registry
is not provided.
Replaces the rate limiter identified by `name` in `registry` with the specified `rate-limiter`. Uses [[default-registry]] if `registry` is not provided.
(reserve-permission! rate-limiter)
(reserve-permission! rate-limiter permits)
Reserves the specified number of permits.
Returns the number of nanoseconds you must wait to use the permission. If the number is negative, the request to reserve permission failed. This failure mode may occur if the number of nanoseconds to wait exceeds the rate limiter timeout duration.
The default permit value is 1.
Reserves the specified number of permits. Returns the number of nanoseconds you must wait to use the permission. If the number is negative, the request to reserve permission failed. This failure mode may occur if the number of nanoseconds to wait exceeds the rate limiter timeout duration. The default permit value is 1.
(with-rate-limiter rate-limiter & body)
Executes body within a context protected by the rate limiter.
rate-limiter
is either a rate limiter or the name of one in the global
registry. If you provide a name and a rate limiter of that name does not
already exist in the global registry, one will be created with the :default
config.
The code in body
will wait up to the configured timeout duration if the rate
limit has been exceeded. If the function is not allowed to execute before the
timeout duration expires, an exception will be thrown.
Executes body within a context protected by the rate limiter. `rate-limiter` is either a rate limiter or the name of one in the global registry. If you provide a name and a rate limiter of that name does not already exist in the global registry, one will be created with the `:default` config. The code in `body` will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, an exception will be thrown.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close