Skip to content

Commit 4616fb0

Browse files
author
Matt Jacobs
committed
Fix method names in jmh tests
1 parent 6188fc9 commit 4616fb0

File tree

3 files changed

+145
-17
lines changed

3 files changed

+145
-17
lines changed

hystrix-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jmh {
3838
fork = 10
3939
iterations = 3
4040
jmhVersion = '1.9.3'
41-
profilers = ['gc']
41+
//profilers = ['gc']
4242
threads = 8
4343
warmup = '1s'
4444
warmupBatchSize = 1
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.netflix.hystrix.perf;
2+
3+
import com.netflix.hystrix.strategy.properties.HystrixProperty;
4+
import com.netflix.hystrix.util.HystrixRollingNumber;
5+
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
6+
import org.openjdk.jmh.annotations.Benchmark;
7+
import org.openjdk.jmh.annotations.BenchmarkMode;
8+
import org.openjdk.jmh.annotations.Group;
9+
import org.openjdk.jmh.annotations.GroupThreads;
10+
import org.openjdk.jmh.annotations.Level;
11+
import org.openjdk.jmh.annotations.Mode;
12+
import org.openjdk.jmh.annotations.OutputTimeUnit;
13+
import org.openjdk.jmh.annotations.Scope;
14+
import org.openjdk.jmh.annotations.Setup;
15+
import org.openjdk.jmh.annotations.State;
16+
17+
import java.util.Random;
18+
import java.util.concurrent.TimeUnit;
19+
20+
public class RollingMaxPerfTest {
21+
@State(Scope.Thread)
22+
public static class CounterState {
23+
HystrixRollingNumber counter;
24+
25+
@Setup(Level.Iteration)
26+
public void setUp() {
27+
counter = new HystrixRollingNumber(
28+
HystrixProperty.Factory.asProperty(100),
29+
HystrixProperty.Factory.asProperty(10));
30+
}
31+
}
32+
33+
@State(Scope.Thread)
34+
public static class ValueState {
35+
final Random r = new Random();
36+
37+
int value;
38+
39+
@Setup(Level.Invocation)
40+
public void setUp() {
41+
value = r.nextInt(100);
42+
}
43+
}
44+
45+
@Benchmark
46+
@BenchmarkMode({Mode.Throughput})
47+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
48+
public HystrixRollingNumber writeOnly(CounterState counterState, ValueState valueState) {
49+
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
50+
return counterState.counter;
51+
}
52+
53+
@Benchmark
54+
@BenchmarkMode({Mode.Throughput})
55+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
56+
public long readOnly(CounterState counterState) {
57+
HystrixRollingNumber counter = counterState.counter;
58+
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
59+
}
60+
61+
@Benchmark
62+
@Group("writeHeavy")
63+
@GroupThreads(7)
64+
@BenchmarkMode({Mode.Throughput})
65+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
66+
public HystrixRollingNumber writeHeavyUpdateMax(CounterState counterState, ValueState valueState) {
67+
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
68+
return counterState.counter;
69+
}
70+
71+
@Benchmark
72+
@Group("writeHeavy")
73+
@GroupThreads(1)
74+
@BenchmarkMode({Mode.Throughput})
75+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
76+
public long writeHeavyReadMetrics(CounterState counterState) {
77+
HystrixRollingNumber counter = counterState.counter;
78+
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
79+
}
80+
81+
@Benchmark
82+
@Group("evenSplit")
83+
@GroupThreads(4)
84+
@BenchmarkMode({Mode.Throughput})
85+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
86+
public HystrixRollingNumber evenSplitUpdateMax(CounterState counterState, ValueState valueState) {
87+
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
88+
return counterState.counter;
89+
}
90+
91+
@Benchmark
92+
@Group("evenSplit")
93+
@GroupThreads(4)
94+
@BenchmarkMode({Mode.Throughput})
95+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
96+
public long evenSplitReadMetrics(CounterState counterState) {
97+
HystrixRollingNumber counter = counterState.counter;
98+
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
99+
}
100+
101+
@Benchmark
102+
@Group("readHeavy")
103+
@GroupThreads(1)
104+
@BenchmarkMode({Mode.Throughput})
105+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
106+
public HystrixRollingNumber readHeavyUpdateMax(CounterState counterState, ValueState valueState) {
107+
counterState.counter.updateRollingMax(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE, valueState.value);
108+
return counterState.counter;
109+
}
110+
111+
@Benchmark
112+
@Group("readHeavy")
113+
@GroupThreads(7)
114+
@BenchmarkMode({Mode.Throughput})
115+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
116+
public long readHeavyReadMetrics(CounterState counterState) {
117+
HystrixRollingNumber counter = counterState.counter;
118+
return counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE);
119+
}
120+
}

