Class RateSpec
- java.lang.Object
-
- io.engineblock.activityapi.ratelimits.RateSpec
-
public class RateSpec extends java.lang.ObjectRate Limiter Specifications
A rate spec represent the configuration of a rate limiter. It is the event carrier for applying changes to a rate limiter. For scripting purposes, rate limiters can be controlled via assignment of a configuration string. A future version of the scripting API will support direct method access. For now, the following semantics will apply to the configuration value assigned to any of the rate parameters like cyclerate and striderate.
Controlling Rate Limiters
Rate limiters specifiers can be easily constructed programmatically. However, in scripting, these will often be controlled by assigning a configuration string.When a rate limiter is configured using the configuration String, it can be in one of the following forms:
- <rate>
- <rate>,<burst ratio>
- <rate>,<burst ratio>,<verb>
- 200 - allow up to 200 ops to start per second, with the default burst ratio of 1.1. Start the rate limiter automatically.
- 3.6,2 - Allow up to 3.6 ops to start per second, but allow up to 7.2 ops per second if needed to catch up. Start the rate limiter automatically
- 1000,1.05,restart - Allow up to 1000 ops per second on average, but allow 1050 ops per second if the workload gets behind. If the rate limiter was already running, restart it, clearing any previous backlog (wait time) and resource pools.
Rate Limiter Life Cycle
A rate limiter can be directly configured, started, restarted. Indirectly, rate limiter construction and initialization occurs as needed.
- (constructed)
- Rate limiters are constructed and assigned automatically when they are first configured. A rate limiter may not be explicitly constructed by the user.
- configure
- When a rate limiter is configured, the rate spec is applied to it. If the rate limiters is already running, then this new rate is applied to it. Applying the same rate parameters a second time to a given rate limiter is a no-op.
- (initialization)
- A rate limiter is initialized immediately before it is initially started. Rate limiters are also re-initialized when they are restarted. When a rate limiter is initialized, the start time is set to the current time, and the resource pools and accumulated wait time are zeroed. A rate limiter may not be explicitly initialized by the user.
- start
- Starting a rate limiter activates the rate metering logic according to the current time. From the time a rate limiter is started, any unused time will accumulate as wait time. A rate limiter is required to be reset immediately before it is started for the first time.
- restart
- Restarting a rate limiter is the same as starting it initially. The only difference is that restarting forces a re-initialization as part of the configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRateSpec.Verb
-
Field Summary
Fields Modifier and Type Field Description doubleburstRatiostatic doubleDEFAULT_BURST_RATIOstatic doubleDEFAULT_RATE_OPS_Sstatic RateSpec.VerbDEFAULT_VERBdoubleopsPerSecTarget rate in Operations Per SecondRateSpec.Verbverb
-
Constructor Summary
Constructors Constructor Description RateSpec(double opsPerSec, double burstRatio)RateSpec(double opsPerSec, double burstRatio, RateSpec.Verb type)RateSpec(ParameterMap.NamedParameter tuple)RateSpec(java.lang.String spec)
-
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object o)doublegetBurstRatio()longgetNanosPerOp()doublegetRate()RateSpec.VerbgetVerb()inthashCode()booleanisAutoStart()booleanisRestart()java.lang.StringtoString()RateSpecwithBurstRatio(double burstRatio)RateSpecwithOpsPerSecond(double rate)RateSpecwithVerb(RateSpec.Verb verb)
-
-
-
Field Detail
-
DEFAULT_RATE_OPS_S
public static final double DEFAULT_RATE_OPS_S
- See Also:
- Constant Field Values
-
DEFAULT_BURST_RATIO
public static final double DEFAULT_BURST_RATIO
- See Also:
- Constant Field Values
-
DEFAULT_VERB
public static RateSpec.Verb DEFAULT_VERB
-
opsPerSec
public double opsPerSec
Target rate in Operations Per Second
-
burstRatio
public double burstRatio
-
verb
public RateSpec.Verb verb
-
-
Constructor Detail
-
RateSpec
public RateSpec(double opsPerSec, double burstRatio)
-
RateSpec
public RateSpec(double opsPerSec, double burstRatio, RateSpec.Verb type)
-
RateSpec
public RateSpec(ParameterMap.NamedParameter tuple)
-
RateSpec
public RateSpec(java.lang.String spec)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withOpsPerSecond
public RateSpec withOpsPerSecond(double rate)
-
withBurstRatio
public RateSpec withBurstRatio(double burstRatio)
-
withVerb
public RateSpec withVerb(RateSpec.Verb verb)
-
getNanosPerOp
public long getNanosPerOp()
-
getRate
public double getRate()
-
getBurstRatio
public double getBurstRatio()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getVerb
public RateSpec.Verb getVerb()
-
isAutoStart
public boolean isAutoStart()
-
isRestart
public boolean isRestart()
-
-