AllocationStrategy that delegates to an underlying AllocationStrategy and samples
the getPermits(int) and returnPermits(int) methods.
Only a given percentage of calls are sampled, and these are stored as stacktraces in the sampling strategy.
If a AllocationStrategy#returnPermits(int) call fails, a new IllegalArgumentException
is thrown with a composite cause that represents all the sampled calls (see Exceptions#unwrapMultiple(Throwable)).
The two types of calls are sampled separately. The reservoir sampling algorithm is used to instantiate a sampling decision
bitset over 100 slots, which are then applied to windows of 100 calls.
Access to the delegate field is possible, as well as gettingSamplingRate/returningSamplingRate
configuration fields and gettingSamples/returningSamples collections.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv long | |
| pack-priv long | |
| public final AllocationStrategy | delegate
The delegate |
| pack-priv final BitSet | |
| public final LinkedList | gettingSamples
The list of samples for |
| public final double | gettingSamplingRate
The configured sampling rate for |
| pack-priv final BitSet | |
| public final LinkedList | returningSamples
The list of samples for |
| public final double | returningSamplingRate
The configured sampling rate for |
| Access | Constructor and Description |
|---|---|
| pack-priv | SamplingAllocationStrategy(AllocationStrategy delegate, double gettingSamplingRate, double returningSamplingRate)
|
| Modifier and Type | Method and Description |
|---|---|
| public int | estimatePermitCount()
Implements reactor. |
| public int | getPermits(int
the desired number of new resources desired)Implements reactor. desired positive number of new resources.
|
| public int | |
| public int | |
| public int | permitMinimum()
Implements reactor. 0 for scale-to-zero.
|
| public void | returnPermits(int returned)
Implements reactor. Pool, potentially leaving space
for N new ones to be allocated.
|
| pack-priv static BitSet | Returns: a random bitsetcardinality of the bit set selectedOutOf100)Reservoir sampling algorithm borrowed from Stack Overflow. |
| pack-priv void | |
| pack-priv void | |
| pack-priv static AllocationStrategy | |
| public static SamplingAllocationStrategy | Returns: a sampledAllocationStrategy that otherwise behaves like the PoolBuilder#sizeBetween(int, int) strategythe minimum number of permits (see min, int PoolBuilder#sizeBetween(int, int))the maximum number of permits (see max, double PoolBuilder#sizeBetween(int, int))the sampling rate for getPermitsSamplingRate, double AllocationStrategy#getPermits(int) calls (0.0d to 1.0d)the sampling rate for returnPermitsSamplingRate)AllocationStrategy#returnPermits(int) calls (0.0d to 1.0d)An |
| public int | warmupParallelism()
Overrides default reactor. |
| public static SamplingAllocationStrategy | withSampling(AllocationStrategy
the underlying delegate, double AllocationStrategythe sampling rate for getPermitsSamplingRate, double AllocationStrategy#getPermits(int) calls (0.0d to 1.0d)the sampling rate for returnPermitsSamplingRate)AllocationStrategy#returnPermits(int) calls (0.0d to 1.0d)An |
| countGetting | back to summary |
|---|---|
| pack-priv long countGetting | |
| countReturning | back to summary |
|---|---|
| pack-priv long countReturning | |
| delegate | back to summary |
|---|---|
| public final AllocationStrategy delegate The delegate | |
| gettingSampleDecisions | back to summary |
|---|---|
| pack-priv final BitSet gettingSampleDecisions | |
| gettingSamples | back to summary |
|---|---|
| public final LinkedList<Throwable> gettingSamples The list of samples for | |
| gettingSamplingRate | back to summary |
|---|---|
| public final double gettingSamplingRate The configured sampling rate for | |
| returningSampleDecisions | back to summary |
|---|---|
| pack-priv final BitSet returningSampleDecisions | |
| returningSamples | back to summary |
|---|---|
| public final LinkedList<Throwable> returningSamples The list of samples for | |
| returningSamplingRate | back to summary |
|---|---|
| public final double returningSamplingRate The configured sampling rate for | |
| SamplingAllocationStrategy | back to summary |
|---|---|
| pack-priv SamplingAllocationStrategy(AllocationStrategy delegate, double gettingSamplingRate, double returningSamplingRate) | |
| estimatePermitCount | back to summary |
|---|---|
| public int estimatePermitCount() Implements reactor. Doc from reactor. Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be
allocated. Should be paired with
| |
| getPermits | back to summary |
|---|---|
| public int getPermits(int desired) Implements reactor. Doc from reactor. Try to get the permission to allocate a
For the warming up case, the typical pattern would be to call this method with a
| |
| permitGranted | back to summary |
|---|---|
| public int permitGranted() Implements reactor.
| |
| permitMaximum | back to summary |
|---|---|
| public int permitMaximum() Implements reactor.
| |
| permitMinimum | back to summary |
|---|---|
| public int permitMinimum() Implements reactor. Doc from reactor. Return the minimum number of permits this strategy tries to maintain granted
(reflecting a minimal size for the pool), or
| |
| returnPermits | back to summary |
|---|---|
| public void returnPermits(int returned) Implements reactor. Doc from reactor. Update the strategy to indicate that N resources were discarded from the
Some strategy MIGHT throw an
| |
| sampleBitSet | back to summary |
|---|---|
| pack-priv static BitSet sampleBitSet(int selectedOutOf100) Reservoir sampling algorithm borrowed from Stack Overflow. https://stackoverflow.com/questions/12817946/generate-a-random-bitset-with-n-1s
| |
| sampleGetting | back to summary |
|---|---|
| pack-priv void sampleGetting(final int desired) | |
| sampleReturning | back to summary |
|---|---|
| pack-priv void sampleReturning(final int returned) | |
| sizeBetweenHelper | back to summary |
|---|---|
| pack-priv static AllocationStrategy sizeBetweenHelper(int min, int max) | |
| sizeBetweenWithSampling | back to summary |
|---|---|
| public static SamplingAllocationStrategy sizeBetweenWithSampling(int min, int max, double getPermitsSamplingRate, double returnPermitsSamplingRate) An
| |
| warmupParallelism | back to summary |
|---|---|
| public int warmupParallelism() Overrides default reactor. Doc from reactor. Return the concurrency level used when the allocator is subscribed to during the warmup phase, if any.
The number of resources created concurrently will not exceed the value returned by Defaults to 1
| |
| withSampling | back to summary |
|---|---|
| public static SamplingAllocationStrategy withSampling(AllocationStrategy delegate, double getPermitsSamplingRate, double returnPermitsSamplingRate) An The two types of calls are sampled separately. The reservoir sampling algorithm is used to instantiate a sampling decision bitset over 100 slots, which are then applied live to windows of 100 calls.
| |