Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ subprojects {
apply plugin: 'nebula.provided-base'
apply plugin: 'nebula.compile-api'

sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.8
targetCompatibility = 1.8



Expand Down
15 changes: 15 additions & 0 deletions hystrix-contrib/hystrix-codahale-metrics-publisher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
apply plugin: 'maven'

dependencies {
compileApi project(':hystrix-core')
compileApi 'io.dropwizard.metrics:metrics-core:3.2.2'
testCompile 'junit:junit-dep:4.10'
testCompile 'org.mockito:mockito-all:1.9.5'
}

uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://clojars.org/repo"){
authentication(userName: "", password: "")
}
pom.version = '1.5.11-22'
pom.groupId = 'org.hystrix'
pom.artifactId = 'hystrix-codahale-metrics-publisher'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ public Integer getValue() {
return metrics.getExecutionTimePercentile(90);
}
});
metricRegistry.register(createMetricName("latencyExecute_percentile_95"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(95);
}
});
metricRegistry.register(createMetricName("latencyExecute_percentile_99"), new Gauge<Integer>() {
@Override
public Integer getValue() {
Expand Down Expand Up @@ -382,6 +388,12 @@ public Integer getValue() {
return metrics.getTotalTimePercentile(90);
}
});
metricRegistry.register(createMetricName("latencyTotal_percentile_95"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(95);
}
});
metricRegistry.register(createMetricName("latencyTotal_percentile_99"), new Gauge<Integer>() {
@Override
public Integer getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherThreadPool;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,6 +37,7 @@ public class HystrixCodaHaleMetricsPublisherThreadPool implements HystrixMetrics
private final MetricRegistry metricRegistry;
private final String metricGroup;
private final String metricType;
private List<String> metricsList = new ArrayList<>();

static final Logger logger = LoggerFactory.getLogger(HystrixCodaHaleMetricsPublisherThreadPool.class);

Expand Down Expand Up @@ -142,14 +145,14 @@ public Number getValue() {
metricRegistry.register(createMetricName("propertyValue_corePoolSize"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.coreSize().get();
return metrics.getCurrentCorePoolSize();
}
});

metricRegistry.register(createMetricName("propertyValue_maximumSize"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.maximumSize().get();
return metrics.getCurrentMaximumPoolSize();
}
});

Expand Down Expand Up @@ -183,6 +186,8 @@ public Number getValue() {
}

protected String createMetricName(String name) {
return MetricRegistry.name(metricGroup, metricType, name);
String metricName = MetricRegistry.name(metricGroup, metricType, name);
metricsList.add(metricName);
return metricName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
* Implementation of {@link HystrixMetricsPublisherThreadPool} using Yammer Metrics (https://github.com/codahale/metrics)
*/
Expand All @@ -36,6 +39,7 @@ public class HystrixYammerMetricsPublisherThreadPool implements HystrixMetricsPu
private final MetricsRegistry metricsRegistry;
private final String metricGroup;
private final String metricType;
private List<MetricName> metricsList = new ArrayList<>();

static final Logger logger = LoggerFactory.getLogger(HystrixYammerMetricsPublisherThreadPool.class);

Expand Down
36 changes: 36 additions & 0 deletions hystrix-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
buildscript {
repositories {
jcenter()
maven{
name 'clojars'
url 'http://clojars.org/repo'
}
}
dependencies {
classpath 'com.netflix.nebula:nebula-clojure-plugin:4.0.1'
}
}
apply plugin: 'nebula.clojure' // this is a wrapper around clojuresque to make it behave well with other plugins

repositories {
mavenCentral()
clojarsRepo()
}

apply plugin: 'osgi'
apply plugin: 'me.champeau.gradle.jmh'

Expand All @@ -11,6 +30,23 @@ dependencies {
}


version = '1.5.0'
apply plugin: "groovy"
apply plugin: 'maven'

uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://clojars.org/repo"){
authentication(userName: "", password: "")
}
pom.version = '1.5.11-22'
pom.groupId = 'org.hystrix'
pom.artifactId = 'hystrix-core'
}
}
}

