16 August 2012

Inside the JVM: Garbage Collection – Living the Java High-life

To most Java developers, the Java Virtual Machine doesn’t really register on their radar – it’s a tool that they use to run their applications and nothing more. Its internals, features and workings are a complete mystery and many developers are quite happy for it to remain that way – after all, what impact does the JVM have on delivering functionality to customers. It’s not uncommon for developers to put more thought and effort into considering the operating system that their application runs on than the JVM.

In some ways, all this is a Good Thing™ , it means that the JVM is doing its job right – in 80% of cases developers don’t need to even recognise that it exists. But that doesn’t mean that it isn’t worth understanding a bit about how it works. Understanding the internals of the JVM can help you write better applications, find faults, and fix them faster. This blog is the first part of a series covering key aspects of the Java Virtual Machine.
 

Thanks for all the memories

Most developers are familiar with the concept of “garbage collection” they know that they don’t need to worry about allocating and de-allocating blocks of memory, although to those lucky enough to not have been brought up on C/C++, they might not really know what that means. When you need to store something in a program, you need to allocate a segment of memory for it, the size of that segment depends how bit the thing you want to allocate is, and if you don’t know how bit it is, you have to take a guess and add a bit more for safety. Because the amount of memory in computers is finite, if you never free memory up, you will eventually run out. Programming languages like C and C++ provided developers with explicit calls to allocate and de-allocate segments of memory. Developers would be responsible for keeping track of when they no-longer needed a segment of memory and freeing it up, so that the space could be re-used for something else. One of the most common causes of application crashes was memory leaks, usually caused by a developer forgetting to put a call to free() somewhere that it was needed.

This approach works as a solution, but places a lot of emphasis on the developer to focus on minutae that are not directly related to solving the business problems. Like many problems, this need to track used memory and free it up when it is no longer needed can be solved by computers – we can get a computer to clean up its own memory, this process is called Automatic Garbage Collection, and is what the Garbage Collector in the JVM does for you.

Talking Trash

It’s not quite as simple as it sounds though, there are a number of ways that you can track and clear up memory that is no longer needed, and like many algorithms, the obvious ones turn out to not necessarily be the most efficient, due to a number of subtle factors. There are a number of algorithms available to the JVM for garbage collection, and within those algorithms, a great many tuneable factors. Recent Java Virtual machines do a very good job of calculating which algorithms and settings will be the best for your application (a JVM feature called GC Ergonimics works this out) but it doesn’t always make the best choice, so its worth understanding some of the principals behind modern garbage collectors.

You can think of garbage collection as being like having a live-in maid to clean your house. She is there all the time, but she doesn’t follow you around picking up behind you, because this is not the most effective way to clean the house, instead, whenever the house gets above a certain threashold of ‘dirtiness’, she will blitz the whole house, top to bottom, before going back to reading her copy of Hello magazine. Java garbage collection takes a similar approach, it doesn’t constantly run, cleaning up behind you, it is triggered by certain events it will pause the execution of application code (to ensure consistency) in what is called a ‘stop the world event’ and clear up as much memory as it can.

Talking about My Generation

The single most important advancement in the development of garbage collectors came very early on in development, with the realisation that memory allocation in Java follows something called “The theory of infant mortality” – that is, most objects become garbage very soon after they are allocated, with only a few objects hanging around for long periods of time. This happens because many objects are created inside loops, and once the loop exits the object goes out of scope, and can be collected. To take advantage of this, all modern garbage collection algorithms do something called “generational garbage collection”, that is, they divide the memory space into several different areas, and run the garbage collector more frequently over the areas in which new objects are created. These areas are referred to as the new generation (comprised of an eden space, and two survivor spaces), and the old (or tenured) generation. Objects are created in Eden, are moved to the survivor spaces, and eventually on to the old generation. The new generation contains a lot of garbage, but can be kept quite small, it can therefore be collected using a fast but space-inneficient algorithm. These young generation collections are frequent but take just a few ms to compete, so are hardly noticeable. The old generation is normally much larger, and the efficient use of this memory space is more of a priority, however garbage collection can occur much less frequently here, so we can use a slow, but space-efficient algororithm. Garbage collections that collect the old generation as well as the young generation are called full garbage collections, and can take hundreds of milliseconds to several seconds to run, which is far more noticeable to users. There is also a space called the Permanent generation, where data that it used to be thought would never become irrelevant (such as class data etc) is stored. Recent JVMs have also included garbage collection of the permanent generation though, and Oracle’s Jrockit JVM does away with it altogether. 

