Search in sources :

Example 1 with PerformanceConfig

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);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) VerifiableProperties(com.github.ambry.config.VerifiableProperties) PerformanceConfig(com.github.ambry.config.PerformanceConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 2 with PerformanceConfig

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);
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) ClosedChannelException(java.nio.channels.ClosedChannelException) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) NettyConfig(com.github.ambry.config.NettyConfig) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) PerformanceConfig(com.github.ambry.config.PerformanceConfig) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with PerformanceConfig

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HashMap(java.util.HashMap) PerformanceConfig(com.github.ambry.config.PerformanceConfig) ChannelInitializer(io.netty.channel.ChannelInitializer) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) NettyConfig(com.github.ambry.config.NettyConfig)

Example 4 with PerformanceConfig

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) PerformanceConfig(com.github.ambry.config.PerformanceConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RestMethod(com.github.ambry.rest.RestMethod) Test(org.junit.Test)

Aggregations

PerformanceConfig (com.github.ambry.config.PerformanceConfig)4 VerifiableProperties (com.github.ambry.config.VerifiableProperties)4 Properties (java.util.Properties)4 Test (org.junit.Test)3 NettyConfig (com.github.ambry.config.NettyConfig)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 RestMethod (com.github.ambry.rest.RestMethod)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1