JVM Performance Tuning


  1. Minimizing memory footprint usually comes at the expense of throughput and/or latency.
  2. Reducing the number of JVM affects the level of availability of the application.

Theses are further discussed briefly in the following topics.

JVM Deployment Model

Availability, manageability, and memory footprint systemic requirements play a role in choosing an appropriate JVM deployment model.

  1. Single JVM Requirement Model
    1. Reducing the manageability cost
  2. Multiple JVM Requirement Model
    1. one JVM fail only affects a portion of an application
    2. Lower latency
    3. Small java heap size, therefore, shorter GC pauses
    4. Distributing the load across multiple JVMs may allow the application to scale to higher load.
    5. monitoring, managing, and maintaining multiple JVMs requires more effort than a single JVM.

JVM Runtime Environment

  • 32 bit -> rapid startup time and small memory footprint, high throughput
  • 64 bit -> high throughput
    1. -d64 -XX:+UseCompressedOops
    2. ^ by default based on maximum Java heap size.
  1. Client Runtime
  2. Server Runtime
  3. Tiered Runtime
    1. Java 6 Update 24 above
    2. Best of Client and server runtime
    3. -server -XX:+TieredCompilation

Garbage Collectors



Throughput (parallel)

-XX:+UseParallelOldGC or -XX:+UseParallelGC

1st one enables both young and old multithreaded GCs


concurrent mark sweep (low latency gc)


garbage first


Systemic Requirement

Systemic Requirement



[1] Availability

[2] Manageability

[3] Throughput

[4] Latency and Responsiveness

[5] Memory Footprint

[6] Startup Time

[1] Application being in the operational and usable state.

    1. Failover requirements.
    2. Multiple JVM
    3. High manageability cost

“the application shall be deployed in a manner in which an unexpected software component failure does not render the entire application unusable.”

[2] a measure of the operational costs associated with running and monitoring the application along with ease of configuration

“the application shall be deployed in the fewest possible number of JVMs due to limited staffing resources.”

[3] A measure of the amount of work that can be performed per unit time.

    1. comes at the expense of either an increase in latency and/or an increase

in memory footprint.

“the application shall execute 2500 transactions per second.”

[4] a measure of the elapsed time between when an application receives a stimulus to do some work and that work is completed

    1. Ignores throughput
    2. increases responsiveness

“the application shall execute trade requests to completion within 60 milliseconds.”

[5] a measure of the amount of memory required to run an application

    1. an increase in memory footprint via an increase in Java heap size can improve throughput or reduce latency, or both.

“the application shall execute on a system having at least 8 gigabytes of memory as a single application or on a system with 24 gigabytes of memory with three additional application instances.”

[6] a measure of the amount of time it takes for an application to initialize

    1. HotSpot VM Runtime – Client
      1. Faster startup time
    2. HostSpot VM Runtime – Server
      1. a longer startup time
      2. highly optimized generated code
      3. higher throughput
      4. lower latency

“the application shall complete its initialization phase within 15 seconds.”

Determining Memory Footprint

1) For Performance:

    1. -XX:PermSize and -XX:MaxPermSize should be set to same value
    2. why? growing or contracting the permanent generation space requires full garbage collections
    3. Full garbage collection will decrease throughput and increase the latency
    4. If heap size is not specified, HotSpot VM will automatically choose values based on the system configurations it discovers through an adaptive tuning feature called ergonomics.

Java theory and practice: Dealing with InterruptedException

Many Java™ language methods, such as Thread.sleep() andObject.wait(), throw InterruptedException. You can’t ignore it because it’s a checked exception, but what should you do with it? In this month’s Java theory and practice, concurrency expert Brian Goetz explains what InterruptedException means, why it is thrown, and what you should do when you catch one.


Java Programming Dynamics

Part 1, “Java classes and class loading” (April 2003)

Part 2, “Introducing reflection” (June 2003)

Part 3, “Applied reflection” (July 2003)

Part 4, “Class transformation with Javassist” (September 2003)

Part 5, “Transforming classes on-the-fly” (February 2004)

Part 6, “Aspect-oriented changes with Javassist” (March 2004)

Part 7, “Bytecode engineering with BCEL” (April 2004)

Part 8, “Replacing reflection with code generation” (June 2004)

XML Standards – A List

In this series we will be talking about some of the following XML standards.


Introduction to XML

XML, extensible markup language, W3C standard introduced to overcome the limitations of successful HTML. Today, HTML can be rendered in almost any devices. The objective of HTML is to describe how web elements are rendered by computer to human. In another words, HTML is used for computer – human interaction. Consider the following example.

<p>Google Inc.
<br>1600 Amphitheatre Parkway
<br>Mountain View, CA 94043
<br><b>telephone:</b> +1 650 253 0000
<br><b>fax:</b> +1 650 253 0001

The above code will be rendered and the following will be the output.

Google Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
<strong>telephone:</strong> +1 650 253 0000
<strong>fax:</strong> +1 650 253 0001

By just looking at the output or/and the HTML code, a human mind can perceive that this is a postal address. However, computer cannot perceive this. Due to this limitation W3C introduces XML, which is mainly for computer to computer interaction.

Look at the following XML snippet.

<address type="company">
 <name>Google Inc.</name>
 <street>1600 Amphitheatre Parkway</street>
 <city>Mountain View</city>
 <telephone>+1 650 253 0000</telephone>
 <fax>+1 650 253 0001</fax>

