Monday, July 11, 2011

Easy Java Performance Tuning: Manage Objects By Size On The Java Runtime Heap

The Problem?

For those of you who use caching with frameworks like Hibernate, Spring or anything else, you know what a pain performance tuning can be. The tools you have available for tuning, resource management and avoiding OOME's boil down to counts and age controls. These are actually not resource management controls at all. They are data freshness controls and should be treated as such.

How do you even begin to figure out how many entries to allow in each Hibernate cache when you have a hundred of them? What if things change and objects get bigger, or smaller. What if you change your heap size and/or usage patterns?

You've Gotta Try This...

With Ehcache 2.5 you can just specify a percentage of heap or a heap size in bytes that your graphs of Java objects are allowed to use. This is accomplished by passing a simple size description into a Cache or CacheManager. All objects held onto by the cache will borrow their space from the cache's or manager's specified pool. Entries will get evicted from the cache as space runs low without any intervention from the developer. This can be done at the Cache Tier level whether it's on heap, disk or BigMemory. It's another way to reduce tuning, improve performance while avoiding OOME's. Learn more here.

If you do things in config or in code it's just a one line change:

A few More Details...

It works on any 1.5 or 1.6 JVM (Tested on Oracle, JRocket and IBM). Doesn't require any object serialization for the on heap management.

Learn More:

Try it out and give us lots of feedback on the Terracotta Forums:


  1. You churn out good stuffs. Just wondering why there hasn't been much activity in terms of comments? I really think these are stuffs developers and admins need to be aware of. Might be good if you could do more in terms of visibility of your blog posts. U might be surprised to know how many people are aware of some of these things yet "suffering" from problems being addressed.. Thanks btw for ur great posts.

  2. Thanks, what did you have in mind as far as visibility

  3. I actually did think about ur question b4 commenting. I think i got here via Dzone, but having some of your post feature on tech blogging sites would help. javablogs, dzone etc Not sure i got good suggestions myself.

  4. Thanks for the feedback. I do get posted on javablogs and I'll poke around and see what other options are out there.