如何允许与 Netty 的更多并发客户端连接? [英] How to allow more concurrent client connections with Netty?

查看:55
本文介绍了如何允许与 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)在 org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:381)在 org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:367)在 org.jboss.netty.channel.DefaultChannelFuture.setSuccess(DefaultChannelFuture.java:316)在 org.jboss.netty.channel.AbstractChannel$ChannelCloseFuture.setClosed(AbstractChannel.java:351)在 org.jboss.netty.channel.AbstractChannel.setClosed(AbstractChannel.java:188)在 org.jboss.netty.channel.socket.nio.NioSocketChannel.setClosed(NioSocketChannel.java:146)在 org.jboss.netty.channel.socket.nio.NioWorker.close(NioWorker.java:592)在 org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.close(NioClientSocketPipelineSink.java:415)在 org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:379)在 org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:299)在 org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)在 org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)在 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.

你有什么提示吗?

推荐答案

1) 您可以在客户端引导程序中调整 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 服务器的 backlog 值,可以增加传入连接队列的大小,让客户端有更好的机会连接到服务器

2) By setting the backlog value in the Netty server, you can increase the queue of incoming connection size, so clients will have better chance 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