-
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 #74 from elandau/feature/refactor
Eliminate Strategy abstraction + Gradient2 algorithm
- Loading branch information
Showing
39 changed files
with
1,195 additions
and
1,293 deletions.
There are no files selected for viewing
50 changes: 15 additions & 35 deletions
50
concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/Limit.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 |
---|---|---|
@@ -1,49 +1,29 @@ | ||
package com.netflix.concurrency.limits; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Contract for an algorithm that calculates a concurrency limit based on | ||
* rtt measurements | ||
*/ | ||
public interface Limit { | ||
/** | ||
* Details of the current sample window | ||
*/ | ||
interface SampleWindow { | ||
/** | ||
* @return Candidate RTT in the sample window. This is traditionally the minimum rtt. | ||
*/ | ||
long getCandidateRttNanos(); | ||
|
||
/** | ||
* @return Average RTT in the sample window. Excludes timeouts and dropped rtt. | ||
*/ | ||
long getAverateRttNanos(); | ||
|
||
/** | ||
* @return Maximum number of inflight observed during the sample window | ||
*/ | ||
int getMaxInFlight(); | ||
|
||
/** | ||
* @return Number of observed RTTs in the sample window | ||
*/ | ||
int getSampleCount(); | ||
|
||
/** | ||
* @return True if there was a timeout | ||
*/ | ||
boolean didDrop(); | ||
} | ||
|
||
/** | ||
* @return Current estimated limit | ||
*/ | ||
int getLimit(); | ||
|
||
|
||
/** | ||
* Register a callback to receive notification whenever the limit is updated to a new value | ||
* @param consumer | ||
*/ | ||
void notifyOnChange(Consumer<Integer> consumer); | ||
|
||
/** | ||
* Update the concurrency limit using a new rtt sample | ||
* | ||
* @param sample Data from the last sampling window such as RTT | ||
* Update the limiter with a sample | ||
* @param startTime | ||
* @param rtt | ||
* @param inflight | ||
* @param didDrop | ||
*/ | ||
void update(SampleWindow sample); | ||
void onSample(long startTime, long rtt, int inflight, boolean didDrop); | ||
} |
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
81 changes: 0 additions & 81 deletions
81
concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/Strategy.java
This file was deleted.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
...urrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/AbstractLimit.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,41 @@ | ||
package com.netflix.concurrency.limits.limit; | ||
|
||
import com.netflix.concurrency.limits.Limit; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.function.Consumer; | ||
|
||
public abstract class AbstractLimit implements Limit { | ||
private volatile int limit; | ||
private final List<Consumer<Integer>> listeners = new CopyOnWriteArrayList<>(); | ||
|
||
protected AbstractLimit(int initialLimit) { | ||
this.limit = initialLimit; | ||
} | ||
|
||
@Override | ||
public final synchronized void onSample(long startTime, long rtt, int inflight, boolean didDrop) { | ||
setLimit(_update(startTime, rtt, inflight, didDrop)); | ||
} | ||
|
||
protected abstract int _update(long startTime, long rtt, int inflight, boolean didDrop); | ||
|
||
@Override | ||
public final int getLimit() { | ||
return limit; | ||
} | ||
|
||
protected synchronized void setLimit(int newLimit) { | ||
if (newLimit != limit) { | ||
limit = newLimit; | ||
listeners.forEach(listener -> listener.accept(newLimit)); | ||
} | ||
} | ||
|
||
public void notifyOnChange(Consumer<Integer> consumer) { | ||
this.listeners.add(consumer); | ||
} | ||
|
||
|
||
} |
18 changes: 5 additions & 13 deletions
18
concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/FixedLimit.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 |
---|---|---|
@@ -1,33 +1,25 @@ | ||
package com.netflix.concurrency.limits.limit; | ||
|
||
import com.netflix.concurrency.limits.Limit; | ||
|
||
/** | ||
* Non dynamic limit with fixed value | ||
*/ | ||
public final class FixedLimit implements Limit { | ||
|
||
private final int limit; | ||
public final class FixedLimit extends AbstractLimit { | ||
|
||
public static FixedLimit of(int limit) { | ||
return new FixedLimit(limit); | ||
} | ||
|
||
private FixedLimit(int limit) { | ||
this.limit = limit; | ||
} | ||
|
||
@Override | ||
public int getLimit() { | ||
return limit; | ||
super(limit); | ||
} | ||
|
||
@Override | ||
public void update(SampleWindow sample) { | ||
public int _update(long startTime, long rtt, int inflight, boolean didDrop) { | ||
return getLimit(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FixedLimit [limit=" + limit + "]"; | ||
return "FixedLimit [limit=" + getLimit() + "]"; | ||
} | ||
} |
Oops, something went wrong.