Welcome!

Java IoT Authors: Stackify Blog, Yeshim Deniz, Liz McMillan, Pat Romanski, Jason Bloomberg

Related Topics: Java IoT

Java IoT: Article

Know Your Worst Friend, the Garbage Collector

It can make or break performance

The first one is called incremental garbage collection. As its name suggests, this mode does a bit of major collecting every time a minor collection is run. Global performance suffers from this execution mode but you get rid of those nasty pauses caused by major collections. Incremental garbage collection also tends to leave the heap in a fragmented state. So it's a good idea to limit its use to applications with long-lived objects. It can help you in a subtle way to obtain more responsive Swing UIs.

The second mode is a parallel GC using many threads at once, at least one per processor, to do minor collections. If your target computer has less than three processors, it is unlikely you will ever notice a difference. This option is particularly well suited to heavy servers running applications spawning many short-lived objects like web servers.

Finally yet importantly, a concurrent GC can do incremental major collection without interrupting the application for long periods of time. A concurrent GC can also use parallel execution for minor collections. According to Sun Microsystems, this execution mode gets good results with interactive applications running on a single-processor computer. To choose among these three modes and set them up, you need to use the following command-line flags:

  • -Xincgc activates incremental garbage collection.
  • -XX:+UseParallelGC activates the parallel GC. The number of threads used to do minor collections is defined by the -XX:ParallelGCThreads=<a number> flag.
  • -XX:+UseConcMarkSweepGC activates the concurrent GC. Parallel minor collections can be activated as well by using the -XX:+UseParNewGC flag.
To measure the impact of your choice on your application, you'll want to use the –verbose:gc command-line flag. You'll then get a GC activity trace on the standard output. Redirecting the standard output to a file and running the following Python script will let you draw very useful charts as shown in Figure 2.

This script can be used by specifying a file name as the first parameter or by piping it directly to the Java command.


#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-

import fileinput
import re

print "%s\t%s\t%s\t%s" % ("Minor", "Major", "Alive", "Freed")

for line in fileinput.input():
match = re.match("\[(Full )?GC (\d+)K->(\d+)K\((\d+)K\), ([^ ]+) secs]", line)
if match is not None:
minor = match.group(1) == "Full " and "0.0" or match.group(5)
major = match.group(1) == "Full " and match.group(5) or "0.0"
alive = match.group(3)
freed = int(match.group(2)) - int(alive)
print "%s\t%s\t%s\t%s" % (minor, major, alive, freed)

The result is a CSV document using tabs as separators and containing four columns of data. The first one gives the time consumed by the GC to do a minor collection, the second one gives the same information for a major collection, the third one indicates the amount of memory used by the application after the execution of the GC and the last one gives the amount of memory reclaimed by the last collection. (This script was inspired by an AWK script written by Ken Gottry in the article Pick up performance with generational garbage collection published on javaworld.com.)

The chart presents the running time of each collection performed by the GC during the application life cycle. This chart was generated with the following command line and OpenOffice.org:


$ java -verbose:gc -Xms64m -Xmx128m -XX:NewRatio=2 -XX:+UseConcMarkSweepGC -jar ../lib/jext-5.0.jar > gclog
$ gclog2csv.py gclog > gclog.csv

Although simple, this small script can help you tune your application pretty quickly. As of J2SE 5.0, Sun Microsystems provides a more powerful tool called JConsole that will graphically monitor the state of the heap and the activity of the GC as shown in Figure 3.

