Ok, so i've updated my classes to use IoBuffer instead of ByteBuffer, so my 
classes are now:

This is my Encoder:

public class ServiceEnvironmentMessageEncoder extends ProtocolEncoderAdapter {
    public void encode(IoSession session, Object message, ProtocolEncoderOutput 
out) throws EncoderException {
        ServiceEnvironmentMessage serviceEnvironmentMessage = 
(ServiceEnvironmentMessage)message;
        IoBuffer buffer = null;
        buffer = serviceEnvironmentMessage.encode(buffer);
        buffer.rewind();
        out.write(buffer);
    }
}

And my decoder:

public class ServiceEnvironmentMessageDecoder extends CumulativeProtocolDecoder 
{
    protected boolean doDecode(IoSession session, IoBuffer in, 
ProtocolDecoderOutput out) throws DecoderException {
        IoBuffer inFlipped = in.flip();
        byte[]inArray = inFlipped.array();
        out.write(decode(inArray));
        return true;
    }

    private ServiceEnvironmentMessage decode(byte[] stream) throws 
DecoderException {
        IoBuffer iob = IoBuffer.wrap(stream);
        ServiceEnvironmentMessageContainer container = new 
ServiceEnvironmentMessageContainer(ServiceEnvironmentMessageGrammar.getInstance());
        decoder.decode(iob, container);
        ServiceEnvironmentMessage message = 
container.getServiceEnvironmentMessage();
        container.clean();
        return message;
    }
}

Without the transformation to array and wrap i get an exception:
07-24 16:48:35,030 [NioDatagramAcceptor-2] WARN  
org.apache.mina.filter.logging.LoggingFilter - EXCEPTION :
org.apache.mina.filter.codec.ProtocolDecoderException: 
java.lang.IllegalArgumentException: message (Hexdump: empty)

Anyway it works well under low to moderate load, but under high load it 
performs poorly, the response messages are not getting sent through fast enough 
it seems. i'm trying to figure out how to optimise it. Using jConsole and 
Yourkit profiler.

Brendan





-----Original Message-----
From: Emmanuel Lécharny [mailto:[email protected]] 
Sent: 24 July 2012 16:27
To: [email protected]
Subject: Re: Upgrade considerations between MINA 2.0.0-M3 to 2.0.4

For some unknown reason, you are sending every mails twice. Could you 
check that please ?


Le 7/24/12 2:13 PM, Brendan Crowley a écrit :
> I've tried using flip on the decoder on the IoBuffer and it solves my looping 
> issue, so this now is my currently implementation:
>
> This is my Encoder:
>
> public class ServiceEnvironmentMessageEncoder extends ProtocolEncoderAdapter {
>      public void encode(IoSession session, Object message, 
> ProtocolEncoderOutput out) throws EncoderException {
>          ServiceEnvironmentMessage serviceEnvironmentMessage = 
> (ServiceEnvironmentMessage)message;
>          ByteBuffer buffer = null;
>          buffer = serviceEnvironmentMessage.encode(buffer);
>          buffer.rewind();
>          IoBuffer ioBuffer = IoBuffer.wrap(buffer);
>          out.write(ioBuffer);
>      }
> }
>
> And my decoder:
>
> public class ServiceEnvironmentMessageDecoder extends 
> CumulativeProtocolDecoder {
>      protected boolean doDecode(IoSession session, IoBuffer in, 
> ProtocolDecoderOutput out) throws DecoderException {
>          IoBuffer inFlipped = in.flip(); // MINA 2.0.4 implementation
>          byte[]inArray = inFlipped.array(); // MINA 2.0.4 implementation
>          /* MINA 2.0.0-M3 Implementation
>          byte[]inArray = in.array(); */
>          out.write(decode(inArray));
>          return true;
>      }
>
>      private ServiceEnvironmentMessage decode(byte[] stream) throws 
> DecoderException {
>          ByteBuffer bb = ByteBuffer.wrap(stream);
>          ServiceEnvironmentMessageContainer container = new 
> ServiceEnvironmentMessageContainer(ServiceEnvironmentMessageGrammar.getInstance());
>          decoder.decode(bb, container);
>          ServiceEnvironmentMessage message = 
> container.getServiceEnvironmentMessage();
>          container.clean();
>          return message;
>      }
> }

Not sure why you transform the IoBuffer to an array, to transform it 
back to a ByteBuffer...
>
> So, for my original issue - under high load (4000+ transactions per second) 
> my responses are timing out on the request side, is there performance 
> tweaking i can do to improve performance?

Depends. Have you used a profiling to see where the time is consummed ?
>
> I see in the FAQs under troubleshooting: "I get OutOfMemoryError or response 
> timeout and connection reset under heavy load."
> There is a recommendation to switch buffer type to heap.
Default buffers are heap buffers.
>   How can i tell what type i'm already using and how to set it to 'heap' type?
It's already set to heap.

> It says to do this, but make little sense to me:
> ByteBuffer.setUseDirectBuffers(false);
> ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

Don't use direct buffer. This is genrally not a good idea...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Reply via email to