netty4.0 研究 ing ... ...

之前做过一个基于netty3.X版本的server,性能测试很不错,现在netty4.0已经出beta2版本beta3的快照也出来了,相信不久就会发布,先尝鲜,总结了一些东西:


#The shutdown process of a typical network application is composed of the following three steps:
#
#Close all server sockets if there are any,
#
#Close all non-server sockets (i.e. client sockets and accepted sockets) if there are any, and
#
#Release all resources used by ServerBootstrap or Bootstrap.


action:
#2. How do I incorporate my blocking application code with the non-blocking NioEventLoopGroup?
#
#NioEventLoopGroup contains n Threads that handle the IO of all the registered Channels.
#
#If your applicaiton's handler blocks such as (reading from a database) or is CPU intensive, the worker thread pool maybe exhausted and performance will degrade.
#
#We recommend that you implement your blocking application code in another thread pool. You can do this by adding your handler with an extra EventExecutor to the ChannelPipeline.
#
#  1 public static void main(String[] args) throws Exception {
#  2         final EventExecutor executor = new DefaultEventExecutor(8);
#
#  4         ServerBootstrap bootstrap = new ServerBootstrap();
#            bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup());
#  6         bootstrap.childHandler(new ChannelInitializer<Channel>() {
#                @Override
#  8             public void initChannel(Channel channel) {
#                    ChannelPipeline pipeline = channel.pipeline();
# 10                 pipeline.addLast("decoder", new HttpRequestDecoder());
#                    pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
# 12                 pipeline.addLast("encoder", new HttpResponseEncoder());
#                    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
# 14
#                    // MyHandler contains code that blocks so add it with the
# 16                 // EventExecutor to the pipeline.
#                    pipeline.addLast(executor, "handler", new MyHandler());
# 18             }
#            });
# 20         ...
#
# 22         sb.bind(socketAddress);
#
# 24         // Other code
#
# 26     }
#
# 28
#        public class MyHandler extends SimpleChannelUpstreamHandler {
# 30         // Your blocking application code
#    }





netty4变化较大,不管是线程池管理还是buffer,新添加了AIO,但是建议还是用nio(个人观点),但是根据开发者帮助文档,基本上也可以快速实现一个稳定高效的服务端(TCP/IP)socket长连接。

有关netty4.0 持续关注中... ...  有时间的话 将会很快写一个基于netty4.0的server。

http://netty.io/4.0/guide/#faq.3,在上面可以找到很多资料,并且快速上手,如果你对netty3足够熟悉的话。

http://netty.io/4.0/xref/(source)

你可能感兴趣的:(netty4.0 研究 ing ... ...)