Tag: tuning

Improved Performance by Compressing JSP contents

Hi,

Jay SenSharma

Jay SenSharma

In response to comment of Mr. Fabian Dsouza

http://middlewaremagic.com/weblogic/?page_id=2594#comment-2990

Many times developers write JSP pages which has many spaces inside it.  Like unnecessary Line Breaks, Unnecessary spaces etc. That is required from Developers point of view. Because these spaces and line breaks helps the developers to easily maintain the code and it improves the readability as well.

But it creates problem when it comes to production. These lines and extra spaces degrades the performance of over all n/w transmission because these extra lines and spaces also goes as part of the Response to the client and client can see these spaces in his browser by right clicking on the page    “View Page Source”

WebLogic provides a best way to compress the JSP’s to remove these kind of spaces and line breaks from the JSP if we use “<compress-html-template>true</compress-html-template>”

(Tested on WLS10.3)

Step1). Develop a Web Application directory like following:   “C:TestApp”

Step2). Now create a “WEB-INF” directory inside “C:TestApp”

Step3). Provide the following kind of “web.xml” file inside “C:TestAppWEB-INF”

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Step4). Now Write the “weblogic.xml” file inside “C:TestAppWEB-INF”

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
  <jsp-descriptor>
      <compress-html-template>true</compress-html-template>
  </jsp-descriptor>
</weblogic-web-app>

Step5). Write a Jsp  “index.jsp”  with full of spaces and Line breaks like following:

<html>
<head><title>TestApp</title></head>
<body bgcolor=maroon text=white>
<center><h2>TestSpaces</h2>

Hello

There are many Spaces

And

New Lines In This Page                                 Do u see it?

</center>
</body>
</html>

Step6). Deploy the “TestApp” in weblogic Server. For quick testing place the “TestApp” web application inside the “<DOMAIN_ROOT>autodeploy”  directory so that for testing we can quickly edit the application as well.

Step7). Now access the WebApplication like following:    http://localhost:7001/TestApp

View_Page_Source

View_Page_Source

Step8). Now see the Page Source by right clicking on the page and chose “View Page Source”  like following:

View_Page_Source_Without_Spaces

View_Page_Source_Without_Spaces

Step9). Now Undeploy the application (just  remove the TestApp from autodeploy directory ) and then remove the “weblogic.xml” file  then again deploy the TestApp to WebLogic then again check the Page Source …You will see all the Spaces and new Lines in it.

View_Page_Source_With Space

View_Page_Source_With Space

.

.

Thanks

Jay SenSharma


WebLogic Heap Dump Genration Using Jmap

Hi,

Jay SenSharma

Jay SenSharma

Note: Jmap will not work for Any kind of Windows Service so please refer to the following article to know how to generate HeapDump in case of Windows Services : How to Generate HeapDump in case of Windows Service ?

Here is a Simple Demonstration of using JMap to Generate the Binary heap Dump…Which we will analyze later using Jhat tool. These tools are very common and freely available for Download porpose. But from Sun JDK 1.6 Onwards it is by default available inside “<JAVA_HOME>bin” directory.

What is Jmap And Why Not Jhat?
Jmap is much better than Jhat utility because to start with Jmap utility u need not to apply any JAVA_OPTION on the WebLogic Server … you can directly start with any WebLogic Server which is Running on Sun JDK …. All u need to do is …Just find the Process ID of that WLS Server…thats all.

Jmap generates the Heap Dump Much faster than Jhat.

Jhat HeapDumps sometimes are seen as currupted file…But jmap is more reliable and generates the correct Heap Dump file. (correct heap dump generation percentage wise it is better than Jhat)

Step1). Start a Weblogic Server instance normally on your Local Machine and then find the Process ID (PID).

Step2). If you are using Unix Based Operating System then u can find out the Process ID (PID) by running the following Command:

ps -ef | grep java

If you are using Windows then follow the below Steps to find out the Process ID (PID):

a) Press “Ctrl+Alt+Del” 2 buttons together.
b) Press the “Task Manager” Button
c) Click on “Processes” Tab.
d) Now Select the Menu Item “View” — > “Select Columns”
e) Check the “PID (Process Identifier)” Check box as well…
f) Now u can see the Process Id of “java.exe” in the “Processes” Tab.

