Java 基于netty的应力工具和连接计数
我正在为web应用程序构建一个简单且最快的压力测试工具。要求:来自单个节点的最大http请求数(例如,普通请求) 我们以前使用过netty,我选择它来编写这个简单的测试。这是一个非常简单的方法,我只使用了4个扩展netty api的小类,在本地主机开发机器linux上提供了大约30K的rps 主要限制是linux中的传出连接限制打开文件/套接字限制,在我的机器上大约是30-40K。在这种情况下,您会得到java.net.BindException。因此,您必须手动限制传出netty连接的数量,以防止达到限制时性能下降 我用计数器实现了这个限制,在第一个版本中,我在SimpleChannelUpstreamHandler.channelConnected中增加了它,并在future.getChannel.getCloseFuture.addListener中减少了它。看到代码、注释在那个地方,它就不起作用了:连接没有按预期增加,计数器失败 只有在我将增量放在bootstrap.connect附近之后: SimpleChannelUpstreamHandler.messageReceived中的和减量: -它开始工作了。唯一的问题是——这有点不公平,因为您可以增加计数器,但无法连接或减少计数器,并且之后无法断开连接 那么,为什么计数器不能在正确的版本中工作呢 更新:按建议尝试,在SimpleChannelUpstreamHandler.channelConnected中使用inc/dec: 不起作用,发送>连接的数字也不可预测,例如:Java 基于netty的应力工具和连接计数,java,connection,netty,counter,stress-testing,Java,Connection,Netty,Counter,Stress Testing,我正在为web应用程序构建一个简单且最快的压力测试工具。要求:来自单个节点的最大http请求数(例如,普通请求) 我们以前使用过netty,我选择它来编写这个简单的测试。这是一个非常简单的方法,我只使用了4个扩展netty api的小类,在本地主机开发机器linux上提供了大约30K的rps 主要限制是linux中的传出连接限制打开文件/套接字限制,在我的机器上大约是30-40K。在这种情况下,您会得到java.net.BindException。因此,您必须手动限制传出netty连接的数量,以
client1 stat: connected= 0, sent= 0, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 11, sent= 4990, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 1, sent= 8591, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 459, sent=13064, ERRORS: timeouts= 0, binds= 5, connects=0
client1 stat: connected= 1545, sent= 7234, ERRORS: timeouts= 0, binds= 115, connects=0
client1 stat: connected= 0, sent=10037, ERRORS: timeouts= 0, binds= 80, connects=0
sadf是一种理论
在您的原始版本中,对于所有连接尝试,您都会减少已连接计数器的值,但对于失败的连接尝试,则会减少计数器的值。如果您在channelConnected中增加计数器,并在ChannelCloseFuture和该点上添加一个递减侦听器,我想您将获得更好的结果
这是因为
boostrap.connect().getChannel().getCloseFuture(...)
将始终调用operationComplete,即使该通道从未连接
更新:
以确保仅统计连接的通道。在应力ClientHandler中的通道连接calback:
connected.incrementAndGet();
ctx.getChannel().getCloseFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
connected.decrementAndGet();
}
});
您需要增加ChannelFutureListener中的发送计数,该侦听器添加到从写入操作返回的ChannelFuture中。。。活动否则,即使写入挂起,也会增加计数器。您建议将来如何减少计数器?正如我所描述的,我尝试了future.getChannel.getCloseFuture.addListenernew ChannelFutureListener{…但没有运气。还有另一个选项-服务器端:SimpleChannelHandler.channelClosed。你的意思是吗?谢谢,这是关于发送计数器的,但是关于已建立的连接计数器呢?这就是这个问题的内容
client1 stat: connected= 0, sent= 0, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 11, sent= 4990, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 1, sent= 8591, ERRORS: timeouts= 0, binds= 0, connects=0
client1 stat: connected= 459, sent=13064, ERRORS: timeouts= 0, binds= 5, connects=0
client1 stat: connected= 1545, sent= 7234, ERRORS: timeouts= 0, binds= 115, connects=0
client1 stat: connected= 0, sent=10037, ERRORS: timeouts= 0, binds= 80, connects=0
boostrap.connect().getChannel().getCloseFuture(...)
connected.incrementAndGet();
ctx.getChannel().getCloseFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
connected.decrementAndGet();
}
});