Hi,
My team is considering using MINA UDP to implement our RPC server. The
problem is, we saw lots of packet loss when our prototype server tried to
handle over 300 messages per second. I thought this was due to overflow of
UDP's receiving buffer, but increasing the receiving buffer size didn't cure
the problem. We also wrote a simple server that used plain DatagramSocket
and dispatched incoming message to worker threads. This simple server worked
well under thousands of messages per second even though it implemented
exactly the same logic as the MINA version. We're using MINA 1.1.7.

My server can be simplified to the following code. The decoder, encoder, and
IoHandler are very simple. They shouldn't take more than a few million
seconds to run. May I know if I have missed anything, or if there is any tip
or magic trick that I need to be aware of, in order to reduce packet losses?
Thanks!

public static void main(String[] args) throws IOException {
DatagramAcceptor acceptor = new
DatagramAcceptor(Executors.newCachedThreadPool());

acceptor.getDefaultConfig().getSessionConfig().setReceiveBufferSize(BUFFER_SIZE);
acceptor.getDefaultConfig().getSessionConfig().setReuseAddress(true);
 acceptor.getDefaultConfig().setThreadModel(ThreadModel.MANUAL);
acceptor.getFilterChain().addLast("threadPool", new
ExecutorFilter(Executors.newCachedThreadPool()));
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new
MyEncoder(), new MyDecoder()));

acceptor.bind(new InetSocketAddress(PORT), new MyHandler());
System.out.println("UDP listening on "+PORT);
}

private static class MyHandler extends IoHandlerAdapter {
private MessageHandler handler = new MessageHandler();
public void messageReceived(IoSession session, Object message) throws
Exception {
Message response = handler.execute((byte[])message);
session.write(response);
}
 public void sessionClosed(IoSession session) throws Exception {
 session.close();
 }
 }

Reply via email to