• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Will Java 9 modularized apps have a lower RAM footprint due to linking in a custom runtime image?

 
Ranch Hand
Posts: 112
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the module linking and custom runtime image creation features of JDK9 can a program have a lower RAM memory footprint in JDK9 than in JDK8? I imagine this would be because there are fewer classes to load from the classpath. It seems as though the RAM savings that would depend on whether the JVM lazily loads class definitions into RAM when an app starts up.

If there is better RAM usage in Java 9 is it solely because of the fewer classes loaded at runtime? If not, then what are the other sources of improvement?
 
author & internet detective
Posts: 40724
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's one of the reasons. There are others. For example, take a look at the Compact String feature. That's a good amount of space saved since Strings are "everywhere"!
 
Marshal
Posts: 73747
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:. . . take a look at the Compact String feature. . . .

I would be interested to know how much memory it really saves. Probably a lot more if you only write English. Most Strings written by English speakers will use ASCII characters only, where the representation using UTF8 is identical to that in a byte[].

Actually many other western European languages confine themselves to chars < 0x00ff, so they will fit in byte[]s better than UTF8.

Naughty question follows.
Is this the result of a mistake made in JDK1.0: use UTF16 rather than UTF8?
 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Is this the result of a mistake made in JDK1.0: use UTF16 rather than UTF8?



No, the decision in Java 1 was to support Unicode (directly) in Strings. At that time Unicode consisted only of characters which could be represented in 16 bits, so using a 16-bit data type was a natural decision, given that internationalization was a key feature of Java. It wasn't until much later (Unicode Version 5, in 2006, I think, it's hard to tell from what I can find online) that Unicode expanded beyond that limit. So Java 5, to support that version of Unicode, added a lot of methods to the String class which made the distinction between "character" (a 16-bit unit) and "code point" (a Unicode character). So it wasn't until Java 5 that String objects were internally encoded in UTF-16.
 
Kent Bull
Ranch Hand
Posts: 112
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main reason I ask this question is because I want to solve what I see as a problem with my current Spring Boot microservices taking around 1GB of RAM each solely to start up and run. That seems outrageous! Once they are running they stay around 1GB until I start using them. I want to know how to get that initial number down. I see two main possibilities of why I haven't been able to do that so far. One, I don't understand how to properly read JVM memory usage metrics and two, I am unfamiliar with what exactly a JVM classloader and the Spring Runtime Environment does.

Using the Dreyfus Model of Skill Acquisition I put myself as in the beginning stages of competency in our industry, so there are many things I still do not know. I haven't done runtime profiling or JVM monitoring of any application yet nor have I looked very far into how to reduce the RAM consumption of my Java applications. I have read some of the literature on the subject such as this post by Dave Syer, and other related posts. Is the high RAM consumption a big problem? Not yet, since my employer can just buy more and bigger machines. However, I see it as a challenge to make me a better engineer and to gain a more complete understanding of what the JVM and machine I am using are doing on behalf of the programs I write.

I am thinking that the feature touted in many Javascript build tools of tree-shaking is roughly equivalent to Java 9's module system with custom runtime images. So, a guess on my part is that since I can do this with my Spring Libraries that I can reduce the amount of the JDK and the SPDK (Spring Development Kit) I load, which should reduce the amount of initial RAM consumption by the software. I believe that Java can be efficient with memory, there just has to be something I am doing that is causing so much RAM usage, or at the very least, something I can do to reduce the amount of RAM needed.

So, I don't know yet if CompactStrings will help me. I did think it was interesting to read up on the Baeldung writeup of that topic and it was interesting to get Paul's knowledge of Java's history. I am also interested in the other reasons for a lower RAM footprint mentioned by Jeanne

... There are others. ...

.
 
Jeanne Boyarsky
author & internet detective
Posts: 40724
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kent O. Johnson wrote:.. There are others. ...

.
I was thinking of Compact Strings and this for Docker (which wouldn't affect you). There may be more. I don't know off the top of my head.

Profiling is going to help you save memory more than anything else.Also, you mentioned Spring Boot. It's really easy to get unneeded dependencies that way so check to see if there is anything you don't need to pull.
 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to make your Java app consume less memory, it is needed to use G1 and configure it properly. The following command can help to set up automatic scaling and invoking Full GC will release the unused resources:-Xms32m -Xmx1G -XX:+UseG1GC

At the same time, do not activate Aggressive Heap option, as it will overwrite all scaling advantages.

We plan to publish an article with examples and graphs in the near days, so I'll share it with you to see the result in action.
 
Campbell Ritchie
Marshal
Posts: 73747
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TF: welcome to the Ranch
 
Tetiana Fydorenchyk
Greenhorn
Posts: 4
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CR: Thank you! I'll try to be active and useful for members here
 
Bartender
Posts: 1310
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kent O. Johnson wrote:The main reason I ask this question is because I want to solve what I see as a problem with my current Spring Boot microservices taking around 1GB of RAM each solely to start up and run. That seems outrageous! Once they are running they stay around 1GB until I start using them. I want to know how to get that initial number down. I see two main possibilities of why I haven't been able to do that so far. One, I don't understand how to properly read JVM memory usage metrics and two, I am unfamiliar with what exactly a JVM classloader and the Spring Runtime Environment does.



I'm really interested on this topic, too. Seems that microservices are the new black, and Spring Boot is very appealing.
Nevertheless, IMHO size & memory requirements of a java based microservice are a big concern : just think about the much smaller footprint that Go or Node.js have. I wonder if Java is really well suited to build and run microservices.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With Java 9 and custom runtime images,
1. We can reduce the footprint of our deliverable if we had been shipping along with JRE.
2. Definitely, startup time will be faster as not all unrequired modules that were present in "rt.jar" are present in the runtime image.

Yes, Compact String is another major improvement, G1 garbage collector looks perfect for Modules wise garbage collection for optimizing usage of RAM.

Beyond these improvements, Java team is targetting value types in next version of Java.

Many a time we forget about the container size and only compare the smaller footprint of application size as the container has many required modules for the application. I hope JPMS will help to create pluggable container platform to deploy and update many microservices vs spring boot which embeds a container/server to create a single microservice.
 
Tetiana Fydorenchyk
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, as I mentioned before we prepared an article with some tips connected with Java memory usage: we tested different garbage collectors and some specific settings in order to find out which one works better in terms of efficient RAM consumption. So you can check out the results with examples and graphs here.

If in short, the G1 in combination with automatic vertical scaling won the race. Also, great results and no need in calling Full GC showed Shenandoah (but consider that it is still experimental currently).
 
Creator of Enthuware JWS+ V6
Posts: 3395
312
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations Kent O. Johnson,

Your question has made it to our Journal  

Have a Cow!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic