Sunday, February 14, 2010

How to prevent OOME? Memory Leak analysis...


What is Memory Leak and how it affects everything in your server? First, Memory Leak is not good. Memory leaks are hard to detect especially when using frameworks or third party library that you didn’t created. Seconds, it affects everything when you deploy it in production environment and don’t care about memory leak until your server is down. If you want to keep the server run 24 x 7, check for memory leak.

In Java, Garbage Collector (GC) is your friend, it collects and handles most of the memory leak issue by default but it still requires help from your code. The GC is just a temporary workaround. When creating an application that use memory as storage, make sure that you clean your own mess. Don’t depend on GC because GC sometimes it ignores your object to be collected because GC doesn’t have a way to identify if your application is really using the object. Memory leak usually cause when an object in JVM are not accessible by a running thread and also caused by a Rogue Thread.

Rogue Thread is an unmanageable thread. No application can control it and it is caused when there is an application running and in the middle, the application stop. Another cause of memory leak is a Circular Reference, on my previous job, I always tell my colleagues to make sure that they’re not doing a circular reference because it’s like doing an infinite loop.


Lesson learned about Memory Leak and what to do:
1.    Stress testing is necessary if you’re application is for multithreaded.
2.    Utilize the tools that Java JDK provided.
3.    Take care of your code before sending it to production.
4.    NEVER EVER BLAME THE SERVER. Server is just another folder in your windows OS.
5.    To be continued…
Basic tips for performance:
1.    Try to minimize the use of STATIC object.
2.    Convert “+” concatenation into StringBuffer or StringBuilder.
3.    Understand GC.

How I search for memory leak?

Simple, use the tools that you already have. The question is how to use it? Anyway, I listed the approach below. Note: You must use JDK 6 or higer

HotSpotDiagnosticMXBean
ManagementFactory.getDiagnosticMXBean().dumpHeap("\temp\heapdump_apps.bin", true);
After getting the heapdump, use the jVisualVM to find the leak.
-XX:HeapDumpOnCtrlBreak
The -XX:HeapDumpOnCtrlBreak option adds the hprofdump diagnostic command to the list of commands that run automatically when the Ctrl-break keys are pressed (similar to the print_threads diagnostic command). The HPROF dump file is written to the location defined by the -XX:HeapDumpPath option. Add this option when running JVM. It will create heap dump every time ctrl+break (kill -3) signal is sent to JVM.

-XX:+HeapDumpOnOutOfMemoryError
If you application throws an OutOfMemoryError, it will create a heap dump (.hprof file) into a binary format. You need to add –XX:HeapDumpPath option to define the location of your heap dump file.

jMap –dump:file=.bin
jMap is the tools that I’ve been using to generate heap dump. It comes with JDK install. is just file name and is your application process_id. In unix, you can get this by “ps eaf”, in windows use the “jps” to get the process ID.

Use jMap in the code
All you need to do is create a simple java class and add the code to your main method.

String appName= ManagementFactory.getRuntimeMXBean().getName()
String processId  = appName.substring(0, appName.indexOf("@"));
String [] myCmd = {"jmap", "-dump:file=/tmp/appHeapDump.bin", processId};
Process proc = Runtime.getRuntime().exec(cmd);




Tuesday, December 15, 2009

Experience WorldWide Telescope - For Kids Knowledge

Immerse yourself in a seamless beautiful environment.

WorldWide Telescope (WWT) enables your computer to function as a virtual telescope, bringing together imagery from the best ground and space-based telescopes in the world. Experience narrated guided tours from astronomers and educators featuring interesting places in the sky.
A web-based version of WorldWide Telescope is also now available. This version enables seamless, guided explorations of the universe from within a web browser on PC and Intel Mac OS X by using the power of Microsoft Silverlight 3.0.

Sunday, October 18, 2009

WiSH Integration

Wicket, Spring and Hibernate integration.

How to convert a Static HTML Pages into a Dynamic HTML Pages?
- When I was following the Wicket Development, I know that someday, it will make my life easier in building Web Secured Application using the Wicket Framework. I've been using Spring since it was released as a development release candidate and I know that someday this will be the powerful Enterprise Technology that can be easily integrate to any kind of framework because of its architecture - IoC.

Hibernate, was my best ORM tool and for me in the first place, it was hard to implement, but when I already got the foundation / core architecture of the framework, I was impressed because of its reliability, secured, robust and easy to implement.

Wicket - I was following wicket 3 years ago when it was on the development. I studied the core architecture and research the ingredients of the framework. I was amazed of the quick and easy way to convert static pages into a dynamic pages. It also help integrate AJAX very easy and secured.

If you want to know Wicket, Spring and Hibernate just let me know and I am happy to assist you during my free time.

R.A.

Thursday, March 26, 2009

MINA Spring Wicket and Hibernate

Project:

Currently, I am developing a system that will integrate the GPS information of the vehicle and feed the data to the database (DB2). It also provide a Web UI for information maintenance. I used wicket because it is easy to integrate to an existing HTML design. You can create some navigation history without any complex approach and you can create dynamic menus according to the user rights.

My architecture is divided into 4 parts/layer.

Socket - MINA
Web Tier - Wicket
Business Tier - Spring
Data Tier - Hibernate

IDE used: IBM RSA 7.5 (I also used customized Eclipse Ganymede)
Application Server: WAS 6.0, WAS 6.1, Tomcat 6.x
WebServer: IBM HTTP Server, Apache WebServer
Monitoring Tools: JConsole integrated to WAS (WebSphere Application Server)
Testing Tools: JUnit, JProbe, JMeter, HTTPUnit
Scripting: JQuery, YUI

Other Tools Used: Aqua Studio, Squirrel, Eclipse Data Tools, Hibernate Tools, Spring IDE, Ultra Edit, Ultra Compare,

Operating System: Mac OS - Leopard, Ubuntu Desktop Edition 8.10

Virtualization: Virtual Box - Installed Guests (Ubuntu, CentOS, Windows XP)

More information to come... Watch out for the system.

Thursday, January 1, 2009

Array Handling

Under Construction - Soon to be released

Tuesday, July 22, 2008

Migrate Green to Blue (CICS to Web)

There are many ways to move Green to Blue - CICS to Web.

Based on my experience, I did some of the following:

1. I reused the business logic on the COBOL by exposing it into a web services.
2. HATS from IBM which is more flexible and easy to implement.
3. Do a screen scrape approach from the reflection screen.
4. Create a macros and dig about EJB, RMI, CORBA.



Saturday, June 7, 2008

Running Wicket on WebSphere Application Server 6.1 using Filter instead of Servlet

It takes time for me to find out why Filter is not working on WAS 6.1 and finally I made it work...

If you're using RAD or RSA to run WebSphere Apps 6.1:

1. On your Server - Right Click WebSphere Apps 6.1 and select Administration - Run Administrative Console

2. If your WAS 6.1 requires your login, please login or please proceed to next step

3. On your Left Pane of the window, expand Server

4. Select the Application Server

5. Select the Server that you want to enable the filter compatibility (ie server1, server2, myserver, etc)

6.On Container Settings - expand Web Container Settings and click on Web Container

7.Click Custom Properties

8.Click on New

9.Enter property name=[com.ibm.ws.webcontainer.invokefilterscompatibility] value=[true]

10. Save and restart the server and run your Wicket with filter implementation....

Good luck...

By rma