【问题标题】:Will Netty be a good choice for a Server multiplexor implementation?Netty 会是服务器多路复用器实现的好选择吗?
【发布时间】:2012-06-17 11:59:36
【问题描述】:

服务器通常会执行以下操作:

-Netty 服务器在 tcp 端口上接收 clientX 绑定。(都是非常简单的文本协议)。

-Netty 接收认证请求。

-Netty 现在将创建一个名为 clientX 的通道组 - 在此通道组内,它将创建 4 个 tcp 连接(每个外部服务器一个)在服务器上为用户执行身份验证并将 1 个 ACK​​ 发送回 clientX。

-从clientX接收下一个请求,它将消息路由/中继到clientX的通道组中的connection1。

-在clientX的通道组中接收下一条消息和路由/中继请求到connection2。

-接收注销请求,断开通道组,进而断开clientX通道组内的所有连接。

-从任何外部服务器接收到的消息必须路由/中继回 clientx (mux)

【问题讨论】:

    标签: netty


    【解决方案1】:

    这样的事情可以用netty来完成。

    我认为代理示例是一个很好的起点:

    https://github.com/netty/netty/tree/3/src/main/java/org/jboss/netty/example/proxy


    我已经修改了代理示例以实现如上所述的服务器。 设计:使用 netty-3.5.3

    客户端|(s-soc)-MUX_NIO_server-(c-socks) |server1(lb)

                                            |<->server2
                                            |<->server3
                                            |<->server4
    

    pipeline=>framedecoder-->stringdecoder-->clienthandler-->framedecoder-->stringdecoder-->serverHandler--|

    它运行 100% 直到达到 +/- 100 tps,然后来自客户端的相同消息一遍又一遍地发送到服务器,看起来像死锁情况。

    在两个处理程序中,我的 channelInterestChanged 事件如下所示:

    //channelInterestChanged 同步(trafficLock){

      if (e.getChannel().isWritable()) {
    
            inboundChannel.setReadable(true);
    
              if (inboundChannel != null) {
    
                 inboundChannel.setReadable(true);
             }
    
      }
    

    }

    在两个处理程序消息 rx 中我这样写:

    同步(trafficLock){

    final ChannelFutureListener writeListener =
                    new ChannelFutureListener() {
    
                        @Override
                        public void operationComplete(final ChannelFuture future)
                                throws Exception {
                            if (Consts.DEBUG_ENABLED) {
                                log.debug("Finished Writing message);
                            }
                        }
                    };
    
            /* if channel is write */
            if (inboundChannel.isWritable()) {
                    inboundChannel.write(bufferMsg).addListener(writeListener);
            }
            // If inboundChannel is saturated, do not read until notified in
             if (!inboundChannel.isWritable()) {
                e.getChannel().setReadable(false);
            }
    

    }

    知道可能出了什么问题以及在哪里解决这个问题吗?谢谢

    【讨论】:

    猜你喜欢
    • 2011-04-07
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2020-12-12
    • 2023-03-10
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    相关资源
    最近更新 更多