Monday, September 19, 2016

How to use VisualVM

      VisualVM can be very helpful to discover the performance lags in Java application.
 It is one of the easiest profiling tools for Java.

Download VisualVM

Run VisualVM and check local running java apps: 

Remote Profiling.
Run your java application with following JVM arguments:
Above parameters, makes your remote java application to listen to port 9010.
Then, you can connect to it from VisualVM by Menu->File->Add JMX connection
Type your hostname and port. Example:
(IP address of remote machine and port)

Performance Profiling
      After you connect to your app from VisualVM, go to "Sampler" tab and press "CPU" button.
It is important to sort by "Total Time(CPU)" to see high CPU consumers on the top of the list.
This gives you some idea, but it is not detail. So, to get detail information,
press "Snapshot" button, this opens you following view:

VisualVM allows you to real-time monitoring which functions are taking up high CPU usage.

This window is very important. From this, you can find which functions, classes,
or packages are causing your Java application to be slow.
It is the key approach to resolve performance issues in your java application.
You can play with sorting options, and navigate through callers,
and check other tabs "Host Spots" etc.

Memory Profiling
      Memory usage analysing is also similar to above. Press "Memory" button in Sampler window.
Sort by "Bytes" to see data types (or classes) which are consuming much memory on the top.
You can also take "Snapshot" to see more details about the monitoring status.

   VisualVM can be very helpful to monitor, analyse, tune Java Application Performance.
This is essential task while developing scalabale, distributed, high-performance applications.

Performance tuning for Web engine

Install Tsung on CentOS

1. Install Erlang:

sudo yum -y update && sudo yum -y upgrade
sudo yum install epel-release

sudo yum -y install erlang perl perl-RRD-Simple.noarch perl-Log-Log4perl-RRDs.noarch gnuplot perl-Template-Toolkit

2. Get Tsung

3. Extract and Install
tar zxvf tsung-1.6.0.tar.gz
cd tsung-1.6.0
./configure && make && sudo make install

Note: Sample XML configurations are located in /usr/share/doc/tsung/examples/http_simple.xml

Setup up Cluster Testing with Tsung

1. Add cluster nodes info in each node's "/etc/hosts"
sudo vi /etc/hosts
# cluster nodes       n1       n2       n3       n4

2. Setup ~/.ssh/config file
vi ~/.ssh/config
Host n1
  Hostname n1
  User tsung
  Port 722
  IdentityFile /home/tsung/.ssh/my_key_rsa7
Host n2
  Hostname n2
  User tsung
  Port 722
  IdentityFile /home/tsung/.ssh/my_key_rsa7

Test and Visualize Results
1. Start tsung on master server
tsung -f /home/tsung/test/selected_scenario.xml start

2. Plot graphs with Perl script
/usr/lib/tsung/bin/ --stats /home/tsung/.tsung/log/$tsung_path/tsung.log

Change Kernel params

vi /etc/sysctl.conf

net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 65000