Hi,

I like MINA for its simplicity and giving ability to the developers
for developing faster prototypes. Thanks for Apache-MINA team for such
a good project.

I am trying mina-0.9.4 for sending events @rate of 1000-2000/sec for a
prototype.  Average event size is 200bytes(approx.). I am using
default obejct factory for serialization.

After 18 minutes at that rate(with two clients), I found mina server
is raising OutofMemoryError and heap-space problems.
Server(RH-9)/Client(Win2k) are P4 3.06 GHZ with 512 MB Ram. I am using
JDK 1.5.0_06

I tried to dig around the code and found the ByteBuffer.putObject has
following code:
--------------------- Original code -----------------------------
 try
       {
           ObjectOutputStream out = new ObjectOutputStream( asOutputStream() )
           {
               protected void writeClassDescriptor( ObjectStreamClass
desc ) throws IOException
               {
                   writeUTF( desc.getName() );
               }
           };
           out.writeObject( o );
           out.flush();
       }
       catch( IOException e )
       {
           throw new BufferDataException( e );
       }

-------------------- Modified code ----------------------------
 try
       {
           ObjectOutputStream out = new ObjectOutputStream( asOutputStream() )
           {
               protected void writeClassDescriptor( ObjectStreamClass
desc ) throws IOException
               {
                   writeUTF( desc.getName() );
               }
           };
           out.writeObject( o );
       }
       catch( IOException e )
       {
           throw new BufferDataException( e );
       }finally{
           // TODO do out.close() in separate thread. is it ok to
call in separate thread
           out.close();// close will internally call flush and clear.
      }
---------------------------------------------------------------------
The problem with ObjectOutputStream is well documented in web. One
good link is: 
http://www.javaspecialists.co.za/archive/newsletter.do?issue=088&locale=en_US

In ByteBuffer.putObject, the ObjectOutputStream anyhow is going to be
garbage collected. But it seems for longer operations/large number of
calls, one needs to call reset/close on ObjectOutputStream to avoid a
memory leak. (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4363937)

My question are:
* Am I missing something ?
* Is this problem is  faced by any body earlier ?
* If I donot want to call ObjectOutputStream.close in finally
block(to avoid latency on the ByteBuffer.putObject callee), can  I
call it in separate Thread/pool ?  Calling ObjectOutputStream.close in
separate thread later will  cause any problems with ByteBuffer bytes.


TIA

GSS Mahadevan

Reply via email to