A sentry that adapts throughput with the success ratio of invoking the protected resource.
Circuit breaker is in broken state, invocations are failing immediately.
A sentry that limits the number of consecutive failures; a.k.a.
A sentry that limits the number of consecutive failures; a.k.a. a circuit breaker. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
The goal of a circuit breaker is to protect the caller from a resource that fails. It also protects the
resource from overload when it is trying to recover. A circuit breaker works by keeping track of the
number of consecutive failures. When there are more then consecutive failLimit
failures, the circuit
breaker 'breaks' and pro-actively blocks all following calls by throwing a
nl.grons.sentries.core.CircuitBreakerBrokenException.
Every retryDelay
one invocation is allowed through in order to test the resource. When this call succeeds,
the circuit breaker goes back to the flow state. If not, it stays in the broken state.
Please see http://day-to-day-stuff.blogspot.com/2013/02/breaking-circuit-breaker.html for a rationale of the used vocabulary (broken/flow state vs. the more known open/half open/close state).
Concurrency limit exceeded, invocations are failing immediately.
A sentry that limits the number of concurrent invocations.
A sentry that limits the number of concurrent invocations. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
The goal of a concurrency limiter is to prevent overloading of a shared resource. This sentry can be used as an alternative to a pool for easy to crate objects.
Duration limit of an invocation was exceeded.
A sentry that limits the duration of an invocation.
A sentry that limits the duration of an invocation. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
The goal of a duration limiter is to support callers that are only interested in the results for a limited time.
WARNING: do NOT use this sentry when you invoke it from a Future
or an Actor
.
For such circumstances you are MUCH better of with a timeout on the enclosing future or a timeout message
within the actor.
Reason: this sentry blocks the current thread while waiting on a future that executes the task. Blocking the
current thread is an anti-pattern for futures and actors.
Note that when the wait period has passed, the task still completes in another thread. Make
sure there are enough threads in the executor. By default a Executors.newCachedThreadPool()
is used which creates as much threads as needed. The executor can be changed by overriding
.executionContext.
Does load balancing between several resources.
Does load balancing between several resources.
Warning: the API is definitely not yet stable. When used wrong, you cause a memory leak. Use at your own risk.
type of resource
Sentry that collects metric of invocations.
Sentry that collects metric of invocations. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
The following metrics are created:
- timer "all" for all invocations - meter "notAvailable" for invocations leading to a nl.grons.sentries.support.NotAvailableException, e.g. all invocations blocked by a sentry - meter "fail" for other failed invocations
Note that in other to make effective use of the "notAvailable" meter, this sentry must be the first sentry in the chain.
This sentry can not be used in the same sentry chain as the nl.grons.sentries.core.TimerSentry.
No resources present at all, invocations are failing immediately.
Rate limit exceeded, invocations are failing immediately.
A sentry that limits the number of invocations per time span.
A sentry that limits the number of invocations per time span. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
A rate limiter is useful for cases where you asynchronously hand of some work and you don't want to overload the receiver. For example sending error emails or an asynchronous rendering job for which there is a limited capacity. For other cases a nl.grons.sentries.core.ConcurrencyLimitSentry is usually more appropriate.
Access to resource was blocked temporarily because throughput is currently reduced.
Sentry that times invocations.
Sentry that times invocations. A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.
A single metrics is created: timer "all" for all invocations.
This sentry can not be used in the same sentry chain as the nl.grons.sentries.core.MetricSentry.
A sentry that adapts throughput with the success ratio of invoking the protected resource. Think of it as a gradual circuit breaker.
The goal of this sentry is to protect the caller from a resource that slows down, or starts to produce errors when overloaded. By reducing throughput until success ratio is at an expected level, the resource can recover and work at its optimal efficiency.
For resources that behave correct most of the time, the target success ratio can be set quite high, e.g.
0.95
. When exceptions are more 'normal', you may have to lower this parameter.The success ratio is calculated per
evaluationDelay
with a simple1 - (fail count / success count)
. When the success ratio is belowtargetSuccessRatio
, the throughput is reduced tocurrentSuccessRatio * currentThroughputRatio
. When the success ratio is again equal to or above the target ratio, throughput is increased bysuccessIncreaseFactor
(defaults to +20%) with a minimum of 0.0001D (1 in thousand calls may proceed). Note that regardless of thecurrentThroughputRatio
, at least 1 call per evaluation period is allowed to continue.This sentry only makes sense for high volume resources. To prevent throttling in low volume times, it is possible to set the minimum number of invocations that must be observed per
evaluationDelay
before throttling takes place. (see theminimumInvocationCountThreshold
parameter).It does not make sense to throttle on fast failing invocations. In those cases its better to get the exception from the underlying resource then to get a ReducedThroughputException. Parameter
failedInvocationDurationThreshold
sets the minimum duration of failed invocation in order for those invocations to be counted as failed. By setting this value to a non-zero value, fast failures do not reduce throughput. (Note that the default is0
for backward compatibility.)When there is a calamity, this sentry only reacts as fast as the given
evaluationDelay
(1 second by default). When the resource becomes fully available, it takes at most 39 evaluation before throughput is back at 100%. You can test this by evaluating the following code in a Scala REPL:A new instance can be obtained through the nl.grons.sentries.SentrySupport mixin.