-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from elandau/feature/gradient_tweak
RTT noLoad low pass filter
- Loading branch information
Showing
7 changed files
with
127 additions
and
137 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ncy-limits-core/src/main/java/com/netflix/concurrency/limits/limit/ExpAvgMeasurement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.netflix.concurrency.limits.limit; | ||
|
||
public class ExpAvgMeasurement implements Measurement { | ||
private final int window; | ||
private final double ratio; | ||
private final double filter; | ||
|
||
private double value; | ||
private int count; | ||
|
||
public ExpAvgMeasurement(int window, double filter) { | ||
this.window = window; | ||
this.ratio = 1.0 / window; | ||
this.filter = filter; | ||
this.value = 0.0; | ||
this.count = 0; | ||
} | ||
|
||
@Override | ||
public Number add(Number sample) { | ||
// First sample seen | ||
if (count == 0) { | ||
value = sample.doubleValue(); | ||
count = 1; | ||
// Adaptive average for the first <window> samples | ||
} else if (count < window) { | ||
count++; | ||
double tempRatio = 1.0 / count; | ||
value = (1-tempRatio) * value + tempRatio * Math.min(value*filter, sample.doubleValue()); | ||
// Steady state | ||
} else { | ||
value = (1-ratio) * value + ratio * Math.min(value*filter, sample.doubleValue()); | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public Number get() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
value = 0.0; | ||
count = 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/Measurement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.