I am implementing a mina server for a protocol that can sometimes send very 
large messages (>250K).  I've noticed that receiving these messages can be very 
slow (>12s).

This performance is surprising, as I can transfer a 250K file to this same 
server via scp or netcat in under 1.5s.

I thought perhaps there was something subtly wrong with my code, so I wrote a 
very simple test server from scratch to see if it still has the same problem.  
Turns out, it performs exactly the same.  That is, sending large (>250K) 
messages takes a very long time (>12s) compared to setting up a netcat server 
(<1.5s).  In both cases the client is netcat.

Here is the test server code:
    public IoAcceptor runServer(int serverPort) throws IOException {
        final Logger logger= LoggerFactory.getLogger(this.getClass());
        TextLineCodecFactory codecFactory= new TextLineCodecFactory( 
                Charset.forName("UTF-8"), LineDelimiter.NUL, LineDelimiter.NUL 
);
        codecFactory.setDecoderMaxLineLength(500 * 1024);
        
        final IoAcceptor acceptor = new NioSocketAcceptor();
        acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );     
   
        acceptor.getFilterChain().addLast( "codec", new 
ProtocolCodecFilter(codecFactory) );

        acceptor.setHandler(new IoHandlerAdapter() {
            public void messageReceived(IoSession session, Object message) {
                String strMessage= (String)message;
                logger.debug("TestServer got message length {}", 
strMessage.length());
                session.write("OK\n");
                session.close(false);
            }            
        });
        acceptor.bind(new InetSocketAddress(serverPort));    

        logger.info("running server on {}", serverPort);
        return acceptor;
    }

It's likely that I'm missing something subtle here, so let me know if I'm 
coding this wrong.  If not, how can I get more logging/performance information 
about what mina is up to?  I don't have visibility into where the bottleneck is.


Thanks,
aaron

Reply via email to