Common Category

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


Sending Email Alert for Hogger Threads Count Using WLST

Ravish Mody

This post is written considering to send an email alert message to Admin’s which would alert them about the hogger threads. Hogging threads can be called as a candidates for stuck threads in other words, those threads that “might” get stuck are called hogging threads. These threads will be declared as stuck threads after “StuckThreadMaxTimeout” seconds which by default value is 600secs.

Most of you guys might agree with me, that no one wants stuck threads in there production environment. Hence this script would surely help you guys to take an relevant actions once you get an alert about the hogging threads have exceeded the given ration.
In below  script we have used a properties file in which you can give all the details about the domain as well as hogger thread ration, time interval and the number of times the ratio has to be checked.

Steps to Create an Email Alert for Hogger Threads Count

Step1) Create a Directory somewhere in your file system like :  “C:WLST”

Step2) Write a Properties file “domains.properties” inside “C:WLST” like following:

admin.url=t3://localhost:7001
admin.username=weblogic
admin.password=weblogic

# This ExecuteThread_Vs_HoggerThreadRatio represtents the division of ExecuteThread/HoggerThreadRatio
ExecuteThread_Vs_HoggerThreadRatio=2

# Number of times the RATIO has to be checked
checkTimes_Number=25

# TIME INTERVAL between number of times the RATIO has to be checked (30000 milliseconds = 30 seconds)
checkInterval_in_Milliseconds=30000

############ Accouding to the above values the checker will run for total 25 times in an interval of 30 seconds each. #############

Step-3) Create a WLST Script somewhere in your file system with some name like “Alert_HoggerThreadCoung.py” inside “C:WLST” contents will be something like following:

UPDATED [26-04-2011]: This script has been updated based on the comment — >  http://middlewaremagic.com/weblogic/?p=5423#comment-3760, thanks to sathya.

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################

from java.io import FileInputStream
import java.lang
import os

propInputStream = FileInputStream("domains.properties")
configProps = Properties()
configProps.load(propInputStream)

adminUrl = configProps.get("admin.url")
adminUser = configProps.get("admin.username")
adminPassword = configProps.get("admin.password")
executeThread_Vs_HoggerThreadRatio = configProps.get("ExecuteThread_Vs_HoggerThreadRatio")
checkTimes_Number = configProps.get("checkTimes_Number")
checkInterval_in_Milliseconds = configProps.get("checkInterval_in_Milliseconds")

i = 0
y = int(checkTimes_Number)

#############  This method would send the Alert Email  #################
def sendMailString():
	os.system('/bin/mailx -s  "ALERT: Hogger Thread Count Exceeded the Limt !!! " abcd@company.com < rw_file')
	print '*********  ALERT MAIL HAS BEEN SENT  ***********'
	print ''

#############  This method is checking the Hogger Threads Ratio  #################
def alertHoggerThreads(executeTTC , hoggerTC):
	print 'Execute Threads : ', executeTTC
	print 'Hogger Thread Count : ', hoggerTC
	if hoggerTC != 0:
		ratio=(executeTTC/hoggerTC)
		print 'Ratio : ' , ratio
		print ''
		if (int(ratio) <= int(executeThread_Vs_HoggerThreadRatio)):
			print ' !!!! ALERT !!!! Stuck Threads are on its way.....'
			print ''
			message =  'ExecuteThreads Count= ' + str(executeTTC) + '   HoggingThreads= '+ str(hoggerTC) +'   ExecuteThreads/HoggingThreads Ratio= '+ str(ratio)
			cmd = "echo " + message +" > rw_file"
			os.system(cmd)
			sendMailString()
		else:
			print '++++++++++++++++++++++++++++++++++++'
			print 'Everything is working fine till now'
			print '++++++++++++++++++++++++++++++++++++'
	else:
			print '++++++++++++++++++++++++++++++++++++'
			print 'Everything is working fine till now'
			print '++++++++++++++++++++++++++++++++++++'

connect(adminUser,adminPassword,adminUrl)
serverRuntime()
cd('ThreadPoolRuntime/ThreadPoolRuntime')

while (i < y):
	ls()
	executeTTC=cmo.getExecuteThreadTotalCount();
	hoggerTC=cmo.getHoggingThreadCount();
	alertHoggerThreads(executeTTC , hoggerTC)
	print 'Sleeping for ', int(checkInterval_in_Milliseconds) , ' ...'
	print ''
	Thread.sleep(int(checkInterval_in_Milliseconds))
	i = i + 1

