I’ve written a simple UDP server using Netty. The server listens on one port on a certain interface.
ChannelFactory factory =
new NioDatagramChannelFactory(
Executors.newCachedThreadPool());
ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
bootstrap.getPipeline().addLast("MyHandler", new TestHandler());
bootstrap.bind(new InetSocketAddress(InetAddress.getByName("192.168.1.100"), 8080));
I use a client that sends a lot of UDP datagrams to the server. When I profile my app with VisualVM, I see that there are only one thread (named New I/O worker #1) that processes the incoming messages. Is it as expected?
If yes, how a single thread can handle a big amount of incoming messages? I’ve already written an application with Spring integration that listens on a port for UDP datagrams (using a UDP inbound channel adapter), and there is one thread that listens on the port but this thread passes the incoming messages for processing to other threads of a pool.
Thanks
How many cores do you have on your machine?
If your handler pipe line does not do any blocking or any lengthy processing, it is very probable that the I/O processing will always be a lot faster than the network, i.e. the IO thread will be idle and waiting for work quite a large fraction of its time. No need to allocate another thread from the pool.
If, on the other hand, you handler involves lengthy processing or blocking calls, e.g. data base or file access, then you should hand of the processing to an ExecutionHandler, that transfer processing from the IO worker pool to a another thread pool.