Java Monitoring

http://jamonapi.sourceforge.net/

https://code.google.com/p/javasimon/ (Not recommended)

Metrics: http://metrics.dropwizard.io/
Reports Server: http://ganglia.info/

Check Ganglia Demos:
http://ganglia.info/?page_id=69

-o-

Monitoring Tomcat

https://www.hugeinc.com/ideas/perspective/happy-monitoring-with-javamelody

https://github.com/javamelody/javamelody/wiki/UserGuide

Easy to use
Excellent features
License: Apache Software License
Need tinkering to enable/disable in production.
Easy to take thread dumps
Active development going on

-o-

JMX Monitoring is best….but many won’t open ports in production.
http://wiki.apache.org/tomcat/FAQ/Monitoring

-o-

http://www.moskito.org/index.html

#tomcat-monitoring

THE ART OF SCALABILITY

http://theartofscalability.com/

The Scale Cube: http://microservices.io/articles/scalecube.html

http://akka.io/

The Concurrent Mark Sweep (CMS) Collector Vs The Garbage First or G1 garbage collector

G1 Garbage Collector got introduced in Java 7. People already written on this subject. Just giving links. Please go through and take care of GC Configurations.

 

Java Garbage Collection Basics

http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

http://docs.oracle.com/javase/7/docs/technotes/guides/vm/G1.html

Bench marking

http://java-is-the-new-c.blogspot.com/2013/07/tuning-and-benchmarking-java-7s-garbage.html

 

To check quickly, check following in JVM Params

-XX:+UseG1GC

-XX:+UseConcMarkSweepGC

 

Multithreaded Custom Class Loaders in Java SE 7

http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html

-o-

#gc-tuning

Cache (Noun)

Cache: a part of a computer’s memory where information is kept so that the computer can find it very quickly
http://www.merriam-webster.com/dictionary/cache

Nearest Place to CPU to find Objects are Primary Memory, File System, Database and Network.
We have software which supports cache. No need to implement from scratch. But we need to know concepts and fundamentals behind this. There are different Cache Algorithms to use.

2013-12-13 18_54_55-cache

Software:

http://ehcache.org/modules
http://terracotta.org/

Spring/EhCache: http://www.codingpedia.org/ama/spring-caching-with-ehcache/

Cache Algorithms: http://en.wikipedia.org/wiki/Cache_algorithms

Open Source Cache Software List: http://java-source.net/open-source/cache-solutions

Connection Pool

HTTP Connection Pool: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html

FTP Connection Pool

Image / JS / HTML Cache in transit, Network Route Optimization : http://www.akamai.com/

#cache

How to do Performance Fine Tuning?

This is very common question asked by many.
Enterprise systems are made up of 4 components.

2013-12-13 17_59_35-performance

Primary Memory: Make sure that we use memory efficiently. Reduce the foot print.

CPU: Use CPU friendly algorithms for calculations. Example: One team member is fetching records and counting them in while loop to know total number of records. Instead of this he should have use select count(*)

Use Visual VM to monitor CPU, Memory. Use JMeter or other tools to simulate load.
1. Take memory dump and analyze total number of objects and its size
2. Avoid object creation. Reuse Objects. Example: String query = a+b+c+d+ ….etc
3. Do proper code review and check SONAR violations
4. Use New Relic, Spring Insight, Visual VM, JMeter, …tools
5. JMon API is good one to check performance
6. Establish bench mark performance numbers.

Secondary Memory: File System/Database comes under this. Reduce total number of trips. Store wisely.
1. Reading same object again and again is not good. Better to cache them. Implement good caching algorithms.
2. Instead of statement, prepared statements are good
3. Avoid select *. If user needs two columns, it is better to choose only those two, instead of using select * and using data only from two columns.
4. Where clause order
5. Indexes, Re-indexes, Table Partitions, …etc
6. Instead of making two calls to database, combine them and fetch data in one call

Network: Network latency, Network Bandwidth, HTTP Connection reuse, Time Outs, Firewalls, ..etc

>ping -t www.google.com

Pinging www.google.com [173.194.115.84] with 32 bytes of data:
Request timed out.
Request timed out.

Ping statistics for 173.194.115.84:
Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),
Control-C
^C

Operating System / JVM Performance Tuning: Check Memory Settings, JVM Parameters, …etc

-o-

Reference Books:
Java Performance and Scalability: A Quantitative Approach Paperback
by Henry H. Liu

Oracle Database 12c Performance Tuning Recipes: A Problem-Solution Approach [Paperback]
Sam Alapati (Author), Darl Kuhn (Author), Bill Padfield (Author)

