Search in sources :

Example 6 with OverCapacityException

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);
}
Also used : SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 7 with OverCapacityException

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);
}
Also used : SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 8 with OverCapacityException

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();
}
Also used : ChainedRequestLimiter(com.twitter.distributedlog.limiter.ChainedRequestLimiter) StreamOp(com.twitter.distributedlog.service.stream.StreamOp) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException)

Aggregations

OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)8 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)5 Test (org.junit.Test)4 ChainedRequestLimiter (com.twitter.distributedlog.limiter.ChainedRequestLimiter)2 StreamOp (com.twitter.distributedlog.service.stream.StreamOp)2 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)2 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 StreamNotReadyException (com.twitter.distributedlog.exceptions.StreamNotReadyException)1 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)1 Future (com.twitter.util.Future)1 ArrayList (java.util.ArrayList)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1