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)
### 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)

@ -433,14 +433,18 @@ public class ConfigurationOverviewBuilder {
private void detectJemalloc(final List<String> 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");
}
},
() -> {

@ -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" "\$@"

@ -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

Loading…
Cancel
Save