Skip to content

Commit 53a9258

Browse files
committed
Fix epoll
1 parent cc1929c commit 53a9258

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main/java/com/rabbitmq/perf/PerfTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
import com.rabbitmq.perf.metrics.MetricsFormatterFactory;
4242
import com.rabbitmq.perf.metrics.MetricsFormatterFactory.Context;
4343
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
44+
import io.netty.bootstrap.Bootstrap;
4445
import io.netty.channel.EventLoopGroup;
4546
import io.netty.channel.IoHandlerFactory;
4647
import io.netty.channel.MultiThreadIoEventLoopGroup;
4748
import io.netty.channel.epoll.EpollIoHandler;
49+
import io.netty.channel.epoll.EpollSocketChannel;
4850
import io.netty.channel.nio.NioIoHandler;
4951
import java.io.*;
5052
import java.math.BigDecimal;
@@ -59,6 +61,7 @@
5961
import java.util.concurrent.*;
6062
import java.util.concurrent.atomic.AtomicBoolean;
6163
import java.util.function.BooleanSupplier;
64+
import java.util.function.Consumer;
6265
import java.util.function.Function;
6366
import java.util.stream.Collectors;
6467
import javax.net.ssl.SSLContext;
@@ -180,8 +183,8 @@ && useDefaultSslContext(cmd, System.getProperties())) {
180183
factory.useBlockingIo();
181184
}
182185

183-
factory = configureNioIfRequested(cmd, factory, shutdownService);
184-
factory = configureNettyIfRequested(cmd, factory, shutdownService);
186+
configureNioIfRequested(cmd, factory, shutdownService);
187+
configureNettyIfRequested(cmd, factory, shutdownService);
185188

186189
String oauth2TokenEndpoint = strArg(cmd, "o2uri", null);
187190
if (oauth2TokenEndpoint != null) {
@@ -793,7 +796,7 @@ private static PrintWriter openCsvFileForWriting(
793796
}
794797

795798
@SuppressWarnings("deprecation")
796-
private static ConnectionFactory configureNioIfRequested(
799+
private static void configureNioIfRequested(
797800
CommandLineProxy cmd, ConnectionFactory factory, ShutdownService shutdownService) {
798801
int nbThreads = Utils.intArg(cmd, "niot", -1);
799802
int executorSize = Utils.intArg(cmd, "niotp", -1);
@@ -822,7 +825,6 @@ private static ConnectionFactory configureNioIfRequested(
822825
factory.useNio();
823826
factory.setNioParams(nioParams);
824827
}
825-
return factory;
826828
}
827829

828830
protected static int[] getNioNbThreadsAndExecutorSize(
@@ -853,21 +855,22 @@ private static com.rabbitmq.client.impl.nio.NioParams nioParams(ConnectionFactor
853855
return cf.getNioParams();
854856
}
855857

856-
private static ConnectionFactory configureNettyIfRequested(
858+
private static void configureNettyIfRequested(
857859
CommandLineProxy cmd, ConnectionFactory factory, ShutdownService shutdownService) {
858860
if (netty(cmd)) {
859861
int nbThreads = Utils.intArg(cmd, "ntyt", -1);
860862
boolean epoll = hasOption(cmd, "ntyep");
861863
IoHandlerFactory ioHandlerFactory =
862864
epoll ? EpollIoHandler.newFactory() : NioIoHandler.newFactory();
865+
Consumer<Bootstrap> bootstrapCustomizer =
866+
epoll ? b -> b.channel(EpollSocketChannel.class) : b -> {};
863867
EventLoopGroup eventLoopGroup =
864868
nbThreads > 0
865869
? new MultiThreadIoEventLoopGroup(nbThreads, ioHandlerFactory)
866870
: new MultiThreadIoEventLoopGroup(ioHandlerFactory);
867871
shutdownService.wrap(() -> eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS));
868-
factory.netty().eventLoopGroup(eventLoopGroup);
872+
factory.netty().bootstrapCustomizer(bootstrapCustomizer).eventLoopGroup(eventLoopGroup);
869873
}
870-
return factory;
871874
}
872875

873876
private static boolean netty(CommandLineProxy cmd) {

0 commit comments

Comments
 (0)