File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change
1
+ package io .rsocket ;
2
+
3
+ import io .netty .util .collection .IntObjectMap ;
4
+ import io .rsocket .internal .SynchronizedIntObjectHashMap ;
5
+ import org .openjdk .jmh .annotations .*;
6
+ import org .openjdk .jmh .infra .Blackhole ;
7
+
8
+ @ BenchmarkMode (Mode .Throughput )
9
+ @ Fork (
10
+ value = 1 // , jvmArgsAppend = {"-Dio.netty.leakDetection.level=advanced"}
11
+ )
12
+ @ Warmup (iterations = 10 )
13
+ @ Measurement (iterations = 10 )
14
+ @ State (Scope .Thread )
15
+ public class StreamIdSupplierPerf {
16
+ @ Benchmark
17
+ public void benchmarkStreamId (Input input ) {
18
+ int i = input .supplier .nextStreamId (input .map );
19
+ input .bh .consume (i );
20
+ }
21
+
22
+ @ State (Scope .Benchmark )
23
+ public static class Input {
24
+ Blackhole bh ;
25
+ IntObjectMap map ;
26
+ StreamIdSupplier supplier ;
27
+
28
+ @ Setup
29
+ public void setup (Blackhole bh ) {
30
+ this .supplier = StreamIdSupplier .clientSupplier ();
31
+ this .bh = bh ;
32
+ this .map = new SynchronizedIntObjectHashMap ();
33
+ }
34
+ }
35
+ }
Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
-
17
16
package io .rsocket ;
18
17
19
18
import io .netty .util .collection .IntObjectMap ;
@@ -43,7 +42,7 @@ int nextStreamId(IntObjectMap<?> streamIds) {
43
42
int streamId ;
44
43
do {
45
44
streamId = (int ) STREAM_ID .addAndGet (this , 2 ) & MASK ;
46
- } while (streamIds .containsKey (streamId ));
45
+ } while (streamId == 0 || streamIds .containsKey (streamId ));
47
46
return streamId ;
48
47
}
49
48
Original file line number Diff line number Diff line change @@ -95,8 +95,8 @@ public void testWrap() {
95
95
StreamIdSupplier s = new StreamIdSupplier (Integer .MAX_VALUE - 3 );
96
96
97
97
assertEquals (2147483646 , s .nextStreamId (map ));
98
- assertEquals (0 , s .nextStreamId (map ));
99
98
assertEquals (2 , s .nextStreamId (map ));
99
+ assertEquals (4 , s .nextStreamId (map ));
100
100
101
101
s = new StreamIdSupplier (Integer .MAX_VALUE - 2 );
102
102
You can’t perform that action at this time.
0 commit comments