如何允许与Netty更多的并发客户端连接? [英] How to allow more concurrent client connections with Netty?
问题描述
首先,感谢所有的Netty贡献者的伟大的图书馆。我一直高兴地使用它几个星期。
First, thanks all the Netty contributors for the great library. I have been happily using it for several weeks.
最近,我开始加载测试我的系统,但现在我遇到一些可扩展性问题与Netty。我试图尽可能多的同时Netty客户端尽可能连接到Netty服务器。对于少数客户端(<50),系统只是工作正常。但是,对于大量客户端(> 100),我发现客户端总是提示ClosedChannelException:
Recently, I started to load test my system but now I'm experiencing some scalability problem with Netty. I tried to fork as many simultaneous Netty clients as possible to connect to a Netty server. For small number of clients (<50), the system just works fine. However, for large number of clients (>100), I find the client side always prompts the "ClosedChannelException":
java.nio.channels.ClosedChannelException
在org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ 1.operationComplete(NioClientSocketPipelineSink.java:157)
at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:381)
at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:367)
at org.jboss.netty.channel.DefaultChannelFuture.setSuccess(DefaultChannelFuture.java:316)
at org。 jboss.netty.channel.AbstractChannel $ ChannelCloseFuture.setClosed(AbstractChannel.java:351)
at org.jboss.netty.channel.AbstractChannel.setClosed(AbstractChannel.java:188)
at org.jboss。 netty.channel.socket.nio.NioSocketChannel.setClosed(NioSocketChannel.java:146)
at org.jboss.netty.channel.socket.nio.NioWorker.close(NioWorker.java:592)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ Boss.close(NioClientSocketPipelineSink.java:415)
在org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ Boss.processConnectTimeout(NioClientSocketPipelineSink.java :379)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink $ Boss.run(NioClientSocketPipelineSink.java:299)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable .java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker $ 1.run(DeadLockProofWorker.java:44)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1110)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
java.nio.channels.ClosedChannelException at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$1.operationComplete(NioClientSocketPipelineSink.java:157) at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:381) at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:367) at org.jboss.netty.channel.DefaultChannelFuture.setSuccess(DefaultChannelFuture.java:316) at org.jboss.netty.channel.AbstractChannel$ChannelCloseFuture.setClosed(AbstractChannel.java:351) at org.jboss.netty.channel.AbstractChannel.setClosed(AbstractChannel.java:188) at org.jboss.netty.channel.socket.nio.NioSocketChannel.setClosed(NioSocketChannel.java:146) at org.jboss.netty.channel.socket.nio.NioWorker.close(NioWorker.java:592) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.close(NioClientSocketPipelineSink.java:415) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:379) at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:299) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
我想知道如何让Netty支持更多的同时客户端连接,如10K。我使用最新版本的Netty。以下是测试场景:
I am wondering how to make Netty support more simultaneous client connections, such as 10K. I am using the newest version of Netty. Following is the testing scenario:
每个客户端向服务器发送一个四个字母的字符串,服务器处理程序在接收到字符串时不执行任何操作。每个服务器和客户端都运行在具有八核和16GB内存的高性能机器上。这两台机器通过千兆网络连接。
Each client sends a four letter string to the server and the server handler does nothing upon receiving the string. Each of the server and the clients is running on a high performance machine with eight-core and 16GB memory. The two machines are connected by a Gigabyte network.
您有任何提示吗?
推荐答案
在客户端引导中调整connectTimeout以确保没有网络/服务器问题
1) You can tweak the connectTimeout in the client bootstrap to make sure, there is no network/server issues
clientBootStrap.setOption("connectTimeoutMillis", optimumTimout);
2)通过在Netty服务器中设置积压值, ,因此客户端将更好地连接到服务器。
2)By setting the backlog value in the Netty server, you can increase the queue of incoming connection size, so clients will have better change of connecting to the server
serverBootStrap.setOption("backlog", 1000);
3)你说你的应用程序正在创建多个连接,Client Boss线程可能滞后,如果应用程序连接太快。
3) You have said that, your application is creating many connections simultaneously, Client Boss thread may lag behind, if the application is connecting too fast.
Netty 3.2.7 Final允许在NioClientSocketChannelFactory构造函数中设置多个Client Boss线程,以避免此问题。
Netty 3.2.7 Final allows to set more than one Client Boss thread in NioClientSocketChannelFactory constructor to avoid this issue.
这篇关于如何允许与Netty更多的并发客户端连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!