Skip to content

Commit 641d6cf

Browse files
John Calcotekofemann
authored andcommitted
Set leader-follower strategy in grizzly if selected in oncrpc4j.
By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: John Calcote <[email protected]> (cherry picked from commit e50ceda) Signed-off-by: Tigran Mkrtchyan <[email protected]>
1 parent f917a7d commit 641d6cf

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/grizzly/GrizzlyUtils.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -19,19 +19,21 @@
1919
*/
2020
package org.dcache.oncrpc4j.grizzly;
2121

22+
import org.dcache.oncrpc4j.rpc.IoStrategy;
2223
import org.dcache.oncrpc4j.rpc.RpcMessageParserTCP;
2324
import org.dcache.oncrpc4j.rpc.RpcMessageParserUDP;
2425
import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
25-
import org.dcache.oncrpc4j.rpc.IoStrategy;
2626
import org.glassfish.grizzly.IOStrategy;
2727
import org.glassfish.grizzly.Transport;
2828
import org.glassfish.grizzly.filterchain.Filter;
2929
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
3030
import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
31+
import org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy;
32+
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
3133
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
3234

33-
import static org.dcache.oncrpc4j.rpc.IoStrategy.*;
3435
import static com.google.common.base.Preconditions.checkArgument;
36+
import static org.dcache.oncrpc4j.rpc.IoStrategy.WORKER_THREAD;
3537

3638
/**
3739
* Class with utility methods for Grizzly
@@ -116,4 +118,23 @@ public static ThreadPoolConfig getSelectorPoolCfg(IoStrategy ioStrategy, String
116118

117119
return poolCfg;
118120
}
121+
122+
/**
123+
* Convert an oncrpc4j IoStrategy enum value into a grizzly NIOStrategy instance. Note that the only two that matter
124+
* here are single-thread and leader-follower. Worker threads should not be used in the grizzly layer as they would
125+
* just inject more context switching overhead to no benefit.
126+
*
127+
* @param ioStrategy the oncrpc4j IoStategy to map to an NIOStrategy instance.
128+
* @return the matching NIOStrategy instance for the specified IoStrategy value.
129+
*/
130+
public static IOStrategy getNIOStrategy(IoStrategy ioStrategy) {
131+
switch (ioStrategy) {
132+
case LEADER_FOLLOWER:
133+
return LeaderFollowerNIOStrategy.getInstance();
134+
case WORKER_THREAD:
135+
case SAME_THREAD:
136+
default:
137+
return SameThreadIOStrategy.getInstance();
138+
}
139+
}
119140
}

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/OncRpcSvc.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -19,14 +19,15 @@
1919
*/
2020
package org.dcache.oncrpc4j.rpc;
2121

22+
import org.dcache.oncrpc4j.grizzly.GrizzlyRpcTransport;
2223
import org.dcache.oncrpc4j.grizzly.StartTlsFilter;
23-
import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
24-
import org.dcache.oncrpc4j.rpc.net.InetSocketAddresses;
25-
import org.dcache.oncrpc4j.rpc.gss.GssProtocolFilter;
26-
import org.dcache.oncrpc4j.rpc.gss.GssSessionManager;
2724
import org.dcache.oncrpc4j.portmap.GenericPortmapClient;
2825
import org.dcache.oncrpc4j.portmap.OncPortmapClient;
2926
import org.dcache.oncrpc4j.portmap.OncRpcPortmap;
27+
import org.dcache.oncrpc4j.rpc.gss.GssProtocolFilter;
28+
import org.dcache.oncrpc4j.rpc.gss.GssSessionManager;
29+
import org.dcache.oncrpc4j.rpc.net.InetSocketAddresses;
30+
import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
3031
import org.glassfish.grizzly.CloseType;
3132
import org.glassfish.grizzly.Connection;
3233
import org.glassfish.grizzly.ConnectionProbe;
@@ -45,15 +46,17 @@
4546
import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder;
4647
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
4748
import org.glassfish.grizzly.ssl.SSLFilter;
48-
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
4949
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
5050
import org.slf4j.Logger;
5151
import org.slf4j.LoggerFactory;
5252

53+
import javax.net.ssl.SSLContext;
54+
import javax.net.ssl.SSLParameters;
5355
import java.io.IOException;
5456
import java.net.Inet6Address;
5557
import java.net.InetAddress;
5658
import java.net.InetSocketAddress;
59+
import java.net.SocketAddress;
5760
import java.net.UnknownHostException;
5861
import java.util.ArrayList;
5962
import java.util.HashSet;
@@ -66,14 +69,11 @@
6669
import java.util.concurrent.Future;
6770
import java.util.concurrent.TimeUnit;
6871
import java.util.concurrent.TimeoutException;
69-
import javax.net.ssl.SSLContext;
72+
import java.util.stream.Collectors;
7073

7174
import static com.google.common.base.Throwables.getRootCause;
7275
import static com.google.common.base.Throwables.propagateIfPossible;
73-
import java.net.SocketAddress;
74-
import java.util.stream.Collectors;
75-
import javax.net.ssl.SSLParameters;
76-
import org.dcache.oncrpc4j.grizzly.GrizzlyRpcTransport;
76+
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getNIOStrategy;
7777
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getSelectorPoolCfg;
7878
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.rpcMessageReceiverFor;
7979
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.transportFor;
@@ -149,7 +149,7 @@ public class OncRpcSvc {
149149
final TCPNIOTransport tcpTransport = TCPNIOTransportBuilder
150150
.newInstance()
151151
.setReuseAddress(true)
152-
.setIOStrategy(SameThreadIOStrategy.getInstance())
152+
.setIOStrategy(getNIOStrategy(ioStrategy))
153153
.setSelectorThreadPoolConfig(selectorPoolConfig)
154154
.setSelectorRunnersCount(selectorPoolConfig.getMaxPoolSize())
155155
.build();
@@ -160,7 +160,7 @@ public class OncRpcSvc {
160160
final UDPNIOTransport udpTransport = UDPNIOTransportBuilder
161161
.newInstance()
162162
.setReuseAddress(true)
163-
.setIOStrategy(SameThreadIOStrategy.getInstance())
163+
.setIOStrategy(getNIOStrategy(ioStrategy))
164164
.setSelectorThreadPoolConfig(selectorPoolConfig)
165165
.setSelectorRunnersCount(selectorPoolConfig.getMaxPoolSize())
166166
.build();

0 commit comments

Comments
 (0)