diff --git a/CHANGELOG.md b/CHANGELOG.md index b78adf6e06..7b02f81270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ This release version has been deprecated release due to CI bug - Remove long-deprecated `perm*whitelist*` methods [#7401](https://github.com/hyperledger/besu/pull/7401) ### Additions and Improvements +- Allow optional loading of `jemalloc` (if installed) by setting the environment variable `BESU_USING_JEMALLOC` to true/false. It that env is not set at all it will behave as if it is set to `true` - Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382) - In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395) - Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index b3dfa2a054..a7b43d0d9e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -433,14 +433,18 @@ public class ConfigurationOverviewBuilder { private void detectJemalloc(final List lines) { Optional.ofNullable(Objects.isNull(environment) ? null : environment.get("BESU_USING_JEMALLOC")) .ifPresentOrElse( - t -> { + jemallocEnabled -> { try { - final String version = PlatformDetector.getJemalloc(); - lines.add("jemalloc: " + version); + if (Boolean.parseBoolean(jemallocEnabled)) { + final String version = PlatformDetector.getJemalloc(); + lines.add("jemalloc: " + version); + } else { + logger.warn( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded"); + } } catch (final Throwable throwable) { logger.warn( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version", - throwable); + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"); } }, () -> { diff --git a/besu/src/main/scripts/unixStartScript.txt b/besu/src/main/scripts/unixStartScript.txt index 3302b9c2fe..9e5c5a300b 100644 --- a/besu/src/main/scripts/unixStartScript.txt +++ b/besu/src/main/scripts/unixStartScript.txt @@ -182,19 +182,19 @@ APP_ARGS=`save "\$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" <% if ( mainClassName.startsWith('--module ') ) { %>--module-path "\"\$MODULE_PATH\"" <% } %>${mainClassName} "\$APP_ARGS" -unset BESU_USING_JEMALLOC if [ "\$darwin" = "false" -a "\$msys" = "false" ]; then - # check if jemalloc is available - TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) - - # if jemalloc is available the output is empty, otherwise the output has an error line - if [ -z "\$TEST_JEMALLOC" ]; then - export LD_PRELOAD=libjemalloc.so - export BESU_USING_JEMALLOC=true - else - # jemalloc not available, as fallback limit malloc to 2 arenas - export MALLOC_ARENA_MAX=2 - fi + if [ "\$BESU_USING_JEMALLOC" != "FALSE" -a "\$BESU_USING_JEMALLOC" != "false" ]; then + # check if jemalloc is available + TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) + + # if jemalloc is available the output is empty, otherwise the output has an error line + if [ -z "\$TEST_JEMALLOC" ]; then + export LD_PRELOAD=libjemalloc.so + else + # jemalloc not available, as fallback limit malloc to 2 arenas + export MALLOC_ARENA_MAX=2 + fi + fi fi exec "\$JAVACMD" "\$@" diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index ea06f406ed..eb789478b9 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNotNull; +import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -2412,13 +2413,16 @@ public class BesuCommandTest extends CommandTestAbstract { @Test public void logsWarningWhenFailToLoadJemalloc() { assumeTrue(PlatformDetector.getOSType().equals("linux")); - setEnvironmentVariable("BESU_USING_JEMALLOC", "true"); + setEnvironmentVariable("BESU_USING_JEMALLOC", "false"); parseCommand(); verify(mockLogger) .warn( - eq( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version"), - any(Throwable.class)); + argThat( + arg -> + arg.equals( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded") + || arg.equals( + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"))); } @Test