Introduction to Algorithms [Hardcover]
Thomas H. Cormen (Author), Charles E. Leiserson (Author), Ronald L. Rivest (Author), Clifford Stein (Author)

The Definitive Guide to Terracotta: Cluster the JVM for Spring, Hibernate and POJO Scalability (Expert’s Voice in Open Source) [Paperback]
Terracotta Inc. (Author)

Instant Effective Caching with Ehcache Paperback
by Daniel Wind (Author)

Software Performance and Scalability: A Quantitative Approach [Hardcover]
Henry H. Liu (Author)

Patterns for Performance and Operability: Building and Testing Enterprise Software [Hardcover]
Chris Ford (Author), Ido Gileadi (Author), Sanjiv Purba (Author), Mike Moerman (Author)
-o-

#java-performance, #performance-fine-tuning

Custom Plugins for Apache JMeter

http://jmeter-plugins.org/

http://jmeter-plugins.org/wiki/StandardSet/

These are very useful plugins to analyze the JMeter Results.

Tips:
Please disable View Results Tree
Log only Errors
Add Assertions to count proper errors
Define Time Outs

Optimum Numbers:
C2B API (Customer is calling Business API)
50% CPU
70% Memory
1 Sec Max
The TPS within this is optimum TPS for given JVM

B2B API (Business is calling Business API)
80% CPU
80% Memory
.75 Sec Max
The TPS within this is optimum TPS for given JVM
-o-

#custom-plugins-for-apache-jmeter, #tps

Software Performance Cycle – Deming Wheel

Many people think that installing software in new system will improve performance. Many people suggest that adding memory or increasing CPU will improve. Without understanding fundamentals doing all this won’t help much. This type of thinking comes from watching present day advertisements. After watching Nike shoe advertisement, perception is that if you can wear good shoe you can run faster. Person go to shop, buys Nike Shoe. He can’t win in Olympics just because he had Nike Shoe. Performance comes from within. External shoes, track helps after that.

Many times we won’t plan / design properly. Team is not familiar with performance driven coding. Due to project pressure everybody concentrates on functionality to work. Once it is working management moves resources to other work. There is no time to stop and check the code / performance. While studying Deming Wheel it is reminding the same.

800px-PDCA_Process

Plan: Keep Performance in mind while designing code, SQL Queries, Infrastructure, Architecture, ..etc

Do: Code for Performance + Functionality + Modularity + Testability..etc

Check: Take time to check what we did and identify the problems

Act: Fix the issues

Improve Standards / Increase Awareness:
1. Set up new standards so that team won’t do the same mistake again and again.
2. Share the knowledge across teams. Awareness prevents doing same mistake again

If we can follow this cycle religiously, over period of time performance of the code will increase. Otherwise at the same pace it will go downhill.

Reference:
https://deming.org/theman/theories/pdsacycle
http://en.wikipedia.org/wiki/PDCA

-o-

#deming-wheel, #software-deming-wheel, #software-performance, #software-performance-deming-wheel

Application performance management (APM)

http://newrelic.com/   – This is very cost effective and best tool.

http://bluestripe.com/ – Very Costly tool

http://www.bmc.com/solutions/application-management/application-performance-monitoring.html – Leader in the market

Others:

http://www.appdynamics.com/

http://www.optier.com/

http://www.precise.com/

http://en.wikipedia.org/wiki/Application_performance_management

Note: Many times business is confused with monitoring at different levels like software/hardware/application. Architect can bring more clarity to the table.

Enterprise Application Fine Tuning.

Enterprise Application Performance Fine tuning is very important.

Measure the performance at different layers.

———————

Step 1: Prevention (Design, Code Reviews, Alerts, Dashboards, Caching techniques)

Step 2: Detection (Performance testing, Set Alerts and Dashboards, Log and Monitor apps, Service Attacks)

Step 3: Recovery in Production (Restrict Traffic, Allocate more resources like space, memory, cpu…until we fix the issue., Restart)

———————

Different levels of performance fine tuning.

1. JVM Fine tuning

2. OS (JVM Running) fine tuning

3. Database Fine Tuning

4. Application Fine Tuning

5. UI Fine Tuning: http://polimetla.com/2012/10/19/web-page-testing-tools/

6. Network Fine tuning. (http://bluestripe.com/)

Each step is big subject and contact me for more help.

Tools:

Spring Insight : http://static.springsource.com/projects/tc-server/2.0/devedition/htmlsingle/devedition.html

Visual VM: http://visualvm.java.net/

-o-