Skip to content

Commit

Permalink
Merge pull request #803 from mattrjacobs/add-jmh-rolling-number
Browse files Browse the repository at this point in the history
Add jmh for rolling number and rolling max
  • Loading branch information
mattrjacobs committed May 29, 2015
2 parents 726466d + 4616fb0 commit e68ed42
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hystrix-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jmh {
fork = 10
iterations = 3
jmhVersion = '1.9.3'
profilers = ['gc']
//profilers = ['gc']
threads = 8
warmup = '1s'
warmupBatchSize = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.netflix.hystrix.perf;

import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.netflix.hystrix.util.HystrixRollingNumber;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.GroupThreads;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class RollingMaxPerfTest {
@State(Scope.Thread)
public static class CounterState {
HystrixRollingNumber counter;

@Setup(Level.Iteration)
public void setUp() {
counter = new HystrixRollingNumber(
HystrixProperty.Factory.asProperty(100),
HystrixProperty.Factory.asProperty(10));
}
}

@State(Scope.Thread)
public static class ValueState {
final Random r = new Random();

int value;

@Setup(Level.Invocation)
public void setUp() {
value = r.nextInt(100);
}
}

@Benchmark
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber writeOnly(CounterState counterState, ValueState valueState) {
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
return counterState.counter;
}

@Benchmark
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long readOnly(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
}

@Benchmark
@Group("writeHeavy")
@GroupThreads(7)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber writeHeavyUpdateMax(CounterState counterState, ValueState valueState) {
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("writeHeavy")
@GroupThreads(1)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long writeHeavyReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
}

@Benchmark
@Group("evenSplit")
@GroupThreads(4)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber evenSplitUpdateMax(CounterState counterState, ValueState valueState) {
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("evenSplit")
@GroupThreads(4)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long evenSplitReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
}

@Benchmark
@Group("readHeavy")
@GroupThreads(1)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber readHeavyUpdateMax(CounterState counterState, ValueState valueState) {
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("readHeavy")
@GroupThreads(7)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long readHeavyReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package com.netflix.hystrix.perf;

import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.netflix.hystrix.util.HystrixRollingNumber;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.GroupThreads;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class RollingNumberPerfTest {
@State(Scope.Thread)
public static class CounterState {
HystrixRollingNumber counter;

@Setup(Level.Iteration)
public void setUp() {
counter = new HystrixRollingNumber(
HystrixProperty.Factory.asProperty(100),
HystrixProperty.Factory.asProperty(10));
}
}

@State(Scope.Thread)
public static class ValueState {
final Random r = new Random();

int value;
HystrixRollingNumberEvent type;

@Setup(Level.Invocation)
public void setUp() {
value = r.nextInt(100);
int typeInt = r.nextInt(3);
switch(typeInt) {
case 0:
type = HystrixRollingNumberEvent.SUCCESS;
break;
case 1:
type = HystrixRollingNumberEvent.FAILURE;
break;
case 2:
type = HystrixRollingNumberEvent.TIMEOUT;
break;
default: throw new RuntimeException("Unexpected : " + typeInt);
}
}
}

@Benchmark
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber writeOnly(CounterState counterState, ValueState valueState) {
counterState.counter.add(valueState.type, valueState.value);
return counterState.counter;
}

@Benchmark
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long readOnly(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
}

@Benchmark
@Group("writeHeavy")
@GroupThreads(7)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber writeHeavyCounterAdd(CounterState counterState, ValueState valueState) {
counterState.counter.add(valueState.type, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("writeHeavy")
@GroupThreads(1)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long writeHeavyReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
}

@Benchmark
@Group("evenSplit")
@GroupThreads(4)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber evenSplitCounterAdd(CounterState counterState, ValueState valueState) {
counterState.counter.add(valueState.type, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("evenSplit")
@GroupThreads(4)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long evenSplitReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
}

@Benchmark
@Group("readHeavy")
@GroupThreads(1)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public HystrixRollingNumber readHeavyCounterAdd(CounterState counterState, ValueState valueState) {
counterState.counter.add(valueState.type, valueState.value);
return counterState.counter;
}

@Benchmark
@Group("readHeavy")
@GroupThreads(7)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public long readHeavyReadMetrics(CounterState counterState) {
HystrixRollingNumber counter = counterState.counter;
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
}
}

0 comments on commit e68ed42

Please sign in to comment.