Further Reading

  • Java HotSpot VM Options, Sun Microsystems, http://java.sun.com/docs/hotspot/VMOptions.html
  • A Collection of JVM Options, Joseph Mocker, http://blogs.sun.com/roller/resources/watt/jvm-options-list.html
  • Pick up performance with generational garbage collection, Ken Gottry, www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc-p4.html
  • Garbage Collection in the Java HotSpot Virtual Machine, Tony Printezis, www.devx.com/Java/Article/21977?trk=DXRSS_JAVA
  • Garbage Collection Performance, Brian Goetz, www-106.ibm.com/developerworks/java/library/j-jtp01274.html
  • Using JConsole to Monitor Applications, Mandy Chung, http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html
  • Comments (1) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    Suresh 05/31/05 01:44:21 PM EDT

    cannot go to page2!!!!

    @ThingsExpo Stories
    In his session at @ThingsExpo, Dr. Robert Cohen, an economist and senior fellow at the Economic Strategy Institute, presented the findings of a series of six detailed case studies of how large corporations are implementing IoT. The session explored how IoT has improved their economic performance, had major impacts on business models and resulted in impressive ROIs. The companies covered span manufacturing and services firms. He also explored servicification, how manufacturing firms shift from se...
    The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta Chakraborty, Chief Customer Officer at Ayasdi, will provide a tactical framework to become a truly intelligent enterprise, including how to identify the right applications for AI, how to build a Center of Excellence to ...
    SYS-CON Events announced today that Massive Networks will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
    SYS-CON Events announced today that CAST Software will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CAST was founded more than 25 years ago to make the invisible visible. Built around the idea that even the best analytics on the market still leave blind spots for technical teams looking to deliver better software and prevent outages, CAST provides the software intelligence that matter ...
    Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution and join Akvelon expert and IoT industry leader, Sergey Grebnov, in his session at @ThingsExpo, for an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
    Because IoT devices are deployed in mission-critical environments more than ever before, it’s increasingly imperative they be truly smart. IoT sensors simply stockpiling data isn’t useful. IoT must be artificially and naturally intelligent in order to provide more value In his session at @ThingsExpo, John Crupi, Vice President and Engineering System Architect at Greenwave Systems, will discuss how IoT artificial intelligence (AI) can be carried out via edge analytics and machine learning techn...
    SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
    In his session at @ThingsExpo, Arvind Radhakrishnen discussed how IoT offers new business models in banking and financial services organizations with the capability to revolutionize products, payments, channels, business processes and asset management built on strong architectural foundation. The following topics were covered: How IoT stands to impact various business parameters including customer experience, cost and risk management within BFS organizations.
    SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
    SYS-CON Events announced today that Pulzze Systems will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Pulzze Systems Inc, provides the software product "The Interactor" that uniquely simplifies building IoT, Web and Smart Enterprise Solutions. It is a Silicon Valley startup funded by US government agencies, NSF and DHS to bring innovative solutions to market.
    From 2013, NTT Communications has been providing cPaaS service, SkyWay. Its customer’s expectations for leveraging WebRTC technology are not only typical real-time communication use cases such as Web conference, remote education, but also IoT use cases such as remote camera monitoring, smart-glass, and robotic. Because of this, NTT Communications has numerous IoT business use-cases that its customers are developing on top of PaaS. WebRTC will lead IoT businesses to be more innovative and address...
    WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, will introduce two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a...
    When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
    SYS-CON Events announced today that CA Technologies has been named “Platinum Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business – from apparel to energy – is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
    SYS-CON Events announced today that Elastifile will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Elastifile Cloud File System (ECFS) is software-defined data infrastructure designed for seamless and efficient management of dynamic workloads across heterogeneous environments. Elastifile provides the architecture needed to optimize your hybrid cloud environment, by facilitating efficient...
    SYS-CON Events announced today that Golden Gate University will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Since 1901, non-profit Golden Gate University (GGU) has been helping adults achieve their professional goals by providing high quality, practice-based undergraduate and graduate educational programs in law, taxation, business and related professions. Many of its courses are taug...
    Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
    When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
    WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web communications world. The 6th WebRTC Summit continues our tradition of delivering the latest and greatest presentations within the world of WebRTC. Topics include voice calling, video chat, P2P file sharing, and use cases that have already leveraged the power and convenience of WebRTC.
    An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics ...