use of com.github.ambry.config.PerformanceConfig in project ambry by linkedin.
the class MockChannelHandlerContext method requestPerformanceEvaluationTest.
/**
* Tests that requests can be correctly evaluated based on their performance (i.e. latency, bandwidth)
* @throws Exception
*/
@Test
public void requestPerformanceEvaluationTest() throws Exception {
long BANDWIDTH_THRESHOLD = 500L;
long TIME_TO_FIRST_BYTE_THRESHOLD = 30L;
String content = "@@randomContent@@@";
MockNettyRequest.inboundBytes = content.length();
Properties properties = new Properties();
properties.put("performance.success.post.average.bandwidth.threshold", Long.toString(BANDWIDTH_THRESHOLD));
properties.put("performance.success.get.average.bandwidth.threshold", Long.toString(BANDWIDTH_THRESHOLD));
properties.put("performance.success.get.time.to.first.byte.threshold", Long.toString(TIME_TO_FIRST_BYTE_THRESHOLD));
properties.put(PerformanceConfig.NON_SUCCESS_REST_REQUEST_TOTAL_TIME_THRESHOLD_STR, "{\"PUT\": \"35\",\"GET\": \"35\",\"POST\": \"35\",\"HEAD\": \"35\",\"DELETE\": \"35\"}");
properties.put(PerformanceConfig.SUCCESS_REST_REQUEST_TOTAL_TIME_THRESHOLD_STR, "{\"PUT\": \"35\",\"GET\": \"35\",\"POST\": \"35\",\"HEAD\": \"35\",\"DELETE\": \"35\"}");
PerformanceConfig config = new PerformanceConfig(new VerifiableProperties(properties));
MockNettyMessageProcessor.useMockNettyRequest = true;
MockNettyMessageProcessor.PERFORMANCE_CONFIG = config;
// test "Satisfied" requests
MockNettyRequest.roundTripTime = 30L;
MockNettyRequest.timeToFirstByte = 25L;
verifySatisfactionOfRequests(content, true);
// test "Unsatisfied" requests
MockNettyRequest.roundTripTime = 40L;
MockNettyRequest.timeToFirstByte = 36L;
verifySatisfactionOfRequests(content, false);
// use OPTIONS request as an example, which should skip evaluation and mark as satisfied directly
HttpRequest httpRequest = RestTestUtils.createFullRequest(HttpMethod.OPTIONS, TestingUri.ImmediateResponseComplete.toString(), null, TestUtils.getRandomBytes(18));
sendRequestAndEvaluateResponsePerformance(httpRequest, null, HttpResponseStatus.OK, true);
}
use of com.github.ambry.config.PerformanceConfig in project ambry by linkedin.
the class MockChannelHandlerContext method channelInactiveTest.
/**
* ClosedChannelException is expected when write to a NettyResponseChannel and channel is inactive.
*/
@Test
public void channelInactiveTest() {
// request is keep-alive by default.
HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.Close.toString());
ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler();
EmbeddedChannel channel = new EmbeddedChannel(chunkedWriteHandler);
VerifiableProperties verifiableProperties = new VerifiableProperties(new Properties());
NettyResponseChannel nettyResponseChannel = new NettyResponseChannel(new MockChannelHandlerContext(channel), new NettyMetrics(new MetricRegistry()), new PerformanceConfig(verifiableProperties), new NettyConfig(verifiableProperties));
channel.disconnect().awaitUninterruptibly();
assertFalse("Channel should be closed", channel.isOpen());
Future<Long> future = nettyResponseChannel.write(Unpooled.buffer(1), null);
try {
future.get();
fail("Future.get() should throw exception.");
} catch (InterruptedException | ExecutionException e) {
assertTrue("Should be ClosedChannelException", e.getCause() instanceof ClosedChannelException);
}
}
use of com.github.ambry.config.PerformanceConfig in project ambry by linkedin.
the class NettyServerTest method getNettyServer.
// helpers
// general
/**
* Gets an instance of {@link NettyServer}.
* @param properties the in-memory {@link Properties} to use.
* @return an instance of {@link NettyServer}.
* @throws InstantiationException
* @throws IOException
*/
private NettyServer getNettyServer(Properties properties) throws InstantiationException, IOException {
if (properties == null) {
// dud properties. should pick up defaults
properties = new Properties();
}
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
final NettyConfig nettyConfig = new NettyConfig(verifiableProperties);
final PerformanceConfig performanceConfig = new PerformanceConfig(verifiableProperties);
Map<Integer, ChannelInitializer<SocketChannel>> channelInitializers = new HashMap<>();
channelInitializers.put(nettyConfig.nettyServerPort, new FrontendNettyChannelInitializer(nettyConfig, performanceConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, null, null));
channelInitializers.put(nettyConfig.nettyServerSSLPort, new FrontendNettyChannelInitializer(nettyConfig, performanceConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY, null));
return new NettyServer(nettyConfig, NETTY_METRICS, channelInitializers);
}
use of com.github.ambry.config.PerformanceConfig in project ambry by linkedin.
the class ThresholdsTest method defaultPerformanceConfigTest.
/**
* Test that {@link PerformanceConfig} can correctly populate thresholds with default value. This is to ensure JSONObject
* can parse the long value from default strings.
*/
@Test
public void defaultPerformanceConfigTest() {
// purposely use empty properties to make config use default value
VerifiableProperties properties = new VerifiableProperties(new Properties());
PerformanceConfig config = new PerformanceConfig(properties);
for (RestMethod method : EnumSet.of(RestMethod.GET, RestMethod.DELETE, RestMethod.POST, RestMethod.HEAD, RestMethod.PUT)) {
Criteria criteria = config.nonSuccessRequestThresholds.get(method).getCriteria(PerformanceIndex.RoundTripTime);
assertEquals("Threshold value is not as expected", criteria.getThresholdValue(), Long.MAX_VALUE);
}
// verify default GET time to first byte is Long.MAX_VALUE
assertEquals("Threshold value is not as expected", config.successGetTimeToFirstByteThreshold, Long.MAX_VALUE);
// verify default GET/POST average bandwidth is 0
assertEquals("Threshold value is not as expected", config.successGetAverageBandwidthThreshold, 0);
assertEquals("Threshold value is not as expected", config.successPostAverageBandwidthThreshold, 0);
}
Aggregations