Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed May 10, 2024
2 parents 80295f4 + d696edd commit d325d93
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,7 @@ public abstract class AbstractRateLimiter implements RateLimiter {
public AbstractRateLimiter(RateLimitPolicy policy) {
this.policy = policy;
this.option = MapOption.of(policy.getActionParameters());
this.timeout = getTimeout(option);
}

/**
* Retrieves the timeout duration for permit acquisition based on the provided option.
* The timeout is determined by the `maxWaitMs` parameter set in actionParameters.
*
* @param option The option that may contain the max wait time in milliseconds.
* @return The timeout duration as a Duration object.
*/
protected Duration getTimeout(Option option) {
// The timeout period is set by `maxWaitMs` set in actionParameters
return Duration.ofMillis(option.getLong(MAX_WAIT_MS, DEFAULT_MAX_WAIT_MS));
this.timeout = Duration.ofMillis(policy.getMaxWaitMs());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public interface RateLimiter {

String MAX_BURST_SECONDS = "maxBurstSeconds";

String MAX_WAIT_MS = "maxWaitMs";

long DEFAULT_MAX_WAIT_MS = 0L;

/**
* Try to get a permit return the result
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public abstract class AbstractLimitPolicy extends PolicyId implements LimitPolic
*/
private String strategyType;

/**
* The maximum time, in milliseconds, a request can wait to be executed before it is rejected, when the maximum
* concurrency or rate limit has been reached.
*/
private long maxWaitMs;

/**
* A map of parameters that further customize the action of the limiting strategy.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public class ConcurrencyLimitPolicy extends AbstractLimitPolicy implements Polic
*/
private int maxConcurrency;

/**
* The maximum time, in milliseconds, a request can wait to be executed before it is rejected, when the maximum
* concurrency limit has been reached.
*/
private long maxWaitMs;

/**
* Constructs a new {@code ConcurrencyLimitPolicy} with default settings.
*/
Expand Down
35 changes: 31 additions & 4 deletions joylive-package/src/main/assembly/config/microservice.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"timeWindowInMs": 2000
}
],
"maxWaitMs": 100,
"actionParameters": {
"maxWaitMs": 100
},
"relationType": "AND",
"conditions": [
Expand Down Expand Up @@ -96,8 +96,13 @@
"retry": 10,
"retryInterval": 1000,
"timeout": 5000,
"retryStatuses": [500, 502],
"retryExceptions": ["java.lang.NullPointException"],
"retryStatuses": [
500,
502
],
"retryExceptions": [
"java.lang.NullPointException"
],
"version": 1704038400000
},
"rateLimitPolicies": [
Expand All @@ -115,8 +120,30 @@
"timeWindowInMs": 2000
}
],
"maxWaitMs": 100,
"actionParameters": {
},
"relationType": "AND",
"conditions": [
{
"type": "header",
"opType": "EQUAL",
"key": "x-live-ext-demo",
"value": [
"abc"
]
}
]
}
],
"concurrencyLimitPolicies": [
{
"name": "limit-rule-2",
"version": 1704038400000,
"strategyType": "Resilience4j",
"maxConcurrency": 10,
"maxWaitMs": 100,
"actionParameters": {
"maxWaitMs": 100
},
"relationType": "AND",
"conditions": [
Expand Down

0 comments on commit d325d93

Please sign in to comment.