For a computer, it is easier to understand and process data warped within XML. There are 3 terminologies that one should be familiar with. Those are: tag, element, and attribute. In above example, address, name, street, are tags, where is starts with ‘<’ and ends with ‘>’. Elements are the one that is being encapsulated within a tag. ‘Mountain View’ is the element of ‘city’ tag. Moreover, you may include tags within tags. In this case, elements of ‘address’ tag are name, country, fax, etc. Attributes, on the other hand, key-value pairs that carry properties of a tag. ‘type’ is a attribute of address; this example address is of a company.

XML is ubiquitous and platform independent. Therefore, it is a great mean of communication and data interchange among different entities throughout the internet.

There are certain properties in a XML document.

1) Elements are case sensitive. For example <test> tag should be closed with </test>.

2) If an element is empty, you can close the element in the first tag by having a forward slash ‘/’. As an example: Replace <img src=”../qbit.png”></img> with <img src=”../qbit.png” />.

3) It is recommended (but not required) to have XML declaration at the top of the document. XML declaration tag conveys information to parser.

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

This above example, version attribute is the XML version used, encoding is the character set used, and standalone conveys whether this document depend with other XML documents. UTF-8 is the Unicode Standard that included every character in world languages.

4) Comments are wrapped within <!– COMMENTS –>

5) Processing Instructions (PI) is a set of markup code intended for a particular framework. The following is a PI for Apache Cocoon, which is a XML processing framework.

<!-- Here's a PI for Cocoon: -->
<?cocoon-process type="sql"?>

6) There are Entities which you can as a replacement for some strings. For example, the following defines an entity, thus when &qbit; is used, it will be replaced with qbit-labs value. There fore few default  entities defined by the XML specification.

  • &lt; for the less-than sign
  • &gt; for the greater-than sign
  • &quot; for a double-quote
  • &apos; for a single quote (or apostrophe)
  • &amp; for an ampersand.

<!ENTITY qbit "qbit-labs">

7) Namespaces are used to distinguish and group certain attributes. In this post, we have used “name” as the name of the company. However, this “name” can be used as a name of a product. Because of this we use namespaces. Following is an example of namespace declarations.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<util:list id="addressList" list-class="java.util.ArrayList">
<custom:list id="nameList">

In above example there are 2 list elements, where one belongs to util and the other belongs to custom namespace. Value for xmlns (XML Namepace) is always a string and a xml parser with interpret it just as a string. You may have any string which you prefer. However, a URL is used as the value because it should be unique.


So far we have covered the basics of XML. This post is based on IBM developerWorks “Introduction to XML” tutorial up to section 3 out of 10 sections. You may find it here.


Web Services Series

From this post, I am inaugurating a series of sessions on web service technologies. Starting from basics of Web Services, SOAP, XML, HTTP, RESTful, WSDL, SoapUI to JAXB, JAX-RS, JAX-WS, Apache CXF, Axis2, and Java Service Wrapper. I am hoping to cover theories and hands on code examples on most the important technologies. All the codes will be hosted at GitHub and I will share the links to the repos while we move forward with the series.  My main objective of this series is to give the practical knowledge on the web services and its technologies widely used in the industry, hence you would not see in-detailed  theories sometimes. Resourceful links will be shared with you, if you are interested to gain more information on the technologies.

Series Category Link: http://qbit-labs.org/category/web-services/

GitHub: https://github.com/azeemigi

Setting Up Samba File Server


Samba file server is a free and open software that provides cross platform file and print services, by implementing Server Message Block (SMB) protocol for UNIX system, and facilitates interoperatability between UNIX & Windows.

More Information on Samba can be found here.

In this post, I will show how easily Samba server can be configured on Ubuntu and how one can secure it with username and password.


sudo apt-get install samba


1) Add a new system user. For the example, let’s create a user called “samba-user”.

sudo useradd samba-user

2) All Samba server configurations are found in /etc/samba/smb.conf. Using vim or any editor, open this file,

sudo vi /etc/samba/smb.conf

Append the file with the following snippet with appropriate changes

     comment = Samba File Server
     path = /PATH/TO/FOLDER
     browsable = yes
     guest ok = no
     read only = no
     create mask = 0755

In above snippet,

  • [share]: is the uri/alias to the shared location
  • comment: a short description
  • path: an absolute path to the folder that need to be shared
  • browsable: browse the shared directory with Nautilus or Windows Explorer
  • guest ok: if true, anyone can connect and view the files and folders in the shared directory
  • read only: if true, users are not allowed to delete and add new folders and files
  • create mask: permission that new files and folders will have

4) In /etc/samba/smb.conf, you will see key/value paired properties for  [global].

Change the workgroup to the workgroup/NT-domain name your Samba server will part of.

workgroup = WORKGROUP

Now find and uncomment the following line

security = user

Here, the value for the “security” key, determines the level and type of security methods enforced to your samba server.  SMB protocol, defines 2 levels of security; user-level and share-level. Samba’s security provides 4 ways to implement user-level security and 1 way to implement share-level security. In this post I am using the user-level security with username and password authorization. For more information regarding the security, please read this article.

5) Username and Password

Now, let’s add “samba-user” to the Samba service with a password.

sudo smbpasswd -a samba-user

6) Now the server is successfully configured. You need to create the directory that you wants to share and change the permission to the intended user (i.e. samba-user).

sudo mkdir -p /PATH/TO/FOLDER
sudo chown -R samba-user.samba-user /PATH/TO/FOLDER

7) Now restart the samba service.

sudo restart smbd


Now the service is up and running.

1) Linux Users

Open the nautilus, and activate the location bar if not visible. (CTRL + L or in the menu bar click Go -> Location)

Execute by replace the IP of your Samba server:


2) Windows Users:

On the Windows Explorer, execute by replace the IP of your Samba server.


If successful, you will be prompted a dialog box, as following.