The Art of Java Application Performance Analysis and Tuning – Part 1

This is the first article in the series of articles exploring the tools and techniques for analyzing, monitoring, and improving the performance of Java applications.

The Art of Java Application Performance Analysis and Tuning-Part 2                                     The Art of Java Application  Performance Analysis and Tuning-Part 3                                       The Art of Java Application  Performance Analysis and Tuning-Part 4                                    The Art of Java Application  Performance Analysis and Tuning-Part 5                                          The Art of Java Application  Performance Analysis and Tuning-Part 6                                     The Art of Java Application  Performance Analysis and Tuning-Part 7

In this blog we are going to discuss  basic terminology and performance methodology.

 Basics

Excerpts from the book “Java Concurrency In Practice” by Brian Goetz..

Application performance can be measured in a number of ways, such as response time, latency, throughput, scalability, or capacity.  Some of these (response time, latency) are measures of “how fast” a given unit of work can be processed or acknowledged; others (capacity, throughput, scalability) are measures of “how much” work can be performed with a given quantity of computing resources.

Throughput is the amount of work that a application can do in a given time period.

Example: Number of  Jobs  completed in a hour.

Scalability describes the ability to improve throughput or capacity when additional computing resources (such as additional CPUs, memory, storage, or I/O bandwidth) are added.”

Example: Say a Java application can complete 100 Jobs in 10 hours  on a given hardware/DB configuration.  Can the application complete 200 Jobs in 10 hours by doubling/increasing hardware/DB configuration?
If  the application completes the above task without modifying the code then we say the application is scalable.

The “how much” aspects scalability, throughput, and capacity are usually of greater concern for server applications than the “how fast” aspects. For interactive/web applications, response time, latency tends to be more important, so that users need not wait for longer periods
to see the results.

Improving Application Performance?

Improving performance means doing more work with fewer resources.

Here “resources” means CPU cycles, Memory, network bandwidth, I/O bandwidth, database requests, disk space etc..  In practice the performance of an activity/application is limited by one or more of these resources. When the performance of an activity is limited by availability of a particular resource, we say it is bound by that resource: CPU-bound, Database-bound, I/O-bound etc.

What about your application? Is it CPU-bound? or Database-bound? or Memory-bound?

Tuning for throughput/capacity, the goal is usually to do the same work with less effort, such as by using better algorithms or using caching techniques.

Tuning for scalability, the goal is to find ways to parallelize the problem so you can take advantage of additional processing resources to do more work with more resources.

When Application Tuning is Required?

Safety always comes first. Here “safety” means the functionality of the application/program. First make your program right, then make it fast. And then tune further only if your performance requirements tell you it needs to be faster.

When Application Tuning is Required?

  1. If your application/feature is not performing as expected.
  2. On QA/Customer complaints
  3. If your Project requires

If an application is performing as well as expected, you don’t need to put additional efforts to enhance its performance.

Performance Analysis and Tuning Methodology

Performance analysis and tuning is a iterative process.

Any performance tuning activity involves taking decisions and trade-offs. And these decisions/trade-off involve multiple variables (Application, O/S, DB, Cache) and are specific to project requirements. So before deciding that one approach/decision is “faster”/”better”
than another, we need the understand the effect these decisions..

So for each of the performance decisions we need to understand

Under what conditions will this approach actually be faster?

Example: Hardware/DB configuration, Application Settings, Cache Settings etc..

Under light or heavy load?

Example: No. of parallel threads,  thread count, No. of Concurrent Clients, No. Of  Processing Threads etc..

With large or small (input/processing) data?

Example: small database,  large database

All performance decisions should be supported with measurements.

Fig A. shows a flow chart from the book Java Performance  co-authored by Charlie Hunt and Binu John. This chart shows the process of Java application performance tuning.

Performance Tuning Methodology

Fig A. Performance Tuning Methodology

Performance tuning exercise should be accompanied by

  1. Concrete performance requirements. So that you know the target performance and know when to end the tuning activity.
  2. Test Program/Time Stamps/Logs to measure the program
  3. Required load/data/input to test the program

Step 1: The process starts with setting concrete performance requirements.

Step 2: After we have the baseline data, we are ready to begin our performance tests by increasing the load (or) increasing the data size/network size (or) increasing the input size.

Step 3: We need to measure/analyze the application using tools like thread dump , JConsole and profiler etc.

