GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][cli] Default the pulsar-perf client memory limit to half of the JVM max direct memory by AlvaroStream · Pull Request #26491 · apache/pulsar

Conversation

@AlvaroStream

@AlvaroStream AlvaroStream commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Main Issue: #26340

Follow-up to #26341, which is closed. That PR proposed a fixed 64M default; this one takes the approach recommended in review instead: #26341 (comment)

Motivation

pulsar-perf passes its --memory-limit option to the client unconditionally, but the backing field has no initializer:

@Option(names = { "-ml", "--memory-limit", }, ...)
public long memoryLimit;

and 0 is not "no override", it is "no limit":

public boolean isMemoryLimited() {
    return memoryLimit > 0;
}

So since #20663 the performance tools run with client memory limiting disabled unless the user passes -ml explicitly. With no limit there is no client-side bound on outbound buffers, and a producer that outruns the brokers can exhaust direct memory and die with OutOfDirectMemoryError (#26340) instead of throttling and reporting the achievable rate.

#26342 fixes the root cause of #26340 by making NO_MEMORY_LIMIT_DEFAULT_MAX_PENDING_MESSAGES / NO_MEMORY_LIMIT_DEFAULT_MAX_PENDING_MESSAGES_ACROSS_PARTITIONS apply to non-partitioned topics as well. This PR is the follow-up @lhotari suggested in the review of #26341: give the tool a memory limit default that caps memory without silently changing benchmark results.

A fixed 64M default (the approach in the now-closed #26341) was rejected for good reason: since there has effectively been no limit, imposing 64M changes behaviour significantly for workloads with many partitions and larger messages (for example 100 partitions, 32kB messages, high rate), because far fewer messages stay in flight. Making the default proportional to the direct memory the JVM was actually given avoids that: results stay comparable across versions, the tool uses the memory it was handed, and it is still bounded.

Modifications

  • Add PerformanceBaseArguments.DEFAULT_MEMORY_LIMIT_BYTES, computed as (long) (0.5d * DirectMemoryUtils.jvmMaxDirectMemory()), and use it as the initial value of memoryLimit. pulsar-perf uses direct memory only for Netty, so half of the available direct memory leaves ample headroom. This follows the existing convention in ManagedLedgerClientFactory, which derives managedLedgerMaxReadsInFlightSizeInMB from a fraction of DirectMemoryUtils.jvmMaxDirectMemory().
  • Update the --memory-limit option description to state the default and to document that 0 disables the limit.

This applies to PerformanceProducer, PerformanceConsumer, PerformanceReader, PerformanceTransaction and LoadSimulationClient, which share PerformanceBaseArguments, and it reaches both the existing ClientBuilder call site and the v5 PulsarClientBuilder one in PerfClientUtils.

--memory-limit 0 still disables the limit explicitly, so the capability added by #20663 is retained. Only the unset behaviour changes.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is covered by existing tests. PerformanceBaseArgumentsTest#testMemoryLimitCliArgument continues to verify that explicit values (-ml 1, -ml 1K, --memory-limit 1G) are parsed correctly.

PerformanceBaseArgumentsTest#testMemoryLimitCliArgumentDefault asserted the previous 0 default and now asserts the direct-memory-proportional default.

Added PerformanceBaseArgumentsTest#testMemoryLimitCanBeDisabled to pin the escape hatch, so a future change cannot quietly remove the ability to run unbounded via -ml 0.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

The default of the pulsar-perf --memory-limit option changes from 0 (unlimited) to half of the JVM's max direct memory. Runs that need unbounded client memory can pass --memory-limit 0.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlvaroStream
[improve][cli] Default the pulsar-perf client memory limit to half of…
95add36
… the JVM max direct memory

PerformanceBaseArguments#memoryLimit had no initializer, so an unset
--memory-limit passed 0 to the client builder, and 0 disables the limit
rather than leaving the client default in place. The performance tools have
therefore run with client memory limiting switched off since apache#20663.

Instead of restoring a fixed 64M default, which would change results for
workloads that relied on the unbounded behaviour, derive the default from the
direct memory the JVM was actually given: half of
DirectMemoryUtils.jvmMaxDirectMemory(). pulsar-perf uses direct memory only
for Netty, so half leaves ample headroom while still bounding the tool. This
follows the existing convention in ManagedLedgerClientFactory, which derives
managedLedgerMaxReadsInFlightSizeInMB from a fraction of the same value.

--memory-limit 0 still disables the limit explicitly, so the capability added
by apache#20663 is retained. Only the unset behaviour changes.

Assisted-by: Claude Code (Opus 5)
@lhotari lhotari added this to the 5.0.0-M2 milestone Sep 8, 2026
@lhotari lhotari added release/4.2.5 release/4.0.14 labels Sep 8, 2026
lhotari
lhotari approved these changes Sep 8, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodece
nodece merged commit 0b56d9d into apache:master Sep 9, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

lhotari pushed a commit that referenced this pull request Sep 9, 2026
@AlvaroStream @lhotari
[improve][cli] Default the pulsar-perf client memory limit to half of…
59311c9
… the JVM max direct memory (#26491)

(cherry picked from commit 0b56d9d)
@lhotari lhotari added the cherry-picked/branch-4.2 label Sep 9, 2026
lhotari pushed a commit that referenced this pull request Sep 9, 2026
@AlvaroStream @lhotari
[improve][cli] Default the pulsar-perf client memory limit to half of…
fd38dba
… the JVM max direct memory (#26491)

(cherry picked from commit 0b56d9d)
@lhotari lhotari added the cherry-picked/branch-4.0 label Sep 9, 2026
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@AlvaroStream hechengbo
[improve][cli] Default the pulsar-perf client memory limit to half of…
3f316e1
… the JVM max direct memory (apache#26491)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 release/4.0.14 release/4.2.5

Projects

None yet

Milestone

5.0.0-M2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@AlvaroStream @lhotari @nodece
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.