JVM memory usage is a big topic...
The are __many__ hooks. Some which may be relevant are
Min/MaxHeapFreeRatio and ShrinkHeapInSteps options.
eg. my current settings of phoebus where I hope to persuade a more
or less idle JVM to more aggressively release memory back to the
system.
-XX:MinHeapSize=128m \
-XX:MaxHeapSize=2g \
-XX:InitialHeapSize=1g \
-XX:MaxHeapFreeRatio=10 \
-XX:MinHeapFreeRatio=5 \
-XX:-ShrinkHeapInSteps \
-XX:NativeMemoryTracking=detail \
These values are largely taken from examples I found of tuning java
for "embedded" or "memory constrained" targets.
https://urldefense.us/v3/__https://docs.oracle.com/en/java/javase/11/gctuning/factors-affecting-garbage-collection-performance.html__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo-0_wZIvA$
https://urldefense.us/v3/__https://bugs.openjdk.org/browse/JDK-8146436__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo-YHplDAg$
On 7/29/24 11:21, Kasemir, Kay via Tech-talk wrote:
I’d be concerned about memory leaks, but not memory usage in general.
Java Virtual Machine Memory
---------------------------
CS-Studio/Phoebus is a plain Java application, with memory managed by the JVM.
See also https://urldefense.us/v3/__https://developers.redhat.com/articles/2021/09/09/how-jvm-uses-and-allocates-memory__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo_1btiQEg$ <https://urldefense.us/v3/__https://developers.redhat.com/articles/2021/09/09/how-jvm-uses-and-allocates-memory__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7T7vNd4pE$>
When you launch the applications, the JVM option `-Xmx` sets the maximum amount of memory that the JVM will use, and `-Xms` sets the initial amount.
For example,
```
export JDK_JAVA_OPTIONS="-Xms500M -Xmx2G"
java -jar product.jar
```
will start the JVM will 500MB of memory, and it will allocate up to 2GB.
A tool like VisualVM (free, https://urldefense.us/v3/__https://visualvm.github.io__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo89zayEjQ$ <https://urldefense.us/v3/__https://visualvm.github.io__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TY0pTgm4$>) or JProfiler (very good but not free, https://urldefense.us/v3/__https://www.ej-technologies.com/products/jprofiler/overview.html__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo_LXqREKw$ <https://urldefense.us/v3/__https://www.ej-technologies.com/products/jprofiler/overview.html__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TRoDJyCM$>) can be used to track memory usage over time.
What you should see is a sawtooth-type pattern where the application uses more and more memory, maybe up to the `-Xmx` limit, then frees it.
When you open several displays, the sawtooth pattern may ramp up more rapidly, and when you then close those displays, it should free memory and return to a slower/longer sawtooth pattern. If you find a scenario where the memory keeps increasing until running out of memory, you may have spotted a memory leak that should should report, ideally with a reproducible recipe.
Linux Memory
------------
It can be confusing to compare memory usage as reported by the JVM with the memory usage reported by the Linux OS.
Especially the "VIRT" virtual memory indicated in for example `top` may appear huge, but that tends to have no
practical significance, see for example https://urldefense.us/v3/__https://stackoverflow.com/questions/561245/virtual-memory-usage-from-java-under-linux-too-much-memory-used__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo8i7Vg-4w$ <https://urldefense.us/v3/__https://stackoverflow.com/questions/561245/virtual-memory-usage-from-java-under-linux-too-much-memory-used__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TXiL_1Bc$>, which also points to related discussions of the glibc `MALLOC_ARENA_MAX` setting.
*From: *Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Xiao, Lingran via Tech-talk <tech-talk at aps.anl.gov>
*Date: *Monday, July 29, 2024 at 1:51 PM
*To: *tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
*Subject: *[EXTERNAL] tune CSS Phoebus's memory usage
Hi all,
We're concerned about CSS Phoebus's high memory usages. I was wondering do you have the same concerns. And did you take any actions to minimize the memory usages while maintaining Phoebus's performance? Any inputs are welcome.
Thanks a lot,
Lingran
- References:
- tune CSS Phoebus's memory usage Xiao, Lingran via Tech-talk
- Re: tune CSS Phoebus's memory usage Kasemir, Kay via Tech-talk
- Navigate by Date:
- Prev:
Re: tune CSS Phoebus's memory usage Kasemir, Kay via Tech-talk
- Next:
Registration deadline for Sept. 16-20 EPICS Meeting at ORNL, USA Kasemir, Kay via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
<2024>
2025
- Navigate by Thread:
- Prev:
Re: tune CSS Phoebus's memory usage Kasemir, Kay via Tech-talk
- Next:
Registration deadline for Sept. 16-20 EPICS Meeting at ORNL, USA Kasemir, Kay via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
<2024>
2025
|