Finding WLS Process ID in WINDOWS

Finding WLS Process ID in WINDOWS

Step3). Start the “JMap” tool from “<JAVA_HOME>bin” directory as following:

C:bea103jdk160_05bin>jmap -dump:format=b,file=heapJMap.bin 7540

Note: use  -J-d64 jvm option if your JVM is 64 Bit Jvm jmap    -J-d64 -heap     pid”

Heap Dump Generation Using Jmap

Heap Dump Generation Using Jmap

Step4). To Read the Binary Heap Dump File … Jhat is one of the Best Tool… Please run the following command to inoke the “jhat” tool Http Server by passing the Heap Dump File name…

C:bea103jdk160_05bin>jhat -J-mx1024m heapJMap.bin

Using Jhat HttpServer to read the Jmap Generated HeapDump

Using Jhat HttpServer to read the Jmap Generated HeapDump

Step5). Now open a Web Browser with the following URL: “http://localhost:7000”
and refer to Post:  heap-dump-using-jhat-for-weblogic-server-heap-analysis/

Jhat Non Product Instance Counter

Jhat Non Product Instance Counter

Step6). U can use  different options available as part of “jmap” to analyze the Binary heap Dump like

To See the Heap Histogram u can do the following:

You can use some other “Jmap” options as well:

JMap Histogram Analysis

JMap Histogram Analysis

-finalizerinfo
Prints information on objects awaiting finalization.
-heap
Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.
-permstat
Prints class loader wise statistics of permanent generation of Java heap. For each class loader, its name, liveness, address, parent class loader, and the number and size of classes it has loaded are printed. In addition, the number and size of interned Strings are printed.

.
.
Thanks
Jay SenSharma


Heap Dump Using Jhat for WebLogic Server Heap Analysis

Hi,
Jay SenSharma

Jay SenSharma

Many times we want to Generate the Heap Dump to see what all objects are created inside the JVMs Heap space. The Heap Dump tells us that what all objects are created inside the JVM and what is the size of those Objects. Based on this analysis we can findout that what all objects (Application Objects/Platform Objects) are consuming more memory inside the heap.

Here is a Basic Step to enable the Jhat tool to generate the Heap Dump of our WebLogic Server and a brief intro of using this Great and wonderful tool.
Jhat tool comes free and available inside the “<JAVA_HOME>bin” directory (from JDK1.6 onwards only). If you are using Jdk 1.5 or Lower version then u need to separately download the Jhat tool.from “https://hat.dev.java.net/
.
.
Step1). Open the “startWebLogic.sh”(Unix Based OS) or “startWebLogic.cmd”(Windows OS)  and then add the JAVA_OPTIONS inside it as following:
@REM **********WINDOWS Operating Systems<(startWebLogic.cmd)******************
@REM
@REM Call setDomainEnv here.
set DOMAIN_HOME=C:bea103user_projectsdomainsWS_Security_Domain
for %%i in ("%DOMAIN_HOME%") do set DOMAIN_HOME=%%~fsi
call "%DOMAIN_HOME%binsetDomainEnv.cmd" %*
set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Xrunhprof:format=b,file=MyHeapDump.hprof
set SAVE_CLASSPATH=%CLASSPATH%
#************Unix Based Operating Systems<(startWebLogic.sh)***********
#
# Call setDomainEnv here.
DOMAIN_HOME="C:/bea103/user_projects/domains/WLST_Domain"
. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*
SAVE_JAVA_OPTIONS="${JAVA_OPTIONS}"   -Xrunhprof:format=b,file=MyHeapDump.hprof
SAVE_CLASSPATH="${CLASSPATH}"
Step2). Now restart Your Server. As soon as you will start your Server you will find that “MyHeapDump.hprof” file is created inside your <DOMAIN_HOME> root directory:
Heap Dump Location

Heap Dump Location

Wait For Some time 4-5 Minutes to get the complete heap Dump

Step3). Open the HeapDump using the Jhat tool like following:
C:bea103jdk160_05bin>jhat -J-mx1024m  C:bea103user_projectsdomainsWS_Security_DomainMyHeapDump.hprof