Step-4) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492

Step-5) Now run the WLST Script in the same command prompt using the following command:

java   weblogic.WLST  Alert_HoggerThreadCoung.py

You will see the following kind of results in the command prompt

Initializing WebLogic Scripting Tool (WLST) ...
]$ java weblogic.WLST Alert_HoggerThreadCoung.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

-r--   CompletedRequestCount                        2606
-r--   ExecuteThreadIdleCount                       1
-r--   ExecuteThreadTotalCount                      6
-r--   ExecuteThreads                               weblogic.work.ExecuteThreadRuntime[weblogic.work.ExecuteThreadRuntime@78de59f8, weblogic.work.ExecuteThreadRuntime@4de4e6c6, weblogic.work.ExecuteThreadRuntime@6eeaf91d, weblogic.work.ExecuteThreadRuntime@48917cf, weblogic.work.ExecuteThreadRuntime@447a195c, weblogic.work.ExecuteThreadRuntime@2c170a23]
-r--   HealthState                                  Component:threadpool,State:HEALTH_OK,MBean:ThreadPoolRuntime,ReasonCode:[]
-r--   HoggingThreadCount                           0
-r--   MinThreadsConstraintsCompleted               104
-r--   MinThreadsConstraintsPending                 0
-r--   Name                                         ThreadPoolRuntime
-r--   PendingUserRequestCount                      0
-r--   QueueLength                                  0
-r--   SharedCapacityForWorkManagers                65536
-r--   StandbyThreadCount                           4
-r--   Suspended                                    false
-r--   Throughput                                   5.0
-r--   Type                                         ThreadPoolRuntime

-r-x   preDeregister                                Void :

Execute Threads :  6
Hogger Thread Count :  0
++++++++++++++++++++++++++++++++++++
Everything is working fine till now
++++++++++++++++++++++++++++++++++++
Sleeping for  30000  ...

NOTE: This script is using mailx (i.e. but Windows box does not have mailx utility) so please do check if your mailx is configured properly or else script would run properly but the mail would not be sent.

Alert Email

Alert Email

.

Regards,

Ravish Mody


NodeManager is not reachable

Ravish Mody

Many times we come across NodeManager is not reachable issue and its one of the conman issues which lot of people face it, in many cases we have found that this issue happens due to missing step of nmEnroll. It means you might have not Enrolled your NodeManager with the Admin Server and thus the NodeManager is not reachable. Hence we have come up  with this post so that anyone can resolve the same issue if the below steps are been followed properly:

.

.

Steps to Resolve NodeManager is not reachable issue

Step1) Start the AdminServer using startScript “startWebLogic.sh/cmd”

Step2) Start the NodeManager.

Step3) Login to admin-console and then see if the NodeManager is Reachable or not at the below console path

Console Path:

Machines -> <YOUR_MACHINE_NAME>  ->  Monitoring (tab)  ->  Node Manager Status (sub-tab)  -> Status: Reachable

If its NOT REACHABLE then please do the following from the Admin Server Box to Enroll the NodeManager

a) Open a command prompt and run "setWLSEnv.sh/cmd" in it then run the following commands

   java weblogic.WLST
   connect('weblogic','weblogic','t3://localhost:7001')
   nmEnroll('C:/bea103/user_projects/domains/7001_Domain','C:/bea103/wlserver_10.3/common/nodemanager')

b)Then again check in the console path if NodeManager is Reachable.

Step4). Once NodeManager is Enrlolled and Reachable in the admin console then continue the following steps.

Step5). Kill the AdminServer because now we need to start it using WLST command nmStart() and NOT using the start scripts.

Step6). Open a command prompt run “setWLSEnv.sh/cmd” and then run the following command


java   weblogic.WLST

Step7). Now connect to the NodeManager using the following command (7001_Domain is the Domain Name for example.)


nmConnect('weblogic','weblogic','localhost','5556','7001_Domain')

Step8). Once you are successfully connected to the Nodemanager please start the AdminServer using the following command


nmStart('AdminServer')

Step9). Once the Server is started run the following command to get the AdminServer Status


nmServerStatus('AdminServer')

Now if you can see the Admin Server status that means now your AdminServer is now reachable. Hope these steps solves your NodeManager is not reachable.

Regards,

Ravish Mody


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