Skip to content

Commit

Permalink
Enable Netty and BookKeeper IO optimizations on jdk17 (#3234)
Browse files Browse the repository at this point in the history
* Enable netty optimization and BK native IO on jdk17

* zip and better docs
  • Loading branch information
nicoloboschi committed May 11, 2022
1 parent 8736029 commit 78662ac
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
20 changes: 18 additions & 2 deletions bin/common.sh
Expand Up @@ -284,7 +284,15 @@ build_cli_jvm_opts() {
}

build_netty_opts() {
echo "-Dio.netty.leakDetectionLevel=${NETTY_LEAK_DETECTION_LEVEL}"
NETTY_OPTS="-Dio.netty.leakDetectionLevel=${NETTY_LEAK_DETECTION_LEVEL} -Dio.netty.tryReflectionSetAccessible=true"
# --add-opens does not exist on jdk8
if [ "$USING_JDK8" -eq "0" ]; then
# Enable java.nio.DirectByteBuffer
# https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent0.java
# https://github.com/netty/netty/issues/12265
NETTY_OPTS="$NETTY_OPTS --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
fi
echo $NETTY_OPTS
}

build_logging_opts() {
Expand Down Expand Up @@ -316,7 +324,15 @@ build_cli_logging_opts() {
}

build_bookie_opts() {
echo "-Djava.net.preferIPv4Stack=true"
BOOKIE_OPTS="-Djava.net.preferIPv4Stack=true"
# --add-opens does not exist on jdk8
if [ "$USING_JDK8" -eq "0" ]; then
# enable posix_fadvise usage in the Journal
BOOKIE_OPTS="$BOOKIE_OPTS --add-opens java.base/java.io=ALL-UNNAMED"
# DirectMemoryCRC32Digest
BOOKIE_OPTS="$BOOKIE_OPTS --add-opens java.base/java.util.zip=ALL-UNNAMED"
fi
echo $BOOKIE_OPTS
}

find_table_service() {
Expand Down
20 changes: 18 additions & 2 deletions bin/common_gradle.sh
Expand Up @@ -266,7 +266,15 @@ build_cli_jvm_opts() {
}

build_netty_opts() {
echo "-Dio.netty.leakDetectionLevel=${NETTY_LEAK_DETECTION_LEVEL}"
NETTY_OPTS="-Dio.netty.leakDetectionLevel=${NETTY_LEAK_DETECTION_LEVEL} -Dio.netty.tryReflectionSetAccessible=true"
# --add-opens does not exist on jdk8
if [ "$USING_JDK8" -eq "0" ]; then
# Enable java.nio.DirectByteBuffer
# https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent0.java
# https://github.com/netty/netty/issues/12265
NETTY_OPTS="$NETTY_OPTS --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
fi
echo $NETTY_OPTS
}

build_logging_opts() {
Expand Down Expand Up @@ -298,7 +306,15 @@ build_cli_logging_opts() {
}

build_bookie_opts() {
echo "-Djava.net.preferIPv4Stack=true"
BOOKIE_OPTS="-Djava.net.preferIPv4Stack=true"
# --add-opens does not exist on jdk8
if [ "$USING_JDK8" -eq "0" ]; then
# enable posix_fadvise usage in the Journal
BOOKIE_OPTS="$BOOKIE_OPTS --add-opens java.base/java.io=ALL-UNNAMED"
# DirectMemoryCRC32Digest
BOOKIE_OPTS="$BOOKIE_OPTS --add-opens java.base/java.util.zip=ALL-UNNAMED"
fi
echo $BOOKIE_OPTS
}

find_table_service() {
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -1220,6 +1220,7 @@
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED
--add-opens java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.util.zip=ALL-UNNAMED
--add-opens java.base/java.time=ALL-UNNAMED
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED
--add-opens java.base/sun.net.dns=ALL-UNNAMED
Expand Down
16 changes: 14 additions & 2 deletions tests/scripts/src/test/bash/bk_test_bin_common.sh
Expand Up @@ -226,9 +226,14 @@ testBuildNettyOpts() {
source ${BK_BINDIR}/common.sh

ACTUAL_NETTY_OPTS=$(build_netty_opts)
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled"
EXPECTED_NETTY_OPTS=""
if [ "$USING_JDK8" -ne "1" ]; then
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled -Dio.netty.tryReflectionSetAccessible=true --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
else
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled -Dio.netty.tryReflectionSetAccessible=true"
fi

assertEquals "Netty OPTS is not set correctly" "${EXPECTED_NETTY_OPTS}" "${ACTUAL_NETTY_OPTS}"
assertEquals "Netty OPTS is not set correctly" "${EXPECTED_NETTY_OPTS}" "${ACTUAL_NETTY_OPTS}"
}

testBuildBookieOpts() {
Expand All @@ -237,6 +242,13 @@ testBuildBookieOpts() {
ACTUAL_OPTS=$(build_bookie_opts)
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true"

USEJDK8=$(detect_jdk8)
if [ "$USING_JDK8" -ne "1" ]; then
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util.zip=ALL-UNNAMED"
else
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true"
fi

assertEquals "Bookie OPTS is not set correctly" "${EXPECTED_OPTS}" "${ACTUAL_OPTS}"
}

Expand Down
14 changes: 12 additions & 2 deletions tests/scripts/src/test/bash/gradle/bk_test_bin_common.sh
Expand Up @@ -203,7 +203,12 @@ testBuildNettyOpts() {
source ${BK_BINDIR}/common_gradle.sh

ACTUAL_NETTY_OPTS=$(build_netty_opts)
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled"
EXPECTED_NETTY_OPTS=""
if [ "$USING_JDK8" -ne "1" ]; then
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled -Dio.netty.tryReflectionSetAccessible=true --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
else
EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled -Dio.netty.tryReflectionSetAccessible=true"
fi

assertEquals "Netty OPTS is not set correctly" "${EXPECTED_NETTY_OPTS}" "${ACTUAL_NETTY_OPTS}"
}
Expand All @@ -212,7 +217,12 @@ testBuildBookieOpts() {
source ${BK_BINDIR}/common_gradle.sh

ACTUAL_OPTS=$(build_bookie_opts)
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true"
USEJDK8=$(detect_jdk8)
if [ "$USING_JDK8" -ne "1" ]; then
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util.zip=ALL-UNNAMED"
else
EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true"
fi

assertEquals "Bookie OPTS is not set correctly" "${EXPECTED_OPTS}" "${ACTUAL_OPTS}"
}
Expand Down

0 comments on commit 78662ac

Please sign in to comment.