Garbage collection tuning, is therefore about picking the right algorithms for the various memory spaces, based on the rate of objection creation and the number of retained objects (together with the specifications of the machine), sizing the memory spaces correctly, and aiming to keep the number of full garbage collections low.

Down the rabbit hole

Hopefully this has given you some interesting background into the kind of complexity and features that make up a modern Java Virtual machine, and inspired you to learn more. If you are interested, we are running a webinar on this subject on Friday 24th August 2012, which you can register for here: https://www4.gotomeeting.com/register/528726463 

Matt Brasier
@mbrasier

3 August 2012

MIDDLEWARE INSIGHT - C2B2 Newsletter Issue 2

MIDDLEWARE INSIGHT
at the Hub of the Middleware Industry
delivered to you by C2B2 Consulting - The Leading Independent Middleware Experts
Welcome to the second issue of Middleware Insight – a newsletter that brings you only the most recent, most important and most interesting news from the middleware industry.
There have been a lot of things happening lately in the middleware world, especially for Red Hat who have recently announced the release of JBoss EAP 6. Following this announcement, many articles and blog posts about JBoss have been published - you can find the links to the most interesting ones below.  
In this issue we also give you an overview of what other vendors are up to; we bring you some interesting posts about Infinispan, present our view on Oracle and Red Hat debate (WebLogic vs JBoss) and remind you about conferences and other events you may want to attend.
We hope that you will find this newsletter interesting and informative. If you have any questions, feedback or suggestions – please do not hesitate to contact us at info@c2b2.co.uk

Many thanks
C2B2 Consulting Team



JBOSS & RED HAT
 
JBoss EAP 6
Interview with Mark Little, JBoss CTO - read more 
JBoss EAP 6 as light as Raspberry PI? See the article 
C2B2 run a series of live webinars about JBoss EAP 6, you can now have a look at the recordings:  JBoss EAP6 First Look  & JBoss EAP6 Domain Mode Features 
Red Hat Summit & JBoss World
Red Hat Summit and JBoss World 2012 took place in Boston between 26th and 29th of June. To see the information about the events including keynotes, presentations and gallery click here  
For the JudCon Boston 2012 presentations and event gallery visit JBoss website . You can also readthe report from the event written by Mark Addy, C2B2 Senior Consultant, who presented at JUDCon this year. 
Other JBoss/Red Hat News:
Apache Camel celebrates 5 years in development with 2.10 release - find out more
JBoss Tools 3.3 and Developer Studio 5.0 final releases are now available - find out more
There's been a lot of articles published about Red Hat's recent acquisition of  Fuse Source: 
  • The Register: Red Hat snaps up open source SOAer FuseSource 
  • SearchSOA: Red Hat buys FuseSource to gain added application integration skills and tools 
  • Steve Millidge, C2B2 Director, also expressed his view on the Red Hat's Fuse Source acquisition in the blog post 
Infinispan:
The last two months brought us some interesting news and posts and about Infinispan:
  • Infinispan 5.1.5 goes FINAL! Read more
  • Infinispan Event push over Tomcat Websocket via HornetQ: read the blog post here
  • Mark Addy presented his talk about Infinispan at JUDCon Boston in June, you can have a look at his presentation here 

ORACLE

Oracle is getting ready for JavaOne 2012 - the conference will take place between 30th of September and 4th of October in San Francisco  The company has also announced the Java Embedded conference that will run at JavaOne 2012 - more information can be found in the press release 
C2B2 Director - Steve Millidge and Senior Consultant Nick Wright will be speaking at JavaOne 2012 - you can find more information about their talks on our blog 
In June Oracle released the Java SE Critical Patch Update Advisory, find out more on the Oracle website 
The article Introducing Groovy by Jim Driscoll, published in July, can help you master the basics of Groovy, a general-purpose scripting language that runs on the Java Virtual Machine (JVM) - see here 
Oracle has recently published a blog post about why you should choose WebLogic 12c instead of JBoss EAP 6. We did not have to wait long for JBoss to respond - see the post here. The articles make a very interesting reading - Matt Brasier, C2B2 Head of Consultancy, expert in both WebLogic and JBoss expressed his view on this debate - see our blog to read more. 