javadoc {
// the exclude isn't working, nor is there a subPackages options as docs suggest there should be
// we do not want the com.netflix.hystrix.util package include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import rx.Observable;
import rx.Subscription;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -52,7 +51,7 @@ public static class ThreadPoolState {
public void setUp() {
hystrixThreadPool = new HystrixThreadPool.HystrixThreadPoolDefault(
HystrixThreadPoolKey.Factory.asKey("PERF")
, HystrixThreadPoolProperties.Setter().withCoreSize(100));
, HystrixThreadPoolProperties.Setter().withCoreSize(100), false);
}

@TearDown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static class ThreadPoolState {
public void setUp() {
hystrixThreadPool = new HystrixThreadPool.HystrixThreadPoolDefault(
HystrixThreadPoolKey.Factory.asKey("PERF")
, HystrixThreadPoolProperties.Setter().withCoreSize(100));
, HystrixThreadPoolProperties.Setter().withCoreSize(100), false);
}

@TearDown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ public interface HystrixThreadPool {
*/
/* package */final static ConcurrentHashMap<String, HystrixThreadPool> threadPools = new ConcurrentHashMap<String, HystrixThreadPool>();

/*
* Use the String from HystrixThreadPoolKey.name() instead of the HystrixThreadPoolKey instance as it's just an interface and we can't ensure the object
* we receive implements hashcode/equals correctly and do not want the default hashcode/equals which would create a new threadpool for every object we get even if the name is the same
*/
final static ConcurrentHashMap<String, HystrixThreadPoolProperties.Setter> threadPoolProperties =
new ConcurrentHashMap<String, HystrixThreadPoolProperties.Setter>();

/**
* Get the {@link HystrixThreadPool} instance for a given {@link HystrixThreadPoolKey}.
* <p>
Expand All @@ -102,17 +109,25 @@ public interface HystrixThreadPool {
/* package */static HystrixThreadPool getInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter propertiesBuilder) {
// get the key to use instead of using the object itself so that if people forget to implement equals/hashcode things will still work
String key = threadPoolKey.name();

HystrixThreadPoolProperties.Setter oldPropertiesBuilder = threadPoolProperties.get(key);
boolean updated = oldPropertiesBuilder != null && !oldPropertiesBuilder.equals(propertiesBuilder);
// this should find it for all but the first time
HystrixThreadPool previouslyCached = threadPools.get(key);
if (previouslyCached != null) {
if(updated && previouslyCached instanceof HystrixThreadPoolDefault){
threadPoolProperties.put(key, propertiesBuilder);
((HystrixThreadPoolDefault)previouslyCached).touchConfig(threadPoolKey, propertiesBuilder);
}
return previouslyCached;
}

// if we get here this is the first time so we need to initialize
synchronized (HystrixThreadPool.class) {
if (!threadPools.containsKey(key)) {
threadPools.put(key, new HystrixThreadPoolDefault(threadPoolKey, propertiesBuilder));
threadPools.put(key, new HystrixThreadPoolDefault(threadPoolKey, propertiesBuilder, updated));
if(propertiesBuilder != null){
threadPoolProperties.put(key, propertiesBuilder);
}
}
}
return threadPools.get(key);
Expand Down Expand Up @@ -162,14 +177,15 @@ public interface HystrixThreadPool {
/* package */static class HystrixThreadPoolDefault implements HystrixThreadPool {
private static final Logger logger = LoggerFactory.getLogger(HystrixThreadPoolDefault.class);

private final HystrixThreadPoolProperties properties;
private HystrixThreadPoolProperties properties;
private final BlockingQueue<Runnable> queue;
private final ThreadPoolExecutor threadPool;
private final HystrixThreadPoolMetrics metrics;
private final int queueSize;

public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter propertiesDefaults) {
this.properties = HystrixPropertiesFactory.getThreadPoolProperties(threadPoolKey, propertiesDefaults);
public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter propertiesDefaults,
boolean updated) {
this.properties = HystrixPropertiesFactory.getThreadPoolProperties(threadPoolKey, propertiesDefaults, updated);
HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
this.queueSize = properties.maxQueueSize().get();

Expand Down Expand Up @@ -206,6 +222,12 @@ public Scheduler getScheduler(Func0<Boolean> shouldInterruptThread) {
return new HystrixContextScheduler(HystrixPlugins.getInstance().getConcurrencyStrategy(), this, shouldInterruptThread);
}

private void touchConfig(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter newProperties) {
this.properties = HystrixPropertiesFactory.getThreadPoolProperties(threadPoolKey, newProperties,
true);
touchConfig();
}

// allow us to change things via fast-properties by setting it each time
private void touchConfig() {
final int dynamicCoreSize = properties.coreSize().get();
Expand All @@ -219,9 +241,10 @@ private void touchConfig() {
dynamicMaximumSize = dynamicCoreSize;
maxTooLow = true;
}

// In JDK 6, setCorePoolSize and setMaximumPoolSize will execute a lock operation. Avoid them if the pool size is not changed.
if (threadPool.getCorePoolSize() != dynamicCoreSize || (allowSizesToDiverge && threadPool.getMaximumPoolSize() != dynamicMaximumSize)) {
logger.info("Old core pool : {}, new core pool : {}, old max : {}, new max {}" ,
threadPool.getCorePoolSize(), dynamicCoreSize, threadPool.getMaximumPoolSize(), dynamicMaximumSize);
if (maxTooLow) {
logger.error("Hystrix ThreadPool configuration for : " + metrics.getThreadPoolKey().name() + " is trying to set coreSize = " +
dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ". Maximum size will be set to " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,31 @@ public Setter withMetricsRollingStatisticalWindowBuckets(int value) {
return this;
}

@Override
public boolean equals(Object o) {
if(this == o)
return true;
if(!(o instanceof Setter))
return false;

Setter setter = (Setter)o;

if(!coreSize.equals(setter.coreSize))
return false;
if(!maximumSize.equals(setter.maximumSize))
return false;
if(!keepAliveTimeMinutes.equals(setter.keepAliveTimeMinutes))
return false;
return maxQueueSize.equals(setter.maxQueueSize);
}



@Override
public int hashCode() {
int result = coreSize.hashCode();
result = 31 * result + maximumSize.hashCode();
result = 31 * result + keepAliveTimeMinutes.hashCode();
result = 31 * result + maxQueueSize.hashCode();
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,29 @@ public static HystrixCommandProperties getCommandProperties(HystrixCommandKey ke
* Pass-thru to {@link HystrixPropertiesStrategy#getThreadPoolProperties} implementation.
* @param builder
* Pass-thru to {@link HystrixPropertiesStrategy#getThreadPoolProperties} implementation.
* @param updated
* @return {@link HystrixThreadPoolProperties} instance
*/
public static HystrixThreadPoolProperties getThreadPoolProperties(HystrixThreadPoolKey key, HystrixThreadPoolProperties.Setter builder) {
public static HystrixThreadPoolProperties getThreadPoolProperties(HystrixThreadPoolKey key, HystrixThreadPoolProperties.Setter builder,
boolean updated) {
HystrixPropertiesStrategy hystrixPropertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
String cacheKey = hystrixPropertiesStrategy.getThreadPoolPropertiesCacheKey(key, builder);
if (cacheKey != null) {
HystrixThreadPoolProperties properties = threadPoolProperties.get(cacheKey);
if (properties != null) {
if (properties != null && !updated) {
return properties;
} else {
if (builder == null) {
builder = HystrixThreadPoolProperties.Setter();
}
// create new instance
properties = hystrixPropertiesStrategy.getThreadPoolProperties(key, builder);
// cache and return
HystrixThreadPoolProperties existing = threadPoolProperties.putIfAbsent(cacheKey, properties);
if (existing == null) {
synchronized (HystrixPropertiesFactory.class){
// create new instance
properties = hystrixPropertiesStrategy.getThreadPoolProperties(key, builder);
// cache and return
threadPoolProperties.put(cacheKey, properties);
return properties;
} else {
return existing;
}

}
} else {
// no cacheKey so we generate it with caching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(Hystri
});
HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("threadPoolFactoryConcurrencyTest");
HystrixThreadPool poolOne = new HystrixThreadPool.HystrixThreadPoolDefault(
threadPoolKey, HystrixThreadPoolPropertiesTest.getUnitTestPropertiesBuilder());
threadPoolKey, HystrixThreadPoolPropertiesTest.getUnitTestPropertiesBuilder(), false);
HystrixThreadPool poolTwo = new HystrixThreadPool.HystrixThreadPoolDefault(
threadPoolKey, HystrixThreadPoolPropertiesTest.getUnitTestPropertiesBuilder());
threadPoolKey, HystrixThreadPoolPropertiesTest.getUnitTestPropertiesBuilder(), false);

assertThat(poolOne.getExecutor(), is(poolTwo.getExecutor())); //Now that we get the threadPool from the metrics object, this will always be equal
HystrixMetricsPublisherThreadPoolContainer hystrixMetricsPublisherThreadPool =
Expand Down