Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce traffic resiliency features #2911

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
weight -> priority
  • Loading branch information
tkountis committed May 8, 2024
commit c0884beaa313ab95a78e004e78802ed622a6876d
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ public static CapacityLimiter composite(final List<CapacityLimiter> providers) {
* Returns a {@link CapacityLimiter} that will reject all requests till the current pending request count is equal
* or less to the passed {@code capacity}.
* This {@link CapacityLimiter} takes into consideration the {@link Classification} of a given request and will
* variate the effective {@code capacity} according to the {@link Classification#weight() weight} before
* variate the effective {@code capacity} according to the {@link Classification#priority() weight} before
* attempting to grant access to the request. The effective {@code capacity} will never be more than the given
* {@code capacity}.
* <p>
* Requests with {@link Classification#weight() weight} equal to or greater than {@code 100} will enjoy
* the full capacity (100%), while requests with {@link Classification#weight() weight} less than {@code 100}
* Requests with {@link Classification#priority() weight} equal to or greater than {@code 100} will enjoy
* the full capacity (100%), while requests with {@link Classification#priority() weight} less than {@code 100}
* will be mapped to a percentage point of the given {@code capacity} and be granted access only if the {@code
* consumed capacity} is less than that percentage.
* <br>
* Example: With a {@code capacity} = 10, and incoming {@link Classification#weight()} = 70, then the effective
* Example: With a {@code capacity} = 10, and incoming {@link Classification#priority()} = 70, then the effective
* target limit for this request will be 70% of the 10 = 7. If current consumption is less than 7, the request
* will be permitted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
@FunctionalInterface
public interface Classification {
/**
* The weight should be a positive number between 0.1 and 1.0 (inclusive), which hints to a {@link CapacityLimiter}
* The priority should be a positive number between 0 and 100 (inclusive), which hints to a {@link CapacityLimiter}
* the importance of a {@link Classification}.
* Higher value represents the most important {@link Classification}, while lower value represents less important
* {@link Classification}.
* @return A positive value between 0.1 and 1.0 (inclusive) that hints importance of a request to a
* @return A positive value between 0 and 100 (inclusive) that hints importance of a request to a
* {@link CapacityLimiter}.
*/
int weight();
int priority();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String name() {

@Override
public Ticket tryAcquire(final Classification classification, final ContextMap meta) {
final int weight = min(max(classification.weight(), 0), 100);
final int weight = min(max(classification.priority(), 0), 100);
final int effectiveLimit = (capacity * weight) / 100;
for (;;) {
final int currPending = pending;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FixedCapacityLimiterBuilder name(final String name) {
/**
* Defines the fixed capacity for the {@link CapacityLimiter}.
* Concurrent requests above this figure will be rejected. Requests with particular
* {@link Classification#weight() weight} will be respected and the total capacity for them will be adjusted
* {@link Classification#priority() weight} will be respected and the total capacity for them will be adjusted
* accordingly.
* @param capacity The max allowed concurrent requests that this {@link CapacityLimiter} should allow.
* @return {@code this}.
Expand Down
Loading