Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Setting the heap size on your JVM

Cameron has posted a comment on my Performance Tuning MySQL article. The reason I'm highlighting this because it's something I wasn't are of:

From the article:

    -Xms128m -Xmx256m

The Sun JVM will run significantly faster with the following config instead:

    -Xms256m -Xmx256m

That's because the Sun implementation acquires and releases memory from / to the OS way too aggresively if the "ms != mx". Furthermore, either your server has the 256MB available or it doesn't. If you don't have it available, don't set the max that high. If you do have it available, you gain nothing from setting the min lower. This isn't a desktop system, it's a server -- make sure you have the necessary resources and if you do then use them!

Time to change all my heap size setting since I've been using the first setting (128/256) for quite some time. Thanks Cameron! The real question is: will changing "-Xms256m -Xmx512m" to "-Xms512m -Xmx512m" speed up my slow-ass PowerBook? ;-)

Posted in Java at Apr 28 2004, 09:16:00 AM MDT 7 Comments
Comments:

Sorry, posting noising msg here. FYI. Today, i made appfuse work with UTF-8 character 1. use displaytag-rc1; 2. specify mysql jdbc driver:autoReconnect=true&useUnicode=true&characterEncoding=utf-8; 3. add a SetCharacterEncodingFilter.java, and mapping info to filter-mappings.xml file; 4. finally, add pageEncoding="UTF-8" contentType="text/html; charset=utf-8" to taglibs.jsp now, it works with chinese character both in pages and database.

Posted by Paul Wang on April 28, 2004 at 09:39 AM MDT #

In respect of heap tuning, one of my favourite tools is jvmstat:
http://developers.sun.com/dev/coolstuff/jvmstat/
Using this tool you can establish what kind of memory usage your app exhibits and look at how gc is affecting performance. Then you can tune the heap size to you heart's content.

Posted by Dan Creswell on April 28, 2004 at 10:17 AM MDT #

Doh! Forgot to mention this which you may/may not have seen:

http://java.sun.com/docs/hotspot/gc1.4.2/index.html

It talks very specifically about how the JVM manages memory given a specific min and max and explains why the heap size varies when mx and ms are not the same.

Posted by Dan Creswell on April 28, 2004 at 11:05 AM MDT #

An interesting tidbit that I wasn't aware of. Still, I'm unwilling to do this on my box where Tomcat and MySQL are both running. For a box running shared services (e.g. JVM and other applications) it seems more efficient to set the max high enough to provide significant space for the JVM when required, but not to tie up the memory otherwise.

Posted by Unknown on April 28, 2004 at 12:56 PM MDT #

oops, forgot to sign my last post.

Posted by Will on April 28, 2004 at 12:56 PM MDT #

These settings are dependent on your application and your systems. I think one has to understand what the implications are of setting the maximum and minimum heap size.

If you have a huge difference between the minimum and maximum heap size then your system will have to free up the un-referenced memory for a longer time: as a consequence your JVM blocks for a long time. If your system is powerful enough, and you don't have a real-time system, blocking of 0.5 seconds might not be an issue. This has the advantage that the GC will not run as often.

On the other hand when you are working with a mission-critical application and your system is slow then it is wise to set the minimum and maximum heap size almost equal. The result is that the GC will run more often but the each cycle will not take so long.

It is a matter of observing your application instead of a blind copy and paste from a tutorial.

The quote above is correct: the JVM will run faster but the GC will also run more often and will block your application more often, however for a very short period.

Posted by Thomas De Vos on April 28, 2004 at 03:56 PM MDT #

Many of the JVM vendors and JVM developers (e.g. Joseph Coha at HP) are starting to discourage this practice with the newer VMs. In a tuning webinar yesterday, Coha told to "minimize the number of JVM options" specified on the command line. The newer VMs are all implementing self-tuning technology that help the VM adapt to its runtime environment. With some of the more innovative advancements, VM not only adapts to the startup environment (i.e. available memory), but will adapt to runtime conditions (increased utilization of the application) dynamically. Specifying runtime memory management options can negatively impact the VMs ability to use its self-tuning. JRockit already has some of these features built into it. The Sun VM has early implementations available as a command-line option (-XX:UseAdaptiveSizePolicy or something similar). The HP webinar should be available within a few days. No, I don't work for HP. Coha did a series of three tuning seminars that I think are valuable, especially the first and third.

Posted by Peter on April 29, 2004 at 06:40 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed