You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2026/09/09 06:45:53 UTC
(pulsar) branch master updated: [improve][cli] Default the pulsar-perf client memory limit to half of the JVM max direct memory (#26491)
This is an automated email from the ASF dual-hosted git repository.
nodece pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 0b56d9d33a1b [improve][cli] Default the pulsar-perf client memory limit to half of the JVM max direct memory (#26491)
0b56d9d33a1b is described below
commit 0b56d9d33a1b66d025bdfbc64ebd85e5a35b6ea7
Author: Alvaro <10...@users.noreply.github.com>
AuthorDate: Wed Sep 9 08:45:46 2026 +0200
[improve][cli] Default the pulsar-perf client memory limit to half of the JVM max direct memory (#26491)
---
.../testclient/PerformanceBaseArguments.java | 17 +++++++++--
.../testclient/PerformanceBaseArgumentsTest.java | 34 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
index bff532d1ff59..e5d8388e8e96 100644
--- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
+++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.testclient;
import static org.apache.commons.lang3.StringUtils.isBlank;
import org.apache.pulsar.cli.converters.picocli.ByteUnitToLongConverter;
import org.apache.pulsar.client.api.ProxyProtocol;
+import org.apache.pulsar.common.util.DirectMemoryUtils;
import picocli.CommandLine.Option;
/**
@@ -110,9 +111,21 @@ public abstract class PerformanceBaseArguments extends CmdBase{
@Option(names = { "--auth_plugin" }, description = "Authentication plugin class name", hidden = true)
public String deprecatedAuthPluginClassName;
+ /**
+ * Default Pulsar client memory limit for the performance tools: half of the JVM's max direct memory.
+ *
+ * <p>The performance tools do not use direct memory for anything other than Netty, so bounding the client
+ * at a fraction of what the JVM can actually allocate keeps the tool from dying with
+ * {@code OutOfDirectMemoryError} while still letting it use the memory it was given. Being proportional
+ * rather than a fixed value also avoids silently changing results for runs that were sized with a larger
+ * {@code -XX:MaxDirectMemorySize}.
+ */
+ public static final long DEFAULT_MEMORY_LIMIT_BYTES = (long) (0.5d * DirectMemoryUtils.jvmMaxDirectMemory());
+
@Option(names = { "-ml", "--memory-limit", }, description = "Configure the Pulsar client memory limit "
- + "(eg: 32M, 64M)", converter = ByteUnitToLongConverter.class)
- public long memoryLimit;
+ + "(eg: 32M, 64M). Defaults to half of the JVM's max direct memory. Use 0 to disable the limit.",
+ converter = ByteUnitToLongConverter.class)
+ public long memoryLimit = DEFAULT_MEMORY_LIMIT_BYTES;
public PerformanceBaseArguments(String cmdName) {
super(cmdName);
}
diff --git a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
index 78cee5c22154..50e57b0428fc 100644
--- a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
+++ b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.pulsar.common.util.DirectMemoryUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -249,6 +250,39 @@ public class PerformanceBaseArgumentsTest {
// Act
baseArgument.parseCLI();
+ // Assert
+ assertEquals(baseArgument.memoryLimit, PerformanceBaseArguments.DEFAULT_MEMORY_LIMIT_BYTES);
+ assertEquals(baseArgument.memoryLimit, (long) (0.5d * DirectMemoryUtils.jvmMaxDirectMemory()));
+ }
+ }
+
+ @Test
+ public void testMemoryLimitCanBeDisabled() throws Exception {
+ for (String cmd : List.of(
+ "pulsar-perf read",
+ "pulsar-perf produce",
+ "pulsar-perf consume",
+ "pulsar-perf transaction"
+ )) {
+ // Arrange
+ final PerformanceBaseArguments baseArgument = new PerformanceBaseArguments("") {
+ @Override
+ public void run() throws Exception {
+
+ }
+
+ };
+ String confFile = "./src/test/resources/perf_client1.conf";
+ Properties prop = new Properties(System.getProperties());
+ try (FileInputStream fis = new FileInputStream(confFile)) {
+ prop.load(fis);
+ }
+ baseArgument.getCommander().setDefaultValueProvider(PulsarPerfTestPropertiesProvider.create(prop));
+ baseArgument.parse(new String[]{"-ml", "0"});
+
+ // Act
+ baseArgument.parseCLI();
+
// Assert
assertEquals(baseArgument.memoryLimit, 0L);
}