-
1. Re: Profiling session memory usage in a Seam application
sbasinge May 3, 2010 8:55 PM (in response to alexandru.al.bologa.yahoo.com)This may make you a bit nervous, but I have a custom version of MarshalledValue.java which is part of JBoss. I added to it's ToString, the size in bytes of the stored instance. Then thru the JMX monitor you can see how many bytes each serialized object requires. I simply compiled the java and created a jar file named a_myjbossaddon.jar and put into the <server>/lib directory.
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: MarshalledValue.java
package org.jboss.invocation;
import java.io.*;
import java.util.Arrays;
// Referenced classes of package org.jboss.invocation:
// MarshalledValueOutputStream, MarshalledValueInputStream
public class MarshalledValue
implements Externalizable
{
public MarshalledValue()
{
}
public MarshalledValue(Object obj)
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MarshalledValueOutputStream mvos = new MarshalledValueOutputStream(baos);
mvos.writeObject(obj);
mvos.flush();
serializedForm = baos.toByteArray();
mvos.close();
int hash = 0;
for(int i = 0; i < serializedForm.length; i++)
hash = 31 * hash + serializedForm[i];
hashCode = hash;
}
public Object get()
throws IOException, ClassNotFoundException
{
if(serializedForm == null)
{
return null;
} else
{
ByteArrayInputStream bais = new ByteArrayInputStream(serializedForm);
MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
Object retValue = mvis.readObject();
mvis.close();
return retValue;
}
}
public byte[] toByteArray()
{
return serializedForm;
}
public int size()
{
int size = serializedForm == null ? 0 : serializedForm.length;
return size;
}
public int hashCode()
{
return hashCode;
}
public boolean equals(Object obj)
{
if(this == obj)
return true;
boolean equals = false;
if(obj instanceof MarshalledValue)
{
MarshalledValue mv = (MarshalledValue)obj;
if(serializedForm == mv.serializedForm)
equals = true;
else
equals = Arrays.equals(serializedForm, mv.serializedForm);
}
return equals;
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
int length = in.readInt();
serializedForm = null;
if(length > 0)
{
serializedForm = new byte[length];
in.readFully(serializedForm);
}
hashCode = in.readInt();
}
public void writeExternal(ObjectOutput out)
throws IOException
{
int length = serializedForm == null ? 0 : serializedForm.length;
out.writeInt(length);
if(length > 0)
out.write(serializedForm);
out.writeInt(hashCode);
}
private static final long serialVersionUID = 0xeacce0d1f44ad099L;
private byte serializedForm[];
private int hashCode;
public String toString() {
return new ToStringBuilder(this).append("size", this.size()).toString();
}
} -
2. Re: Profiling session memory usage in a Seam application
yahawari May 4, 2010 1:16 AM (in response to alexandru.al.bologa.yahoo.com)have a look at
SEAMHOME//examples//wiki//src//main//org//jboss//seam//wiki//admin//WikiHttpSessionManager.java
it may help. -
3. Re: Profiling session memory usage in a Seam application
alexandru.al.bologa.yahoo.com May 4, 2010 3:08 PM (in response to alexandru.al.bologa.yahoo.com)Thanks for the advice. I implemented the WikiHttpSessionManager in my own app. Added a little xhtml and now I can see the memory consumption per session.
I think this is sufficient to get total session memory consumption. (hopefully Seam doesn't hide anything else outside the HTTPSession - for example a map on the application context that has as keys the session IDs... but believing this would make me a bit paranoid :) )I'm still considering the custom MarshalledValue implementation since it might yield some useful fine grained info about memory usage.
-
4. Re: Profiling session memory usage in a Seam application
sean.tozer May 4, 2010 3:57 PM (in response to alexandru.al.bologa.yahoo.com)This all sounds like something that could be valuable added to the Seam distribution as an option, to print out memory usage. I would imagine a number of people might be interested in something like that.