Skip to content

Commit

Permalink
Merge pull request #146 from elandau/bugfix/ignore_cancelled
Browse files Browse the repository at this point in the history
Ignore cancelled
  • Loading branch information
elandau authored Sep 19, 2019
2 parents 5870f1a + faf473c commit 18692b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static class Builder {
private MetricRegistry registry = EmptyMetricRegistry.INSTANCE;
private double rttTolerance = 2.0;
private int probeInterval = 1000;
private double backoffRatio = 0.9;

/**
* Minimum threshold for accepting a new rtt sample. Any RTT lower than this threshold
Expand Down Expand Up @@ -153,6 +154,18 @@ public Builder metricRegistry(MetricRegistry registry) {
this.registry = registry;
return this;
}

/**
* Ratio applied to the limit when a timeout was identified within the sampling window. The default value is
* 0.9. A value of 1.0 means no backoff.
* @param backoffRatio
* @return
*/
public Builder backoffRatio(double backoffRatio) {
Preconditions.checkArgument(backoffRatio >= 0.5 && backoffRatio <= 1.0, "backoffRatio must be in the range [0.5, 1.0]");
this.backoffRatio = backoffRatio;
return this;
}

@Deprecated
public Builder probeMultiplier(int probeMultiplier) {
Expand Down Expand Up @@ -205,14 +218,16 @@ public static GradientLimit newDefault() {

private final double rttTolerance;

private final double backoffRatio;

private final SampleListener minRttSampleListener;

private final SampleListener minWindowRttSampleListener;

private final SampleListener queueSizeSampleListener;

private final int probeInterval;

private int resetRttCounter;

private GradientLimit(Builder builder) {
Expand All @@ -223,6 +238,7 @@ private GradientLimit(Builder builder) {
this.queueSize = builder.queueSize;
this.smoothing = builder.smoothing;
this.rttTolerance = builder.rttTolerance;
this.backoffRatio = builder.backoffRatio;
this.probeInterval = builder.probeInterval;
this.resetRttCounter = nextProbeCountdown();
this.rttNoLoadMeasurement = new MinimumMeasurement();
Expand Down Expand Up @@ -272,7 +288,7 @@ public int _update(final long startTime, final long rtt, final int inflight, fin
double newLimit;
// Reduce the limit aggressively if there was a drop
if (didDrop) {
newLimit = estimatedLimit/2;
newLimit = estimatedLimit * backoffRatio;
// Don't grow the limit if we are app limited
} else if (inflight < estimatedLimit / 2) {
return (int)estimatedLimit;
Expand Down
2 changes: 1 addition & 1 deletion concurrency-limits-grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8
dependencies {
compile project(":concurrency-limits-core")

compile "io.grpc:grpc-core:1.9.0"
compileOnly "io.grpc:grpc-core:1.9.0"

testCompile project(":concurrency-limits-spectator")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public void close(Status status, Metadata trailers) {
} finally {
safeComplete(() -> {
switch (status.getCode()) {
case CANCELLED:
case DEADLINE_EXCEEDED:
listener.onDropped();
break;
Expand Down

0 comments on commit 18692b0

Please sign in to comment.