Recently I heard Kirk Pepperdine speak about changing garbage collectors for better performance — but what exactly does that mean and what makes one garbage collector better or different than the other?
Recently I heard Kirk Pepperdine speak about changing garbage collectors for better performance —
Share
You ask two questions:
What does it mean to change garbage collectors in Java for better performance?
This is a huge topic, and like some of the other responders, I urge you to do some reading. I recommend Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning from Sun. The information below mostly comes from there. The “turbo-charging” java article recommended in another answer is older.
In brief, one of the many options we have when running the JVM is to select a garbage collector, of which there are presently three:
What makes one garbage collector better than another?
Your application does. Each of the garbage collectors has a “sweet spot” – a range of application profiles for which it is the superior collector.
First, know that the VM is pretty good at selecting a collector for you, and as with most optimizations, you should not consider second-guessing it until you’ve identified that your application is not performing well, and that garbage collection is the likely culprit.
In that case, you have to ask these questions: 1) is your app running on a single-processor machine, or multi? 2) Are you more concerned with “minimizing pause time”, or with “maximizing throughput”? That is, if you had to choose between the application never pausing but getting less work done overall, versus getting more work done overall, but pausing from time to time, which would you pick?
Roughly speaking, as a starting point:
Again, though, the VM does a pretty good job of selecting a collector for you, and you’re better off not overriding that unless and until you discover that it’s not working well enough for your application.