Skip to content

Commit 459920f

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 a8f7352 commit 459920f

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

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

Lines changed: 23 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,11 +19,11 @@
1919
*/
2020
package org.dcache.oncrpc4j.grizzly;
2121

22+
import org.dcache.oncrpc4j.rpc.IoStrategy;
2223
import org.dcache.oncrpc4j.rpc.MemoryAllocator;
2324
import org.dcache.oncrpc4j.rpc.RpcMessageParserTCP;
2425
import org.dcache.oncrpc4j.rpc.RpcMessageParserUDP;
2526
import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
26-
import org.dcache.oncrpc4j.rpc.IoStrategy;
2727
import org.glassfish.grizzly.IOStrategy;
2828
import org.glassfish.grizzly.Transport;
2929
import org.glassfish.grizzly.filterchain.Filter;
@@ -33,10 +33,12 @@
3333
import org.glassfish.grizzly.memory.PooledMemoryManager;
3434
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
3535
import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
36+
import org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy;
37+
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
3638
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
3739

38-
import static org.dcache.oncrpc4j.rpc.IoStrategy.*;
3940
import static com.google.common.base.Preconditions.checkArgument;
41+
import static org.dcache.oncrpc4j.rpc.IoStrategy.WORKER_THREAD;
4042

4143
/**
4244
* Class with utility methods for Grizzly
@@ -143,6 +145,24 @@ public static MemoryManager getMemoryManager(MemoryAllocator allocator) {
143145
default:
144146
throw new RuntimeException("Unexpected memory allocator.");
145147
}
148+
}
146149

150+
/**
151+
* Convert an oncrpc4j IoStrategy enum value into a grizzly NIOStrategy instance. Note that the only two that matter
152+
* here are single-thread and leader-follower. Worker threads should not be used in the grizzly layer as they would
153+
* just inject more context switching overhead to no benefit.
154+
*
155+
* @param ioStrategy the oncrpc4j IoStategy to map to an NIOStrategy instance.
156+
* @return the matching NIOStrategy instance for the specified IoStrategy value.
157+
*/
158+
public static IOStrategy getNIOStrategy(IoStrategy ioStrategy) {
159+
switch (ioStrategy) {
160+
case LEADER_FOLLOWER:
161+
return LeaderFollowerNIOStrategy.getInstance();
162+
case WORKER_THREAD:
163+
case SAME_THREAD:
164+
default:
165+
return SameThreadIOStrategy.getInstance();
166+
}
147167
}
148168
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2021 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;
@@ -46,15 +47,17 @@
4647
import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder;
4748
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
4849
import org.glassfish.grizzly.ssl.SSLFilter;
49-
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
5050
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
5151
import org.slf4j.Logger;
5252
import org.slf4j.LoggerFactory;
5353

54+
import javax.net.ssl.SSLContext;
55+
import javax.net.ssl.SSLParameters;
5456
import java.io.IOException;
5557
import java.net.Inet6Address;
5658
import java.net.InetAddress;
5759
import java.net.InetSocketAddress;
60+
import java.net.SocketAddress;
5861
import java.net.UnknownHostException;
5962
import java.util.ArrayList;
6063
import java.util.HashSet;
@@ -67,16 +70,13 @@
6770
import java.util.concurrent.Future;
6871
import java.util.concurrent.TimeUnit;
6972
import java.util.concurrent.TimeoutException;
70-
import javax.net.ssl.SSLContext;
73+
import java.util.stream.Collectors;
7174

7275
import static com.google.common.base.Throwables.getRootCause;
7376
import static com.google.common.base.Throwables.propagateIfPossible;
74-
import java.net.SocketAddress;
75-
import java.util.stream.Collectors;
76-
import javax.net.ssl.SSLParameters;
77-
import org.dcache.oncrpc4j.grizzly.GrizzlyRpcTransport;
78-
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getSelectorPoolCfg;
7977
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getMemoryManager;
78+
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getNIOStrategy;
79+
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.getSelectorPoolCfg;
8080
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.rpcMessageReceiverFor;
8181
import static org.dcache.oncrpc4j.grizzly.GrizzlyUtils.transportFor;
8282

@@ -152,7 +152,7 @@ public class OncRpcSvc {
152152
final TCPNIOTransport tcpTransport = TCPNIOTransportBuilder
153153
.newInstance()
154154
.setReuseAddress(true)
155-
.setIOStrategy(SameThreadIOStrategy.getInstance())
155+
.setIOStrategy(getNIOStrategy(ioStrategy))
156156
.setSelectorThreadPoolConfig(selectorPoolConfig)
157157
.setSelectorRunnersCount(selectorPoolConfig.getMaxPoolSize())
158158
.setMemoryManager(mm)
@@ -164,7 +164,7 @@ public class OncRpcSvc {
164164
final UDPNIOTransport udpTransport = UDPNIOTransportBuilder
165165
.newInstance()
166166
.setReuseAddress(true)
167-
.setIOStrategy(SameThreadIOStrategy.getInstance())
167+
.setIOStrategy(getNIOStrategy(ioStrategy))
168168
.setSelectorThreadPoolConfig(selectorPoolConfig)
169169
.setSelectorRunnersCount(selectorPoolConfig.getMaxPoolSize())
170170
.setMemoryManager(mm)

0 commit comments

Comments
 (0)