简体   繁体   中英

How can I optimize the memory usage of JVM?

I would like to ask if anyone here knows a way how to optimize the memory usage of the JVM? We are using a java service wrapper (YAJSW) that invokes the JVM and the physical memory usage is around 40MB. I want to lessen this to let's say 5-10MB. How do I achieve this?

So far, I only have the following configuration:

java =-Xmx1024m

I have also tried this:

java =-Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=2 -XX:PermSize=256m -XX:MaxPermSize=256m

But these configuration settings made no difference at all. What would be the correct configuration settings for this? or, what else do i have to do to optimize this?

Thank in advance for your answers.

Are you talking about resident memory or virtual? On my machine, a simple while(true); in main without anything else already gets me 10 MB of resident memory, mostly because of memory mapped r/o libraries (libc, libm, librt, libpthread...) and jars. Reducing, if possible at all, the memory footprint any further, or to 10 MB in any non-trivial application, would only mean more paging, thus reducing speed.

Virtual memory, on the other hand, is 1.1 GB on my machine, which could be reduced if necessary, but why do so? Unused virtual memory doesn't really cost anything.

Edit: Apart from that, you may want to have a look at the other HotSpot VM Options , especially MaxHeapFreeRatio.

The documentation for YAJSW states:

Wrapper memory requirements
The flexibility of YAJSW comes at a price. Using java for the wrapper process has many advantages. However we pay the java price of higher memory footprint. Whereas the JSW wrapper requires only a few k of memory, the minimal virtual memory requirement of YAJSW is 90 MB and 40 MB physical memory. The value varies depending on the OS and the functions.

If your application can run within 32bit memory restrictions you can use the community edition of Tanuki as it has a lower footprint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM