Search in sources :

Example 41 with HystrixThreadPoolKey

use of com.netflix.hystrix.HystrixThreadPoolKey in project Hystrix by Netflix.

the class RollingThreadPoolMaxConcurrencyStreamTest method testMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools.

/**
     * BUCKETS
     *     A    |    B    |    C    |    D    |    E    |
     * 1:  [-------------------------------]              ThreadPool x
     * 2:          [-------------------------------]                 y
     * 3:                      [--]                                  x
     * 4:                              [--]                          x
     *
     * Same input data as above test, just that command 2 runs in a separate threadpool, so concurrency should not get tracked
     * Max concurrency should be 2 for x
     */
@Test
public void testMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools() throws InterruptedException {
    HystrixCommandGroupKey groupKeyX = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-X");
    HystrixCommandGroupKey groupKeyY = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-Y");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-X");
    HystrixCommandKey keyX = HystrixCommandKey.Factory.asKey("RollingConcurrency-X");
    HystrixCommandKey keyY = HystrixCommandKey.Factory.asKey("RollingConcurrency-Y");
    stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    Command cmd1 = Command.from(groupKeyX, keyX, HystrixEventType.SUCCESS, 300);
    Command cmd2 = Command.from(groupKeyY, keyY, HystrixEventType.SUCCESS, 300);
    Command cmd3 = Command.from(groupKeyX, keyY, HystrixEventType.SUCCESS, 10);
    Command cmd4 = Command.from(groupKeyX, keyY, HystrixEventType.SUCCESS, 10);
    cmd1.observe();
    //bucket roll
    Thread.sleep(100);
    cmd2.observe();
    Thread.sleep(100);
    cmd3.observe();
    Thread.sleep(100);
    cmd4.observe();
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(2, stream.getLatestRollingMax());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 42 with HystrixThreadPoolKey

use of com.netflix.hystrix.HystrixThreadPoolKey in project Hystrix by Netflix.

the class RollingThreadPoolMaxConcurrencyStreamTest method testMultipleCommandsCarryOverMultipleBuckets.

/**
     * BUCKETS
     *     A    |    B    |    C    |    D    |    E    |
     * 1:  [-------------------------------]
     * 2:          [-------------------------------]
     * 3:                      [--]
     * 4:                              [--]
     *
     * Max concurrency should be 3
     */
@Test
public void testMultipleCommandsCarryOverMultipleBuckets() throws InterruptedException {
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-E");
    HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-E");
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-E");
    stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 300);
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 300);
    Command cmd3 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    Command cmd4 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    cmd1.observe();
    //bucket roll
    Thread.sleep(100);
    cmd2.observe();
    Thread.sleep(100);
    cmd3.observe();
    Thread.sleep(100);
    cmd4.observe();
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(3, stream.getLatestRollingMax());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) CountDownLatch(java.util.concurrent.CountDownLatch) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 43 with HystrixThreadPoolKey

use of com.netflix.hystrix.HystrixThreadPoolKey in project Hystrix by Netflix.

the class SerialHystrixUtilization method serializeUtilization.

private static void serializeUtilization(HystrixUtilization utilization, JsonGenerator json) {
    try {
        json.writeStartObject();
        json.writeStringField("type", "HystrixUtilization");
        json.writeObjectFieldStart("commands");
        for (Map.Entry<HystrixCommandKey, HystrixCommandUtilization> entry : utilization.getCommandUtilizationMap().entrySet()) {
            final HystrixCommandKey key = entry.getKey();
            final HystrixCommandUtilization commandUtilization = entry.getValue();
            writeCommandUtilizationJson(json, key, commandUtilization);
        }
        json.writeEndObject();
        json.writeObjectFieldStart("threadpools");
        for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolUtilization> entry : utilization.getThreadPoolUtilizationMap().entrySet()) {
            final HystrixThreadPoolKey threadPoolKey = entry.getKey();
            final HystrixThreadPoolUtilization threadPoolUtilization = entry.getValue();
            writeThreadPoolUtilizationJson(json, threadPoolKey, threadPoolUtilization);
        }
        json.writeEndObject();
        json.writeEndObject();
        json.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixThreadPoolUtilization(com.netflix.hystrix.metric.sample.HystrixThreadPoolUtilization) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) Map(java.util.Map) HystrixCommandUtilization(com.netflix.hystrix.metric.sample.HystrixCommandUtilization) IOException(java.io.IOException)

Example 44 with HystrixThreadPoolKey

use of com.netflix.hystrix.HystrixThreadPoolKey in project ratpack by ratpack.

the class HystrixThreadPoolMetricsJsonMapper method apply.

@Override
public String apply(HystrixThreadPoolMetrics threadPoolMetrics) throws Exception {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createGenerator(jsonString);
    json.writeStartObject();
    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());
    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount", threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    json.writeNumberField("rollingCountThreadsExecuted", threadPoolMetrics.getRollingCount(HystrixRollingNumberEvent.THREAD_EXECUTION));
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());
    json.writeNumberField("rollingCountCommandRejections", threadPoolMetrics.getRollingCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED));
    json.writeNumberField("propertyValue_queueSizeRejectionThreshold", threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());
    // this will get summed across all instances in a cluster
    json.writeNumberField("reportingHosts", 1);
    json.writeEndObject();
    json.close();
    return jsonString.getBuffer().toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey)

Aggregations

HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)44 HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)42 HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)38 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)37 CountDownLatch (java.util.concurrent.CountDownLatch)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)9 Map (java.util.Map)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)3 StringWriter (java.io.StringWriter)3 HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)2 HystrixCollapserConfiguration (com.netflix.hystrix.config.HystrixCollapserConfiguration)2 HystrixCommandConfiguration (com.netflix.hystrix.config.HystrixCommandConfiguration)2 HystrixThreadPoolConfiguration (com.netflix.hystrix.config.HystrixThreadPoolConfiguration)2 HystrixCommandUtilization (com.netflix.hystrix.metric.sample.HystrixCommandUtilization)2 HystrixThreadPoolUtilization (com.netflix.hystrix.metric.sample.HystrixThreadPoolUtilization)2 IOException (java.io.IOException)2 HystrixCommand (com.netflix.hystrix.HystrixCommand)1 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)1