我试图理解HystrixCommand和HystrixObservableCommand之间的区别.我感到困惑的原因是HysterixCommand还有一个observe()或toObservable()方法,它们分别发出冷热观察.那么需要创建HystrixObservableCommand.如果我将完全处理非阻塞呼叫,我应该使用哪一个?为什么?
我已经成为Java 8中Java函数编程以及Rx java的忠实粉丝.但是一位同事最近指出,使用这些产品会影响性能.因此决定运行JMH Bench标记,但看起来他是对的.无论我做什么,我都无法获得流版本以提供更好的性能.以下是我的代码
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
@OperationsPerInvocation(StreamVsVanilla.N)
public class StreamVsVanilla {
public static final int N = 10000;
static List<Integer> sourceList = new ArrayList<>(N);
static {
for (int i = 0; i < N; i++) {
sourceList.add(i);
}
}
@Benchmark
public List<Double> vanilla() {
List<Double> result = new ArrayList<Double>(sourceList.size() / 2 + 1);
for (Integer i : sourceList) {
if (i % 2 == 0){
result.add(Math.sqrt(i));
}
}
return result;
}
@Benchmark
public List<Double> stream() {
return sourceList.stream().parallel()
.mapToInt(Integer::intValue)
.filter(i …Run Code Online (Sandbox Code Playgroud)