users@glassfish.java.net

Object Serialization Performance 2

From: <glassfish_at_javadesktop.org>
Date: Thu, 21 Jan 2010 12:49:55 PST

Hi everybody,

I'm developing a JEE application with a Swing client (application client container) using Glassfish v2.1.1-b31g.

The Swing client requests a set of JPA entities through a Stateless Session Bean with a remote interface(so, it uses Corba). Everything works fine unless the amount of requested entities is measured in thousands, that is when I get a very bad performance. I noticed that most of the time is being spent in the process of serializing/sending the entities to the Swing client.

I tried tuning the ORB settings as described in http://docs.sun.com/app/docs/doc/820-4343/abegt?a=view and setting properties (like ORBUseNIOSelectToWait=false) but nothing worked.

Searching in this forums I found this thread http://forums.java.net/jive/thread.jspa?threadID=18700 and particularly this post took my attention http://forums.java.net/jive/message.jspa?messageID=193088#193088. I serialized the entities "manually" (as the dalecooper82 says) and the result is awesome.

Before this, the process of serializing/sending a big graph of entities (~50,000 entities) to the Swing client inside a LAN took ~90,000 ms. Now it takes ~1,200 ms.

Just with a few changes in the code.


[b]EJB code[/b]:
--------------------------------------------------

********** [b]Before[/b] **********
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override
public <T> T getEntity(...) {
    ...
    entity = (T) query.getSingleResult();
    ...
    return entity;
}


********** [b]After[/b] **********
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override
public byte[] getEntity(...) {
    ...
    entity = (T) query.getSingleResult();
    ...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        try{
            oos.writeObject(entity);
        } finally {
            oos.close();
        }
    } catch (IOException e) {
            e.printStackTrace();
    }
    return baos.toByteArray();
}



[b]Swing client code[/b]:
--------------------------------------------------

********** [b]Before[/b] **********
    ...
    user = beanRemoteIface.getEntity(...);
    ...


********** [b]After[/b] **********
    ...
    byte[] serializedEntity = beanRemoteIface.getEntity(...);
    ByteArrayInputStream bais = new ByteArrayInputStream(serializedEntity);
    try {
        ObjectInputStream ois = new ObjectInputStream(bais);
        try{
            entity = ois.readObject();
        } finally {
            ois.close();
        }
    } catch (IOException e) {
            e.printStackTrace();
    }
    ...


I would like to know if there is something else to try or consider before adopting this technique for the communication between the EJBs and the Swing client.

I would really appreciate any help. Thanks in advance.
[Message sent by forum member 'jrico' (jnrico_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=382237