I have heard few of my developer friends saying: “Garbage Collection is Automatic. So, I don’t have to worry about it“. First part is true my friends i.e. “Garbage Collection is Automatic” on all modern platforms – JVM (Java Virtual Machine), ART (Android Run Time)…. But second part is not true i.e. “I don’t have to worry about it”. Garbage Collection is automatic, but it’s not free. It comes with a price. In fact, price can be *very expensive*.
Poor Garbage Collection can lead to:
- Unpleasant user experience (SLA Breaches)
- Increase the bill from cloud hosting providers
- Puts entire Application Availability under risk
#1. Unpleasant user experience (SLA Breaches)
To garbage collect objects automatically, entire application must be paused intermittently to mark the objects that are in use and sweep away the objects that are not used. During this pause period, all customer transactions which are in motion will be stalled (i.e. frozen). Depending on the type of GC algorithm and memory settings that you configure, pause times can run from few milliseconds to few seconds to few minutes. Thus, Garbage Collection can affect your application SLA (Service Level Agreement) significantly. Frequent pauses in the mobile application can jank the app (i.e. stuttering, juddering, or halting). It can leave a very unpleasant experience with your user.
#2. Increase the bill from cloud hosting providers
Garbage collection consumes lot of CPU cycles. Each application will have thousands/millions of objects sitting in memory. Each object in memory should be investigated periodically to see whether they are in use? If it’s in use, who is referencing it? Whether those references are still active? If they are not in use, they should be evicted from memory. All these investigations and computation requires a considerable amount of CPU power.
Most applications saturate memory first before saturating other resources (CPU, network bandwidth, storage). Most applications upgrade their EC2 instance size to get additional memory rather to get additional CPU or network bandwidth. More object creation translates to more frequent Garbage Collection. Thus, you will end up buying more compute power. It will increase the bill from your cloud hosting providers.
#3. Puts entire Application Availability under risk
Sometimes garbage collection events pause the application for several seconds to several minutes. Sometimes garbage Collection events might run repeatedly When Garbage Collection runs repeatedly, no customers transactions will be processed. When Garbage Collection runs repeatedly, to recover from the situation, application has to be recycled. Such events can put your applications availability under risk.
Thus, to achieve ‘Wow’ user experience, reduce bills from hosting providers and increase your application’s availability, one would have to study and optimize the Memory/Garbage Collection settings. Tools such as GCeasy.io, HP Jmeter can help you to study and optimize the Memory/Garbage collection settings.
Every single day, millions & millions of people in North America—bank, travel, and commerce—use the applications that Ram Lakshmanan has architected. Ram is an acclaimed speaker in major conferences on scalability, availability, and performance topics. Recently, he has founded a startup, which specializes in troubleshooting performance problems.