hystrix-core/src/jmh/java/com/netflix/hystrix/perf/RollingNumberPerfTest.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import com.netflix.hystrix.strategy.properties.HystrixProperty;
44
import com.netflix.hystrix.util.HystrixRollingNumber;
55
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
6-
import com.netflix.hystrix.util.HystrixRollingPercentile;
76
import org.openjdk.jmh.annotations.Benchmark;
87
import org.openjdk.jmh.annotations.BenchmarkMode;
98
import org.openjdk.jmh.annotations.Group;
109
import org.openjdk.jmh.annotations.GroupThreads;
1110
import org.openjdk.jmh.annotations.Level;
1211
import org.openjdk.jmh.annotations.Mode;
1312
import org.openjdk.jmh.annotations.OutputTimeUnit;
14-
import org.openjdk.jmh.annotations.Param;
1513
import org.openjdk.jmh.annotations.Scope;
1614
import org.openjdk.jmh.annotations.Setup;
1715
import org.openjdk.jmh.annotations.State;
@@ -44,9 +42,15 @@ public void setUp() {
4442
value = r.nextInt(100);
4543
int typeInt = r.nextInt(3);
4644
switch(typeInt) {
47-
case 0: type = HystrixRollingNumberEvent.SUCCESS;
48-
case 1: type = HystrixRollingNumberEvent.FAILURE;
49-
case 2: type = HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE;
45+
case 0:
46+
type = HystrixRollingNumberEvent.SUCCESS;
47+
break;
48+
case 1:
49+
type = HystrixRollingNumberEvent.FAILURE;
50+
break;
51+
case 2:
52+
type = HystrixRollingNumberEvent.TIMEOUT;
53+
break;
5054
default: throw new RuntimeException("Unexpected : " + typeInt);
5155
}
5256
}
@@ -67,17 +71,18 @@ public long readOnly(CounterState counterState) {
6771
HystrixRollingNumber counter = counterState.counter;
6872
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
6973
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
70-
counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE) +
74+
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
7175
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
72-
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE);
76+
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
77+
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
7378
}
7479

7580
@Benchmark
7681
@Group("writeHeavy")
7782
@GroupThreads(7)
7883
@BenchmarkMode({Mode.Throughput})
7984
@OutputTimeUnit(TimeUnit.MILLISECONDS)
80-
public HystrixRollingNumber writeHeavyLatencyAdd(CounterState counterState, ValueState valueState) {
85+
public HystrixRollingNumber writeHeavyCounterAdd(CounterState counterState, ValueState valueState) {
8186
counterState.counter.add(valueState.type, valueState.value);
8287
return counterState.counter;
8388
}
@@ -91,17 +96,18 @@ public long writeHeavyReadMetrics(CounterState counterState) {
9196
HystrixRollingNumber counter = counterState.counter;
9297
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
9398
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
94-
counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE) +
99+
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
95100
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
96-
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE);
101+
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
102+
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
97103
}
98104

99105
@Benchmark
100106
@Group("evenSplit")
101107
@GroupThreads(4)
102108
@BenchmarkMode({Mode.Throughput})
103109
@OutputTimeUnit(TimeUnit.MILLISECONDS)
104-
public HystrixRollingNumber evenSplitLatencyAdd(CounterState counterState, ValueState valueState) {
110+
public HystrixRollingNumber evenSplitCounterAdd(CounterState counterState, ValueState valueState) {
105111
counterState.counter.add(valueState.type, valueState.value);
106112
return counterState.counter;
107113
}
@@ -115,17 +121,18 @@ public long evenSplitReadMetrics(CounterState counterState) {
115121
HystrixRollingNumber counter = counterState.counter;
116122
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
117123
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
118-
counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE) +
124+
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
119125
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
120-
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE);
126+
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
127+
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
121128
}
122129

123130
@Benchmark
124131
@Group("readHeavy")
125132
@GroupThreads(1)
126133
@BenchmarkMode({Mode.Throughput})
127134
@OutputTimeUnit(TimeUnit.MILLISECONDS)
128-
public HystrixRollingNumber readHeavyLatencyAdd(CounterState counterState, ValueState valueState) {
135+
public HystrixRollingNumber readHeavyCounterAdd(CounterState counterState, ValueState valueState) {
129136
counterState.counter.add(valueState.type, valueState.value);
130137
return counterState.counter;
131138
}
@@ -139,8 +146,9 @@ public long readHeavyReadMetrics(CounterState counterState) {
139146
HystrixRollingNumber counter = counterState.counter;
140147
return counter.getCumulativeSum(HystrixRollingNumberEvent.SUCCESS) +
141148
counter.getCumulativeSum(HystrixRollingNumberEvent.FAILURE) +
142-
counter.getRollingMaxValue(HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE) +
149+
counter.getCumulativeSum(HystrixRollingNumberEvent.TIMEOUT) +
143150
counter.getRollingSum(HystrixRollingNumberEvent.SUCCESS) +
144-
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE);
151+
counter.getRollingSum(HystrixRollingNumberEvent.FAILURE) +
152+
counter.getRollingSum(HystrixRollingNumberEvent.TIMEOUT);
145153
}
146154
}

0 commit comments

Comments
 (0)