use of com.twitter.distributedlog.service.stream.StreamOp in project distributedlog by twitter.
the class ServiceRequestLimiter method build.
@Override
public RequestLimiter<StreamOp> build() {
int rpsStreamAcquireLimit = dynConf.getRpsStreamAcquireServiceLimit();
int rpsSoftServiceLimit = dynConf.getRpsSoftServiceLimit();
int rpsHardServiceLimit = dynConf.getRpsHardServiceLimit();
int bpsStreamAcquireLimit = dynConf.getBpsStreamAcquireServiceLimit();
int bpsSoftServiceLimit = dynConf.getBpsSoftServiceLimit();
int bpsHardServiceLimit = dynConf.getBpsHardServiceLimit();
RequestLimiterBuilder rpsHardLimiterBuilder = RequestLimiterBuilder.newRpsLimiterBuilder().statsLogger(limiterStatLogger.scope("rps_hard_limit")).limit(rpsHardServiceLimit).overlimit(new OverlimitFunction<StreamOp>() {
@Override
public void apply(StreamOp request) throws OverCapacityException {
throw new OverCapacityException("RPS limit exceeded for the service instance");
}
});
RequestLimiterBuilder rpsSoftLimiterBuilder = RequestLimiterBuilder.newRpsLimiterBuilder().statsLogger(limiterStatLogger.scope("rps_soft_limit")).limit(rpsSoftServiceLimit);
RequestLimiterBuilder bpsHardLimiterBuilder = RequestLimiterBuilder.newBpsLimiterBuilder().statsLogger(limiterStatLogger.scope("bps_hard_limit")).limit(bpsHardServiceLimit).overlimit(new OverlimitFunction<StreamOp>() {
@Override
public void apply(StreamOp request) throws OverCapacityException {
throw new OverCapacityException("BPS limit exceeded for the service instance");
}
});
RequestLimiterBuilder bpsSoftLimiterBuilder = RequestLimiterBuilder.newBpsLimiterBuilder().statsLogger(limiterStatLogger.scope("bps_soft_limit")).limit(bpsSoftServiceLimit);
ChainedRequestLimiter.Builder<StreamOp> builder = new ChainedRequestLimiter.Builder<StreamOp>();
builder.addLimiter(new StreamAcquireLimiter(streamManager, serviceRps, rpsStreamAcquireLimit, limiterStatLogger.scope("rps_acquire")));
builder.addLimiter(new StreamAcquireLimiter(streamManager, serviceBps, bpsStreamAcquireLimit, limiterStatLogger.scope("bps_acquire")));
builder.addLimiter(bpsHardLimiterBuilder.build());
builder.addLimiter(bpsSoftLimiterBuilder.build());
builder.addLimiter(rpsHardLimiterBuilder.build());
builder.addLimiter(rpsSoftLimiterBuilder.build());
builder.statsLogger(limiterStatLogger);
return builder.build();
}
use of com.twitter.distributedlog.service.stream.StreamOp 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