Higher memory consumption in Java 8 than Java 7
Asked Answered
F

0

4

I'm developing a JavaFX desktop application using Java 7. The application I'm developing uses 10-12 background threads which gets system information or makes HTTP request. I also use some JNA and JNI code.

When i limit the heap size to 40 MB, it's fairly enough and the application runs without a problem with total ~100 MB memory.

However since Oracle is dropping support for Java 7 in April, I decided to upgrade the application to Java 8, the upgrade went smoothly, not much code change required, but i noticed the total memory consumption increased to 130+-20 MB. I researched about this problem, and found out Java 8 introduced Metaspace, I think that may be the problem, but in Java 7 I never set the PermGenSize so in the end I have no idea why the application uses more memory.

Just so you know Metaspace usage is about 33-36 MB in VisualVM.

Any help would be appreciated , thanks

-------SOLVED---------

The problem was; the JDK I was using was 64 bit, since 64 bit JDK on Windows only contains server mode, I installed a 32 bit JDK 8 and started using it in client mode, since then the RAM usage is about 80 MB.

Forwardness answered 6/2, 2015 at 10:1 Comment(10)
I think the assumption is that a few MB is not so important these days. It is possible Java 8 uses more memory to improve speed and flexibility.Succuss
Fair enough, but for an application with 100 mb, 30% increase is not desirable to me.Forwardness
How much would 30 MB cost you? How much time is it worth you spending to reduce this?Succuss
It wouldn't cost me that much, however the company i work for doesn't want the memory to go higher since this application will be installed on many client PCs. Of course I will be doing memory optimizations later but right now i would like to know the cause of this memory usage increase if it's my fault or not.Forwardness
If there is an error, it is more likely to be in terms of memory usage estimate. I would look at the private memory of the application rather than the virtual memory the application uses as this is an over estimate. Getting accurate memory accounting on Windows is tricky. I suspect it uses more memory but not as much as you think and even if you install this on 1000 machines, 30 GB of memory actually costs about $500. If you spend about $500 of your time, you are unlikely to reduce this much.Succuss
So as I understand, what you mean is; 130-150 MB is normal for a client desktop application and I shouldn't mind that because it's just JVM taking this memory i have no control of?Forwardness
Or, put another way, this might have been the thinking of the JVM developers when they produced Java 8 ;)Succuss
if you want to investigate the difference, try running your app with jdk7, take a heap dump using visual vm, then run it again with jdk8, take a heap dump and compare them. That's a start :)Evocator
Heap size is fine on both of them around 35-40 MB. The problem is with non-heap memory.Forwardness
Considering 1000 instances in amazon ec2 cloud VM,if you waste 30GB, then you will waste 1503$ per year. So that's a big price.$0.012 per Hour,for 1GB memory. For a reasonable developer, we shouldn't waste any compute resource.Alejandroalejo

© 2022 - 2024 — McMap. All rights reserved.