Skip to content

Commit

Permalink
Merge pull request #21 from Netflix/bugfix/simpler_vegas
Browse files Browse the repository at this point in the history
Misc cleanup
  • Loading branch information
elandau authored Feb 13, 2018
2 parents 220468f + 905dc30 commit 72fe8b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class Builder {
private Function<Integer, Integer> alpha = (limit) -> 3;
private Function<Integer, Integer> beta = (limit) -> 6;
private Function<Integer, Integer> increaseFunc = (limit) -> limit + 1;
private Function<Integer, Integer> decreaseFunc = (limit) -> limit / 2;
private Function<Integer, Integer> decreaseFunc = (limit) -> limit - 1;

public Builder alpha(int alpha) {
this.alpha = (ignore) -> alpha;
Expand Down Expand Up @@ -86,6 +86,7 @@ public Builder maxConcurrency(int maxConcurrency) {
return this;
}

@Deprecated
public Builder backoffRatio(double ratio) {
return this;
}
Expand Down Expand Up @@ -158,7 +159,7 @@ public synchronized void update(long rtt) {
int alpha = alphaFunc.apply((int)estimatedLimit);
int beta = betaFunc.apply((int)estimatedLimit);

if (queueSize <= alpha) {
if (queueSize < alpha) {
newLimit = increaseFunc.apply((int)estimatedLimit);
} else if (queueSize > beta) {
newLimit = decreaseFunc.apply((int)estimatedLimit);
Expand All @@ -169,15 +170,12 @@ public synchronized void update(long rtt) {

newLimit = Math.max(1, Math.min(maxLimit, newLimit));
newLimit = (int) ((1 - smoothing) * estimatedLimit + smoothing * newLimit);
if ((int)newLimit != (int)estimatedLimit) {
estimatedLimit = newLimit;
if (LOG.isDebugEnabled()) {
LOG.debug("New limit={} minRtt={} μs winRtt={} μs queueSize={}",
estimatedLimit,
TimeUnit.NANOSECONDS.toMicros(rtt_noload),
TimeUnit.NANOSECONDS.toMicros(rtt),
queueSize);
}
if ((int)newLimit != (int)estimatedLimit && LOG.isDebugEnabled()) {
LOG.debug("New limit={} minRtt={} μs winRtt={} μs queueSize={}",
estimatedLimit,
TimeUnit.NANOSECONDS.toMicros(rtt_noload),
TimeUnit.NANOSECONDS.toMicros(rtt),
queueSize);
}
estimatedLimit = newLimit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void decreaseLimit() {
limit.update(TimeUnit.MILLISECONDS.toNanos(10));
Assert.assertEquals(11, limit.getLimit());
limit.update(TimeUnit.MILLISECONDS.toNanos(50));
Assert.assertEquals(5, limit.getLimit());
Assert.assertEquals(10, limit.getLimit());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.netflix.concurrency.limits.spectator;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.patterns.PolledMeter;

import org.junit.Assert;
import org.junit.Test;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.patterns.PolledMeter;

public class SpectatorMetricRegistryTest {
@Test
public void testGuage() {
Expand All @@ -18,4 +18,18 @@ public void testGuage() {

Assert.assertEquals(10.0, registry.gauge(registry.createId("foo.bar")).value(), 0);
}

@Test
public void testUnregister() {
DefaultRegistry registry = new DefaultRegistry();
SpectatorMetricRegistry metricRegistry = new SpectatorMetricRegistry(registry, registry.createId("foo"));

metricRegistry.registerGauge("bar", () -> 10);
metricRegistry.registerGauge("bar", () -> 20);

PolledMeter.update(registry);

Assert.assertEquals(20.0, registry.gauge(registry.createId("foo.bar")).value(), 0);

}
}

0 comments on commit 72fe8b6

Please sign in to comment.