Skip to content

Bump default JVM heap and add OOM diagnostics#2044

Open
jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:jvm-defaults-oom-diagnostics
Open

Bump default JVM heap and add OOM diagnostics#2044
jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:jvm-defaults-oom-diagnostics

Conversation

@jbonofre

@jbonofre jbonofre commented May 26, 2026

Copy link
Copy Markdown
Member
  • Raise the shipped default heap from -Xms64M -Xmx1G to -Xms512M -Xmx2G in assembly/src/release/bin/setenv. The previous default is undersized for a production broker; the new value is still modest and remains overridable via ACTIVEMQ_OPTS_MEMORY.
  • Add a new ACTIVEMQ_OOM_OPTS variable defaulting to -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$ACTIVEMQ_DATA -XX:+ExitOnOutOfMemoryError so that an OutOfMemoryError produces a heap dump under the broker data directory and the JVM terminates rather than continuing in a degraded state.
  • Mirror the same ACTIVEMQ_OOM_OPTS fallback inside assembly/src/release/bin/activemq so the diagnostics still apply if setenv is absent.

Both new variables remain overridable from the environment or from any of the higher-priority configuration files (/etc/default/activemq, ~/.activemqrc, bin/setenv).

@jbonofre jbonofre requested review from cshannon and mattrpav May 26, 2026 15:58
@jbonofre

Copy link
Copy Markdown
Member Author

@cshannon I propose to update the default configuration like this.

@cshannon

Copy link
Copy Markdown
Contributor

Hmm, I think this might need more discussion. I think the 2GB default is good but I don't know about the OOM heap dump as that will cause unexpected output to a file system for users. I think that needs to be configurable on set up maybe. We could bring it up for discussion on the dev list.

@jbonofre

Copy link
Copy Markdown
Member Author

@cshannon yes, I can add a optional flag to setup OOM. I'm just sharing my experience: I have to ask more of the ActiveMQ users to enable it it to investigate 😄 So having a way to enable it by default would be good (or at least documented).

@cshannon

Copy link
Copy Markdown
Contributor

@cshannon yes, I can add a optional flag to setup OOM. I'm just sharing my experience: I have to ask more of the ActiveMQ users to enable it it to investigate 😄 So having a way to enable it by default would be good (or at least documented).

That sounds good, I personally set that flag myself so I am fine with it but I figure someone might not want the extra output.
It can be an issue if the broker gets into an OOM restart loop and has the potential to fill up a partition so users should be aware it's on or at least opt into it.

@mattrpav

Copy link
Copy Markdown
Contributor

+1 to have a preconfigured but commented out set of options. Having it on by default can quickly lead to disk space usage issues -- there is also a 'where to write the files' problem

@jbonofre

jbonofre commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@cshannon @mattrpav what are your thoughts on this PR? I think this default configuration is a good improvement.

@cshannon

cshannon commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@jbonofre - I think the memory updates make sense and I agree with those. For the OOM settings to dump to disk I think we talked about making that optional with a flag to turn on. I don't think it should be on by default because of the unexpected disk usage. Some people might configure large heap sizes.

Also, I would recommend adding compression: -XX:HeapDumpGzipLevel=6 as that was added in JDK 17 (as long as we are not backporting this)

@jbonofre

jbonofre commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@cshannon thanks! It makes sense. Let me update the PR accordingly.

Raise the shipped default heap from -Xms64M/-Xmx1G to -Xms512M/-Xmx2G
which is more representative of a production broker workload while
still leaving headroom on small hosts (override via ACTIVEMQ_OPTS_MEMORY).

Add ACTIVEMQ_OOM_OPTS with -XX:+ExitOnOutOfMemoryError so that an
OutOfMemoryError terminates the JVM instead of leaving the broker running
in a degraded state.

Heap dump on OOM is disabled by default to avoid unexpected disk usage
when large heap sizes are configured. Users can opt in by uncommenting
the ACTIVEMQ_OOM_DUMP_OPTS lines in bin/setenv (or bin/activemq for the
no-setenv fallback). The commented template includes -XX:HeapDumpGzipLevel=6
(JDK 17+) to compress the dump.
@jbonofre jbonofre force-pushed the jvm-defaults-oom-diagnostics branch from 7155e2c to 9d18836 Compare July 9, 2026 14:25
@jbonofre

jbonofre commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@cshannon Thanks for the feedback, I've updated the PR:

  • Heap dump on OOM is now disabled by default. Users can opt in by uncommenting the ACTIVEMQ_OOM_DUMP_OPTS lines in bin/setenv (or bin/activemq for the no-setenv fallback). -XX:+ExitOnOutOfMemoryError remains on by default since it has no disk impact.
  • Added -XX:HeapDumpGzipLevel=6 to the opt-in template (requires JDK 17+).

Comment thread assembly/src/release/bin/setenv Outdated
Per mattrpav's review feedback: setting -Xms512M by default would be
misconstrued as a high baseline memory requirement. Keep the initial
heap at the original 64M so the JVM starts small and grows on demand,
while still raising the ceiling to 2G.
@jbonofre jbonofre requested a review from mattrpav July 9, 2026 15:12

@mattrpav mattrpav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants