control jemalloc reporting and loading (#7424)

* Implementing Issue #7047 - Optionally load jemalloc

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Implementing Issue #7047 - Optionally load jemalloc

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Implementing Issue #7047 - Optionally load jemalloc: fixes after review

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Implementing Issue #7047 - Optionally load jemalloc: added entry to CHANGELOG

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Changes after review

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Added env var check in unix script

Signed-off-by: Antonio Mota <antonio.mota@citi.com>

* Improved code and script, build and tested

Signed-off-by: amsmota <amsmota@gmail.com>

* Improved code and script, build and tested

Signed-off-by: amsmota <amsmota@gmail.com>

---------

Signed-off-by: Antonio Mota <antonio.mota@citi.com>
Signed-off-by: amsmota <amsmota@gmail.com>
pull/7879/head
amsmota 1 week ago committed by GitHub
parent 1895d44415
commit c15afb915b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 14
      besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java
  3. 24
      besu/src/main/scripts/unixStartScript.txt
  4. 12
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java

@ -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) - Remove long-deprecated `perm*whitelist*` methods [#7401](https://github.com/hyperledger/besu/pull/7401)
### Additions and Improvements ### 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) - 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) - 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) - Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161)

@ -433,14 +433,18 @@ public class ConfigurationOverviewBuilder {
private void detectJemalloc(final List<String> lines) { private void detectJemalloc(final List<String> lines) {
Optional.ofNullable(Objects.isNull(environment) ? null : environment.get("BESU_USING_JEMALLOC")) Optional.ofNullable(Objects.isNull(environment) ? null : environment.get("BESU_USING_JEMALLOC"))
.ifPresentOrElse( .ifPresentOrElse(
t -> { jemallocEnabled -> {
try { try {
final String version = PlatformDetector.getJemalloc(); if (Boolean.parseBoolean(jemallocEnabled)) {
lines.add("jemalloc: " + version); 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) { } catch (final Throwable throwable) {
logger.warn( logger.warn(
"BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version", "besu_using_jemalloc is present but we failed to load jemalloc library to get the version");
throwable);
} }
}, },
() -> { () -> {

@ -182,19 +182,19 @@ APP_ARGS=`save "\$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules # 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" 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 if [ "\$darwin" = "false" -a "\$msys" = "false" ]; then
# check if jemalloc is available if [ "\$BESU_USING_JEMALLOC" != "FALSE" -a "\$BESU_USING_JEMALLOC" != "false" ]; then
TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) # 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 # if jemalloc is available the output is empty, otherwise the output has an error line
export LD_PRELOAD=libjemalloc.so if [ -z "\$TEST_JEMALLOC" ]; then
export BESU_USING_JEMALLOC=true export LD_PRELOAD=libjemalloc.so
else else
# jemalloc not available, as fallback limit malloc to 2 arenas # jemalloc not available, as fallback limit malloc to 2 arenas
export MALLOC_ARENA_MAX=2 export MALLOC_ARENA_MAX=2
fi fi
fi
fi fi
exec "\$JAVACMD" "\$@" exec "\$JAVACMD" "\$@"

@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNotNull; import static org.mockito.ArgumentMatchers.isNotNull;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -2412,13 +2413,16 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test @Test
public void logsWarningWhenFailToLoadJemalloc() { public void logsWarningWhenFailToLoadJemalloc() {
assumeTrue(PlatformDetector.getOSType().equals("linux")); assumeTrue(PlatformDetector.getOSType().equals("linux"));
setEnvironmentVariable("BESU_USING_JEMALLOC", "true"); setEnvironmentVariable("BESU_USING_JEMALLOC", "false");
parseCommand(); parseCommand();
verify(mockLogger) verify(mockLogger)
.warn( .warn(
eq( argThat(
"BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version"), arg ->
any(Throwable.class)); 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 @Test

Loading…
Cancel
Save