Module Core_kernel__.Limiter.Expert

expert operations
val create_exn : now:Core_kernel.Time_ns.t ‑> hopper_to_bucket_rate_per_sec:Core_kernel__.Import.float Infinite_or_finite.t ‑> bucket_limit:Core_kernel__.Import.int ‑> in_flight_limit:Core_kernel__.Import.int Infinite_or_finite.t ‑> initial_bucket_level:Core_kernel__.Import.int ‑> initial_hopper_level:Core_kernel__.Import.int Infinite_or_finite.t ‑> t

These tunables can be combined in several ways:

In all cases above throttling and rate limiting combine nicely when the unit of work for both is the same (e.g. one token per message). If the unit of work is different (e.g. rate limit base on a number of tokens equal to message size, but throttle base on simple message count) then a single t probably cannot be used to get the correct behavior, and two instances should be used with tokens taken from both.

val tokens_may_be_available_when : t ‑> now:Core_kernel.Time_ns.t ‑> Core_kernel__.Import.int ‑> Tokens_may_be_available_result.t

returns the earliest time when the requested number of tokens could possibly be delivered. There is no guarantee that the requested number of tokens will actually be available at this time. You must call try_take to actually attempt to take the tokens.

val try_take : t ‑> now:Core_kernel.Time_ns.t ‑> Core_kernel__.Import.int ‑> Try_take_result.t

attempts to take the given number of tokens from the bucket. try_take t ~now n succeeds iff in_bucket t ~now >= n.

val return_to_hopper : t ‑> now:Core_kernel.Time_ns.t ‑> Core_kernel__.Import.int ‑> Core_kernel__.Import.unit

return the given number of tokens to the hopper. These tokens will fill the tokens available to try_take at the fill_rate. Note that if return is called on more tokens then have actually been removed it can cause the number of concurrent jobs to exceed max_concurrent_jobs.

val try_return_to_bucket : t ‑> now:Core_kernel.Time_ns.t ‑> Core_kernel__.Import.int ‑> Try_return_to_bucket_result.t

return the given number of tokens directly to the bucket. If the amount is negative, is more than is currently in flight, or if moving the amount would cause the bucket to surpass its bucket_limit, Unable is returned.