-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #803 from mattrjacobs/add-jmh-rolling-number
Add jmh for rolling number and rolling max
- Loading branch information
Showing
3 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
hystrix-core/src/jmh/java/com/netflix/hystrix/perf/RollingMaxPerfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
hystrix-core/src/jmh/java/com/netflix/hystrix/perf/RollingNumberPerfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |