It is probably bad form to reply to my own post, but I thought that I
would describe what I have discovered for people that might read the ML
archives.
There were two issues that limited the number of UDP ports that I could
listen on:
1) The number of allowed file descriptors for the process. This was
solved (on Linux) by upping the limit in /etc/security/limits.
2) The number of threads that were being created.
When I read the MINA code I realised that creating a DatagramAcceptor
created a new thread. So if I created 1000 DatagramAcceptors each with 1
socket bound, I get 1000 threads. This is not very optimal.
Switching to 1 DatagramAcceptor with 1000 sockets bound to it, means I
get just 1 thread. As my protocol is completely CPU bound and will never
block there is nothing to be gained by having multiple threads listening.
So now I can handle many 1000's of UDP ports with 0.1% of CPU usage and
very limited memory consumption.
Regards
Richard
Richard wrote:
> Hi
>
> I am new to MINA and I have a slightly unusual application. I am hoping
> that someone can give me some advice on the best way to optimise MINA's
> performance.
>
> I have a server for a UDP protocol for which I have implemented a
> handler, decoder, encoder etc. The server works just fine.
>
> But I want to run the protocol on a large number of UDP ports to support
> lots of clients, each with their own port number for talking to my
> server. (I would not have designed it this way, but I do not have
> control of the client implementation).
>
> So I took the, possibly naive, approach of just looping over the
> following code many times to start lots of listeners:
>
>
> acceptor = new DatagramAcceptor();
> acceptor.getDefaultConfig().getSessionConfig().setReuseAddress(true);
>
> DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
> chain.addLast("", new LoggingFilter());
> chain.addLast("codec", new ProtocolCodecFilter(
> new CodecFactory()));
> acceptor.bind(new InetSocketAddress(udp_port), new
> Handler(this));
>
> The only other MINA options that I am setting are:
>
> ByteBuffer.setUseDirectBuffers(false);
> ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
>
> Using this approach I am able to create 250 instances of my server
> before I start to get errors. I think that the errors are either file
> descriptor limits or memory problems because of the number of threads
> that are being created ~500.
>
> Can anyone offer any advice on how I can best setup MINA to handle this
> type of application? I would like to listen on 1000+ UDP ports.
>
>
> Many thanks
>
> Richard
>
>
>