Skip to content

Commit

Permalink
Polish socket configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
acogoluegnes committed Jun 4, 2024
1 parent c462f76 commit 2b7ebcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/rabbitmq/perf/PerfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,7 @@ static Options getOptions() {
options.addOption(
new Option("trbs", "tcp-receive-buffer-size", true, "value for TCP SO_RCVBUF option"));

options.addOption(
new Option("tnd", "tcp-no-delay", true, "value for TCP_NODELAY option"));
options.addOption(new Option("tnd", "tcp-no-delay", true, "value for TCP NODELAY option"));

return options;
}
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/com/rabbitmq/perf/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static SocketConfigurator socketConfigurator(CommandLineProxy cmd) {
}
int sendBufferSize = intArg(cmd, "tsbs", -1);
int receiveBufferSize = intArg(cmd, "trbs", -1);
boolean tcpNoDelay = boolArg(cmd, "tnd", "true");
socketConfigurator =
socketConfigurator.andThen(
socket -> {
Expand All @@ -168,29 +169,24 @@ static SocketConfigurator socketConfigurator(CommandLineProxy cmd) {
if (receiveBufferSize > 0) {
socket.setReceiveBufferSize(receiveBufferSize);
}
socket.setTcpNoDelay(tcpNoDelay);
});
boolean tcpNoDelay = boolArg(cmd, "tnd", "true");
socketConfigurator = socketConfigurator.andThen(socket -> socket.setTcpNoDelay(tcpNoDelay));
return socketConfigurator;
}

static SocketChannelConfigurator socketChannelConfigurator(CommandLineProxy cmd) {
int sendBufferSize = intArg(cmd, "tsbs", -1);
int receiveBufferSize = intArg(cmd, "trbs", -1);
boolean tcpNoDelay = boolArg(cmd, "tnd", "true");
return SocketChannelConfigurators.defaultConfigurator()
.andThen(
socketChannel -> {
if (sendBufferSize > 0) {
socketChannel.socket().setSendBufferSize(sendBufferSize);
}
if (receiveBufferSize > 0) {
socketChannel.socket().setReceiveBufferSize(receiveBufferSize);
}
})
.andThen(
socketChannel -> socketChannel.socket().setTcpNoDelay(boolArg(cmd, "tnd", "true"))
);
return socketChannel -> {
if (sendBufferSize > 0) {
socketChannel.socket().setSendBufferSize(sendBufferSize);
}
if (receiveBufferSize > 0) {
socketChannel.socket().setReceiveBufferSize(receiveBufferSize);
}
socketChannel.socket().setTcpNoDelay(tcpNoDelay);
};
}

static SslEngineConfigurator sslEngineConfigurator(CommandLineProxy cmd) {
Expand Down

0 comments on commit 2b7ebcd

Please sign in to comment.