VMWARE
RabbitMQ gets significant upgrade from VMware - find out more on Jaxenter website  
VMware Explains Em4J - Get More Java Apps Per Server ,read more here 
Beth Brown's post, published on the vFabric Blog, gives you an overview of the 10 features of an Agile App Platform - click here to find out more 

IBM
WebSphere Application Server V8.5 - including the lightweight Liberty Profile - became generally available in June, read more at the WASdev website and Web Age Dev Zone blog

OPEN SOURCE
GlassFish Server 3.1.2.2 is Now Available - find out more 
SpringSource founder Rod Johnson leaves after a decade at the helm - read the article here  

EVENTS 
London JBoss User Group next meetup announced - 22nd of August 'JBoss EAP 6 - JBoss for the enterprise' by Matt Brasier, click here to find out more and register 
Data Grids Explained - free hands-on technical workshop by C2B2 - 4th of September - London -register here 
VMworld 2012 - San Francisco (August) and Barcelona (October) - register here 
SOA, Cloud Computing & Service Technology Symposium - C2B2 is speaking! - London (September) -register here 
JavaOne 2012 -San Francisco (September & October) - C2B2 is speaking! - register here 
Jax 2012 - London (October) - C2B2 is speaking! - register here 
SpringOne 2GX 2012 - Washington (October) - register here  
Devoxx 2012 - Antwerp, Belgium (November) - register  here 
UK Oracle User Group Conference - Birmingham (December) - C2B2 is speaking! register here 

1 August 2012

Real Life WebLogic Performance Tuning - C2B2 is Speaking at the UKOUG Conference 2012

Steve Millidge, C2B2 Director, will be speaking at the UK Oracle User Group Conference 2012 in Birmingham on the 3rd of December 


TitleReal Life WebLogic Performance Tuning: Tales and Techniques from the Field 

Date and Time: Monday, 3rd of December, 11:50 - 12:35

Presentation Abstract:

WebLogic delivers the industry standard in performance and High Availability. However many applications in the field have performance and scalability issues. This presentation takes you through the tools and tricks of the trade of a performance specialist who has spent many years tuning WebLogic large scale production applications since version 6.x. You will learn the standard process used for diagnosis and then through practical demonstrations we will track down typical performance problems using the standard tools available in WebLogic, JRockit and other tools. We will then cover some real case studies of system problems and how they were solved.

Speaker Bio:

Steve is the director and founder of C2B2 Consulting Limited. C2B2 is an Oracle Application Grid Specialized Gold Partner in the UK. C2B2's focus is exclusively on achieving non-functional requirements thereby ensuring Oraclebased solutions go live; Fast, Reliable, Manageable and Secure. Steve has used Java extensively since pre1.0 and has been a field based professional service consultant for over 15 years. Through C2B2 he now focuses exclusively on the configuration of Oracle's JEE and SOA infrastructure for maximum Scalability, Performance, Availability, Recoverability, Manageability and Security. Having worked for and on behalf of Oracle, BEA professional services he has extensive experience of deploying large scale production Java systems. Steve is an expert group member of JSR107 (Java Caching), JSR286 (Portlets) and JSR347 (Data Grids). Steve has spoken at a number of events including Java One, UK Oracle User Group Conference, UK Coherence SIG, The Server Side Symposium, Community One and regularly presents technical workshops on Oracle Coherence in the UK. Prior to founding C2B2, Steve was a Principal Consultant in Solution Architecture at Oracle UK where he was an architect of Ordnance Survey’s Master Map project to deliver digital mapping data over the web and also worked on a large integration application for the Foreign Office. Steve has many years experience of building large scale web applications and was an architect for the Tour De France’s web infrastructure.