Step 4: From the performance analysis/results collected, we can identify the bottlenecks that may have caused issues such as slow response times and high resource usage.

Step 5: Make the required application/configuration changes.

Step 6: Measure again after tuning/making changes to verify that you’ve achieved the desired improvements.

Step 7: Repeat above steps until you meet your performance requirements.

Reference:

http://www.amazon.com/Java-Performance-Charlie-Hunt/dp/0137142528

http://java.dzone.com/articles/principles-java-application

Required Skills

Application performance analysis/tuning requires systems knowledge.

For example, you need knowledge on

  1. Java virtual machines (Oracle Java, IBM Java)
  2. Operating Systems (Linux/Solaris/IBM AIX)
  3. Computer and Database architectures (MySQL/Oracle)
  4. Third Party Tools/libraries (Hibernate, Profilers etc.)

When you apply the systems knowledge on your application deployment, you can successfully tune an application.

Advertisements
Posted in java | Tagged , , | Leave a comment

Simplified Hadoop Versioning Image

Simplified Hadoop Versioning Image

Image | Posted on by | Tagged | Leave a comment

EhCache — Too Many Open Files

EhCahce with  “diskPersistent=true” flag  is used to persist  the cache values to disk and can be used after system restarts.

If you have many caches with “diskPersistent=true” then you may get “Too many Open files Exception”.  This is because EhCache is using nearly 30 open file pointers for each cache and the default no. of open files for user in linux is 1024.  So, to avoid this exception you need to increase the No. Of. open files  per  process/user.

Posted in java | Leave a comment

Hibernate – Oracle : Creating Index For Foreign-Key Columns

In Oracle adding Index for Foreign Key columns is  important for performance reasons.  And also if you are using transactions,  It is important to create index for FK columns.  With out  index your application may experience many deadlock problems.

These indexes are automatically generated for MySQL by Hibernate (In MySQL Index for FK columns is mandatory).  But these indices are  not generated for Oracle by Hibernate.

So we need to  explicitly mention indexes in hibernate mapping tables.

For hibernate  <list> </list>   objects we can use <database-object> tag for explicitly mention the create/drop index.

<hibernate-mapping>
……
……
<database-object>
    <create>CREATE INDEX  ACCOUNT_IDX ON Person(ACCOUNTID)</create>
    <drop>DROP INDEX ACCOUNT_IDX ON Person</drop>
    <dialect-scope name=”org.hibernate.dialect.Oracle10gDialect”></dialect-scope>
</database-object>
<hibernate-mapping>

 

Posted in Hibernate, java | Leave a comment

Airtel 3G datacard on Ubuntu 11.04/11.10

This procedure is for a Huawei E1731 USB modem that I got from Airtel.
1. Install wvdial
  sudo apt-get install -yq usb-modeswitch usb-modeswitch-data   wvdial
2. Configure modem (Make sure you replace the<phone number> placeholder with your actual phone number.

sudo gedit /etc/wvdial.conf

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
ISDN=0
Phone = *99***1#
Username = <Phone number>
Password = <Phone number>
New PPPD = yes
Modem = /dev/ttyUSB0
Baud = 406800
Stupid Modem = 1


3. Run wvdial

sudo wvdial

Posted in Uncategorized | Leave a comment

JacORB Configuaration

Add the following JacORB  properties to java command line or update in jacorb.properties file

To enable general debug logs add the below line

 -Djacorb.log.default.verbosity=4

To enable notification debug logs add the below line

 -Dorg.jacorb.notification.log.verbosity=4

To increase POA Queue. Increase this parameter, for connecting with many EMSs or for many parallel requests. Default value is 100

 -Djacorb.poa.queue_max=100

thread pool configuration for request processing

 -Djacorb.poa.thread_pool_max=100
 -Djacorb.poa.thread_pool_min=20
Posted in java | Leave a comment

Hibernate : Adding an enum as a property

Using Hibernate Annotations:

@Entity public class TestEntity {
   @Enumerated(EnumType.STRING)   
   @Column(name="ENUM_TYPE")   
   private TestEnum testEnum; 
}

Using XML Based Mapping :   Add  hibernate-annotations.jar in your classpath during deployment but there’s no compile-time dependency:

<property name="testEnum" length="30" column="testEnum" lazy="false">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">test.TestEnum</param>
<param name="type">12</param> <!-- To store enum value as VARCHAR -->
</type>
</property>
Posted in Hibernate, java | Tagged | Leave a comment