How to allow more concurrent client connections with Netty?

Firstly, thanks to all Netty contributors for the excellent library. I have enjoyed using it for several weeks.

I recently started downloading a test version of my system, but now I have a scalability problem with Netty. I tried to develop as many concurrent Netty clients as possible to connect to a Netty server. For a small number of clients (<50), the system works fine. However, for a large number of clients (> 100), I find that the client side always raises a "ClosedChannelException":

java.nio.channels.ClosedChannelException on org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ 1.operationComplete (NioClientSocketPipelineSink.java:157) on org.jboss.netty.channel.DefaultChannelFuture.jen at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners (DefaultChannelFuture.javahaps67) at org.jboss.netty.channel.DefaultChannelFuture.setSuccess (DefaultChannelFuture.javahaps16) at org.jboss.netty.channelFunction .setClosed (AbstractChannel.javahaps51) at org.jboss.netty.channel.AbstractChannel.setClosed (AbstractChannel.java:188) at org.jboss.netty.channel.socket.nio.NioSocketChannel.setClosed (NioSocketChannel.java:146 ) on org.jboss.netty.channel.socket.nio.NioWorker.close (NioWorker.java=92) on org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ Boss.close (NioClientSocketPipelineSink.java:415) on org.jboss.nett y.channel.socket.nio.NioClientSocketPipelineSink $ Boss.processConnectTimeout (NioClientSocketPipelineSink.javahaps79) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ Boss.run (NioClientSocketjavaPipeline.jbp99 netty.util.ThreadRenamingRunnable.run (ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker $ 1.run (DeadLockProofWorker.java:44) in java.util.concurrent.ThreadPoolExecutor.junWorker : 1110) in java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:603) in java.lang.Thread.run (Thread.java:722)

I am wondering how to get Netty to support more concurrent client connections like 10K. I am using the latest version of Netty. The following is a test scenario:

Each client sends a four-letter string to the server, and the server handler does nothing after receiving the string. Each of the servers and clients runs on a high-performance machine with eight-core and 16-gigabyte memory. These two machines are connected by a Gigabyte network.

Do you have any clues?

+7
source share
1 answer

1) You can configure ConnectTimeout in the client bootstrap to make sure that there are no problems with the network / server.

clientBootStrap.setOption("connectTimeoutMillis", optimumTimout); 

2) By setting the backlog value on the Netty server, you can increase the size of the incoming connection so that clients have a better replacement for connecting to the server.

 serverBootStrap.setOption("backlog", 1000); 

3) You said that your application creates many connections at the same time, the client Boss thread may lag if the application also connects quickly.

Netty 3.2.7 Final allows you to set more than one client boss thread in the NioClientSocketChannelFactory constructor to avoid this problem.

+6
source

All Articles