Solved

how do i determine the session size in a j2ee application

Posted on 2008-10-27
10
1,229 Views
Last Modified: 2012-05-05
hi experts,

we are trying to setup our application for performance testing up to 1700 concurrent users. system is using up all the jvm memory at a certain point and the session are not creted anymore after a certain number is reached. is there any way to find out what the session size is like for one user.
its a j2ee compliant web based application deployed on websphere 6.0

thanks
Sunil
0
Comment
Question by:sunilramu
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:Repus024
ID: 22813789
The proper way to do this is to run a profiler.  This will give you a very detailed description of what is occurring in memory.  I'm assuming you are using Rational (since you are on websphere).  The built in debugger for WSAD/Rational is not very good.  I've used it before and became quite frustrated.

I've heard that JProfiler is much better, although it comes with a price tag:

http://www.ej-technologies.com/products/jprofiler/overview.html

I used a simple JSP page before to monitor the memory stats for the application as a whole.  This is not session level information but what you could do is run your application, view this jsp page, log on another user, and then view the jsp page again.  The increase would be the memory being held by that user's session that can't be freed.  Please see the attached code snippet for the JSP code.

Please let me know if you have any questions or trouble with these resources.
<%@ page language="java" %>
 
<%@ include file="include/httpHeaders.inc" %>
 
<html>
 
<head>
   <title>
                        Memory
   </title>
   <link rel="stylesheet" type="text/css" href="trexo.css" />
</head>
 
<body>
   <jsp:include page="/include/ApplicationHeading.htm" flush="true" />
   <div id="popup_title">Memory Used</div>
   <div id="popup_form">
    <div id="body">
 
            <%
            System.gc();
            Runtime runtime = Runtime.getRuntime();
            long maxMemory = runtime.maxMemory();
            long allocatedMemory = runtime.totalMemory();
            long freeMemory = runtime.freeMemory();
            long used = allocatedMemory - freeMemory;
            
            java.text.DecimalFormat format = new java.text.DecimalFormat("###,###,###.##");
            String usedMem = format.format(used / 1024);
            String freeMem = format.format(freeMemory / 1024);
            String allocMem = format.format(allocatedMemory / 1024);
            String maxMem = format.format(maxMemory / 1024);
            String totalFreeMem = format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024);
            
            
            System.out.println("used memory: " + used / 1024);
            System.out.println("allocated memory: " + allocatedMemory / 1024);
            System.out.println("free memory: " + freeMemory / 1024);
            System.out.println("max memory: " + maxMemory / 1024);
            System.out.println("total free memory: " + (freeMemory + (maxMemory - allocatedMemory)) / 1024);
            %>
            <table>
            <tr><td>Used Memory</td><td><%= usedMem%>kb</td></tr>
            <tr><td>Allocated Memory</td><td><%= allocMem%>kb</td></tr>
            <tr><td>Free Memory</td><td><%= freeMem%>kb</td></tr>
            <tr><td>Max Memory</td><td><%= maxMem%>kb</td></tr>
            <tr><td>Total Free Memory</td><td><%= totalFreeMem%>kb</td></tr>
            </table>
            </div>
            </div>
   <jsp:include page="/include/ApplicationFooter.htm" flush="true" />
            
</body>
</html>

Open in new window

0
 

Author Comment

by:sunilramu
ID: 22815223
Repus024: thanks will try you code. In the mean time have you used javawebparts or has anyone used the session class in the javawebparts package.
0
 
LVL 3

Expert Comment

by:Repus024
ID: 22815599
I have never personally used the javawebparts package.  Looking quickly at the JavaDocs it looks like the SessionSize object could be useful for what you need.  

I would certainly try including it in your application for debugging purposes to see if it gives you what you are looking for.  

The code I provided will provide a quick snapshot of the entire heap which obviously includes all sessions.  If you need more detail from what my code or the SessionSize object provides, you can force a heap dump during the stress test and use heaproots to analyze it.  This is a very useful application in determining the contents of the JVM heap.  

http://www.alphaworks.ibm.com/tech/heaproots
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:sunilramu
ID: 22816755
i cant use SessionSize from javawebparts since not all objects in my session are serializable. And the code you gave is giving inconsistant results for 3-5 users. any idea how many users you would load it with to get consistent results.
0
 
LVL 3

Expert Comment

by:Repus024
ID: 22816909
Are your users actively doing work, or are they just logged onto the system.  There is two types of memory issues:

1.  Issues that arise from the session holding too many (large) objects.  This will not allow garbage collection to be very effictive.

2.  Issues arising from a spike in memory usage during a transaction.  This is because too much transactional memory is being used, or objects are being referenced longer than they need to

The JSP page will help at identifying issues with #1.  Issues with #2 will require the use of a profiler and some code analysis.  What I've done in the past is log on several users.  Do a few transactions with them (transactions you suspect are loading up the session).  Then look at the page.  Then log on one more user and do a few transactions.  Then look at the page again.  

