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());
}
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());
}
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);
}
}
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();
}
Aggregations