use of com.twitter.distributedlog.exceptions.OverCapacityException in project distributedlog by twitter.
the class TestWriteLimiter method testUnsetDisableFeatureAfterPermitsExceeded.
@Test
public void testUnsetDisableFeatureAfterPermitsExceeded() throws Exception {
SettableFeature feature = new SettableFeature("test", 10000);
SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
limiter.acquire();
limiter.acquire();
limiter.acquire();
limiter.acquire();
assertPermits(streamLimiter, 4, globalLimiter, 4);
feature.set(0);
limiter.release();
assertPermits(streamLimiter, 3, globalLimiter, 3);
try {
limiter.acquire();
fail("should have thrown stream limit exception");
} catch (OverCapacityException ex) {
}
assertPermits(streamLimiter, 3, globalLimiter, 3);
limiter.release();
limiter.release();
limiter.release();
assertPermits(streamLimiter, 0, globalLimiter, 0);
}
use of com.twitter.distributedlog.exceptions.OverCapacityException in project distributedlog by twitter.
the class TestWriteLimiter method testUnsetDisableFeatureBeforePermitsExceeded.
@Test
public void testUnsetDisableFeatureBeforePermitsExceeded() throws Exception {
SettableFeature feature = new SettableFeature("test", 0);
SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
limiter.acquire();
try {
limiter.acquire();
fail("should have thrown stream limit exception");
} catch (OverCapacityException ex) {
}
assertPermits(streamLimiter, 1, globalLimiter, 1);
feature.set(10000);
limiter.acquire();
assertPermits(streamLimiter, 2, globalLimiter, 2);
}
use of com.twitter.distributedlog.exceptions.OverCapacityException in project distributedlog by twitter.
the class StreamRequestLimiter method build.
@Override
public RequestLimiter<StreamOp> build() {
// RPS hard, soft limits
RequestLimiterBuilder rpsHardLimiterBuilder = RequestLimiterBuilder.newRpsLimiterBuilder().statsLogger(limiterStatLogger.scope("rps_hard_limit")).limit(dynConf.getRpsHardWriteLimit()).overlimit(new OverlimitFunction<StreamOp>() {
@Override
public void apply(StreamOp op) throws OverCapacityException {
throw new OverCapacityException("RPS limit exceeded for stream " + streamName);
}
});
RequestLimiterBuilder rpsSoftLimiterBuilder = RequestLimiterBuilder.newRpsLimiterBuilder().statsLogger(limiterStatLogger.scope("rps_soft_limit")).limit(dynConf.getRpsSoftWriteLimit());
// BPS hard, soft limits
RequestLimiterBuilder bpsHardLimiterBuilder = RequestLimiterBuilder.newBpsLimiterBuilder().statsLogger(limiterStatLogger.scope("bps_hard_limit")).limit(dynConf.getBpsHardWriteLimit()).overlimit(new OverlimitFunction<StreamOp>() {
@Override
public void apply(StreamOp op) throws OverCapacityException {
throw new OverCapacityException("BPS limit exceeded for stream " + streamName);
}
});
RequestLimiterBuilder bpsSoftLimiterBuilder = RequestLimiterBuilder.newBpsLimiterBuilder().statsLogger(limiterStatLogger.scope("bps_soft_limit")).limit(dynConf.getBpsSoftWriteLimit());
ChainedRequestLimiter.Builder<StreamOp> builder = new ChainedRequestLimiter.Builder<StreamOp>();
builder.addLimiter(rpsSoftLimiterBuilder.build());
builder.addLimiter(rpsHardLimiterBuilder.build());
builder.addLimiter(bpsSoftLimiterBuilder.build());
builder.addLimiter(bpsHardLimiterBuilder.build());
builder.statsLogger(limiterStatLogger);
return builder.build();
}
Aggregations