If all of the users are actively doing work the transactional memory usage will produce inconsistent results.  The JSP page is good for identifying classical memory leaks or heavyweight sessions as you can see the increase in memory usage over time or as users log on.  

Please let me know if you still can't get consistent results from the JSP page.
0
 
LVL 1

Expert Comment

by:matt_c
ID: 22819924
To find out what the session sizes for each web application use the tool "probe"

It's installed as a war to your application server

Get it from www.lambdaprobe.org/

It also gives real time graphs of memory usage.

It's a good tool to have in your development collection anyway
0
 
LVL 1

Expert Comment

by:matt_c
ID: 22819933
sorry, just read that your using websphere 6.0 probe only works with tomcat
0
 

Author Comment

by:sunilramu
ID: 22822388
Following code does the job. i got if from one of the websphere appserver performance tuning articles.
Also you have an option of monitoring session management in webspehere tivoli PMI.

thanks all.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page 
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>SessionObjects.jsp</TITLE>
</HEAD>
 
<BODY>
<H1>Session Object List JSP</H1>
 
This JSP will dump information about the current HTTPSession.<br><br>
 
<%@ page import="java.io.*,java.util.*,javax.servlet.*" session="false" %>
<%! public void dumpSession(HttpServletRequest request, JspWriter out)  throws IOException { 
  HttpSession session = request.getSession(false);
    Object ro = null ;
 
 
 out.println("Session ID from session.getID : " 
     + session.getId() + "<br>");
 
 out.println("Session ID from getHeader: "
     + request.getHeader("Cookie") + "<br>"); 
  
 
 Enumeration enum = session.getAttributeNames();
    if ( enum.hasMoreElements() )
    {
      int totalSize = 0;
     
 out.println("<h3>Session Objects:</h3>");
 out.println("<TABLE Border=\"2\" WIDTH=\"65%\" BGCOLOR=\"#DDDDFF\">");
 out.println("<tr><th>Name</th>");//<th>Object.toString()</th>");
 out.println("<th>Raw Bytes</th><th>Size (bytes)</th></tr>");
      while ( enum.hasMoreElements() )
      {
   String name = (String)enum.nextElement();
 
   Object sesobj = session.getAttribute(name) ;
 
   ObjectOutputStream oos = null;
       ByteArrayOutputStream bstream = new          ByteArrayOutputStream();
    try {
      
	  oos = new ObjectOutputStream(bstream);
      oos.writeObject(sesobj);
     }
    catch (Exception e) {
      e.printStackTrace();
    }
      finally {
        if (oos != null) {
        try {oos.flush();}
       catch (IOException ioe) {}
       try {oos.close();}
       catch (IOException ioe) {}
 		}
 }
 
    ObjectInputStream ois = null;
   ro = null ;
    
	try {
      ois = new ObjectInputStream(new        ByteArrayInputStream(bstream.toByteArray()));
    ro = ois.readObject();
 }
   catch (Exception e) {
   e.printStackTrace();
 }
     finally {
        if (ois != null) {
        try {ois.close();}
        catch (IOException ioe) {}
 }
 }
     
	totalSize += bstream.size();
        out.println("<tr>");
		out.println("<td>" + name + "</td>");
	       // out.println("<td>" + session.getAttribute(name) + "</td>");
		out.println("<td>" + ro + "</td>");
    	out.println("<td>" + bstream.size() + " bytes </td></tr>");
 }
      out.println("</table>");
  out.println("Total Bytes: " + totalSize + "<br><br>");
 } else {
   out.println("No objects in session");
 }
 }
 %>
<%
  response.setHeader("Pragma", "No-cache");
  response.setHeader("Cache-Control", "no-cache");
  response.setDateHeader("Expires",0);
  
	HttpSession session = request.getSession(false);
  if (session == null) {
	  out.println("No session");
 } else {
	  dumpSession(request, out);
 }
 
%>
</BODY>

Open in new window

0
 
LVL 1

Accepted Solution

by:
sravy earned 500 total points
ID: 22899155
One easyway to do is:
Enable PMI metrics from the WebSphere's admin console
login to Admin COnsole>Monitoring and tuning><server name>>runtime/configuration >servletsessionManager >session object size>enable.
you can also enable other metrics like how long the session is alive , no of sessions etc.
After enabling the metrics
go to Performance viewer>current activity>select server , start monitoring>select advisor>performance modules>servlet session manager
---------------------------------------------------
you can immediately see the average session object size if PMI enabled in runtime.
Note: Make sure you have enough resources to enable PMI.
to disable
just say stop monitoring  from Performance viewer>current activity>select server >stop monitoring
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
print map entry 34 75
Edit a page at wix.com 8 81
maven module vs maven project 3 68
PHP Curl to output a url 7 78
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question