【发布时间】:2014-02-14 01:03:31
【问题描述】:
情况:我有一个使用 Netty 4.0.17.Final 的代理应用程序(仅供参考:我已经遇到了 4.0.13.Final 和 4.0.9.Final 版本的问题),就是这样基于proxy from the Netty examples。
我的代码与示例之间的主要区别在于,当通道处于活动状态时,我的代码不会连接到后端服务器,而是仅在第一次读取时,因为此读取必须先对输入进行一些检查,然后再连接和将该消息转发到后端服务器。
我已经对我的应用进行了数小时的单元测试和负载测试,它运行良好。
问题:
由于收到的第一条消息需要执行一些阻塞操作,我尝试为执行该操作的那个处理程序使用单独的 EventExecutorGroup(这样 IO 线程就不会被阻塞):
private static final EventExecutorGroup handlersExecutor = new DefaultEventExecutorGroup(10);
...
pipeline.addLast(handlersExecutor, "authenticationHandler", new FrontendHandler(outboundAddress));
这(= 我所做的唯一更改!)在负载测试期间破坏了应用程序。什么破? 3500 个客户端连接中的 XXX 向我报告说,这些客户端的 500 条消息中有 YY 没有得到代理的回复(每个请求都应该得到一个响应)。客户端日志摘录:
2014-02-14 00:39:56.146 [id: 0x34cb2c60] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:7201)。收到的 PDU:13
2014-02-14 00:39:56.146 [id: 0xf0955993] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:7201)。收到的 PDU:13
2014-02-14 00:39:56.147 [id: 0x9a911fa3] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:7201)。收到的 PDU:13
2014-02-14 00:39:56.149 [id: 0x811bbadf] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:7201)。收到的 PDU:13
2014-02-14 00:39:56.150 [id: 0x0c4d4c5a] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:7201)。收到的 PDU:13
代理应用告诉我收到并转发了 500 条消息,但只收到了 13 条回复并转发回客户端:
2014-02-14 00:39:57.683 [id: 0x39af563b] 错误 (be.demmel.fun.UcpDecoder) - 空闲连接 (/127.0.0.1:49359)。 PDU 收到:500
2014-02-14 00:39:57.683 [id: 0x82056d39] 错误 (be.demmel.fun.FrontendHandler) - 空闲连接 (/127.0.0.1:52004), 关闭它。转发的 PDU:500。成功:500
2014-02-14 00:40:00.717 [id: 0xcdca8f66] 错误 (be.demmel.fun.UcpDecoder) - 空闲连接 (/127.0.0.1:7900)。收到的 PDU:13
2014-02-14 00:40:00.718 [id: 0xcdca8f66] 错误 (be.demmel.fun.BackendHandler) - 空闲连接 (/127.0.0.1:7900)。转发的 PDU:13。成功:13
服务器告诉我一切正常:
2014-02-14 00:40:02.855 [id: 0x4980be2c] 错误 (com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接 (/127.0.0.1:37944)。收到的 PDU:500
2014-02-14 00:40:02.856 [id: 0x4980be2c] 错误 (com.nsn.ucpsimulator.server.TestUcpHandler) - 空闲 连接(/127.0.0.1:37944)。发回的 PDU:500
有人知道是什么原因造成的吗?
附加信息:
请注意,在我开始为阻塞处理程序使用单独的
EventExecutorGroup之前,一切正常。每次 XX 客户端阻塞时,它们都会阻塞转发给客户端的相同数量的回复。
我已经在这里上传了 netty 代码(它是可运行的,包含代理、服务器和客户端应用程序以及一个 README):https://github.com/AndrewBourgeois/ucp-proxy/tree/master/src/main/java/be/demmel/fun
代理应用被杀时,服务器端会弹出这个错误:
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.7.0_45]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:1.7.0_45]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.7.0_45]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.7.0_45]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379) ~[na:1.7.0_45]
at io.netty.buffer.UnpooledUnsafeDirectByteBuf.setBytes(UnpooledUnsafeDirectByteBuf.java:401) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:869) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:208) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:87) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:478) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341) ~[netty-all-4.0.9.Final.jar:na]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [netty-all-4.0.9.Final.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
我相信这个错误表明我的 Netty 处理程序没有处理服务器回复。
【问题讨论】:
-
你解决过这个问题吗?我也有类似的问题。