OR place the file in some other location before opening it…
C:bea103jdk160_05bin>jhat      -J-mx1024m       C:myHeapDumpsMyHeapDump.hprof
.
Step4). As soon as u run the Obove command jhat tool starts a Http Server on default port 7000…Please open a browser with the following URL:
http://localhost:7000
Opening Jhat Console

Opening Jhat Console

jhat Histogram Analysis

jhat Histogram Analysis

Jhat Object Query Language Editor

Jhat Object Query Language Editor

Jhat Non Product Instance Counter

Jhat Non Product Instance Counter

Jhat Platform/Non-Platform Instance Counter

Jhat Platform/Non-Platform Instance Counter

.
.
***** **** *** **____Advanced Jhat Analysis____ ***** **** *** **
.
Step5). Object Query Language (OQL)
OQL is SQL-like query language to query Java heap. OQL allows to filter/select information wanted from Java heap. While pre-defined queries such as “show all instances of class X” are already supported by HAT, OQL adds more flexibility. OQL is based on JavaScript expression language.
OQL query is of the form
select <JavaScript expression to select>
[ from [instanceof] <class name> <identifier>
[ where <JavaScript boolean expression to filter> ] ]
==================================================
(OQL) Object Query Language Querie

(OQL) Object Query Language Querie

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

(OQL) Object Query Language Querries

========================================================

Issues U May Face While Using Jhat for Analysis:

Issue-1). While reading Heap Dump using Jhat u may find following error:
.
Reading from C:bea103user_projectsdomainsTest_DomainMyHeapDump.hprof…
Dump file created Sun Jul 11 20:22:53 IST 2010
java.io.IOException: Unrecognized heap dump sub-record type:  0
at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReader.java:489)
at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:226)
at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:79)
at com.sun.tools.hat.Main.main(Main.java:143)
Solution: Most of the time this means that the VM did not write the heap dump properly. At some point in the file, everything is zeroed out, hence the unknown sub-record type 0. There is not much you can do but get another heap dump. Or try to download “Eclipse Memory Analyzer(http://www.eclipse.org/proposals/memory-analyzer/) and just say file—>open—>MyHeapDump.hprof “
.
Issue-2). While Killing your Server Profiler will try to generate the HeapDump (around 30 MB minimum size with WLS Server) you may get the following error in the WLS Server stdout:
.
HPROF ERROR: Missing jclass when fields needed [hprof_class.c:647]
HPROF ERROR: Trouble with unprepared classes [hprof_reference.c:384]
HPROF ERROR: Missing jclass when fields needed [hprof_class.c:647]
HPROF ERROR: Trouble with unprepared classes [hprof_reference.c:384]
allocation sites … done.
<Jul 11, 2010 8:11:06 PM IST> <Error> <> <BEA-000000> <THREAD DUMP from JVM taken at ‘Sun Jul 11 20:07:47 2010’>
Solution: Please collect another Heap Dump or use “Eclipse Memory Analyzer”

—————————-

WORKAROUND

——————————————————-

Use the “Jmap” utility (Which comes with JDK1.6 default or download it separately) to generate the Binary Heap Dump File and then read it using Jhat tool….    http://middlewaremagic.com/weblogic/?p=2241
.
Why “Jmap”?
Jmap is much better than Jhat utility because to start with Jmap utility u need not to apply any JAVA_OPTION on the WebLogic Server … you can directly start with any WebLogic Server which is  Running on Sun JDK …. All u need to do is …Just find the Process ID of that WLS Server…thats all.
.
.
Step1). Find the process ID of your Server.
Step2). Run the following command: (Suppose 5552 is the Process ID of your Server Process)
C:bea103jdk160_05bin>jmap -dump:format=b,file=heapJMap.bin 5552
Dumping heap to C:bea103jdk160_05binheapJMap.bin …
Heap dump file created
Step3). Make sure that while reading the Binary Heap Dump using JHat …u set the Heap Size to 1024 or according to the Heap dump size….
C:bea103jdk160_05bin>jhat -J-Xmx1024m heapJMap.bin
Reading from heapJMap.bin…
Dump file created Mon Jul 12 10:05:58 IST 2010
Snapshot read, resolving…
Chasing references, expect 239 dots………….
…………………………………………
Eliminating duplicate references…………….
…………………………………………
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
=================================================
.
.
Thanks
Jay SenSharma

Copyright © 2010-2012 Middleware Magic. All rights reserved. |