Netty(二):Netty为啥去掉支持AIO?
匠心零度 转载请注明原创出处,谢谢!
疑惑
我们都知道bio nio 以及nio2(也就是aio),如果不是特别熟悉可以看看我之前写的网络 I/O模型,那么netty为什么还经常看到类似下面的这段代码呢?
EventLoopGroup ……= new NioEventLoopGroup();
……
……
b.group(……).channel(NioSocketChannel.class)……
……
……
ChannelFuture f = b.bind(PORT).sync();
不选择bio模型我们知道,那么为什么不选择aio模式呢?而还是选择nio模式呢?这是一个值得思考的问题,我就一直很好奇,因为在网络 I/O模型里面介绍的,明显AIO要比NIO模型还要好。

那么为什么Netty还是选择的NIO模型呢?
Netty一些组件简单介绍
Netty中这样定义EventLoop的,本篇重点不在这里,后续继续介绍EventLoop。
Will handle all the I/O operations for a [
Channel] once registered. One [EventLoop] instance will usually handle more than one [Channel] but this may depend on implementation details and internals.
Netty中这样定义EventLoopGroup的,本篇重点不在这里,后续继续介绍EventLoopGroup。
Special [
EventExecutorGroup] which allows registering [Channel]s that get processed for later selection during the event loop.
Netty中这样定义Channel的,本篇重点不在这里,后续继续介绍Channel。
A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.
A channel provides a user:
- the current state of the channel (e.g. is it open? is it connected?),
- the [configuration parameters] of the channel (e.g. receive buffer size),
- the I/O operations that the channel supports (e.g. read, write, connect, and bind), and
- the [
ChannelPipeline] which handles all I/O events and requests associated with the channel.
Netty中这样定义ChannelFuture的,本篇重点不在这里,后续继续介绍ChannelFuture。
The result of an asynchronous [
Channel] I/O operation.All I/O operations in Netty are asynchronous. It means any I/O calls will return immediately with no guarantee that the requested I/O operation has been completed at the end of the call. Instead, you will be returned with a [
ChannelFuture] instance which gives you the information about the result or status of the I/O operation.A [
ChannelFuture] is either uncompleted or completed. When an I/O operation begins, a new future object is created. The new future is uncompleted initially - it is neither succeeded, failed, nor cancelled because the I/O operation is not finished yet. If the I/O operation is finished either successfully, with failure, or by cancellation, the future is marked as completed with more specific information, such as the cause of the failure. Please note that even failure and cancellation belong to the completed state.
Netty提供的网络传输实现

备注: 这个是参考netty实战书籍的。
看看RocketMQ里面的写法,等netty系列完成了,后续RocketMQ会继续分析的。

备注:
If you are running on linux you can use EpollEventLoopGroup and so get better performance, less GC and have more advanced features that are only available on linux.
epoll对文件描述符有两种操作模式--LT(level trigger水平模式)和ET(edge trigger边缘模式)
简单来讲,LT是epoll的默认操作模式,当epoll_wait函数检测到有事件发生并将通知应用程序,而应用程序不一定必须立即进行处理,这样epoll_wait函数再次检测到此事件的时候还会通知应用程序,直到事件被处理。
而ET模式,只要epoll_wait函数检测到事件发生,通知应用程序立即进行处理,后续的epoll_wait函数将不再检测此事件。因此ET模式在很大程度上降低了同一个事件被epoll触发的次数,因此效率比LT模式高。
解释为什么epoll默认是LT的原因(超哥解释,个人觉得还是非常不错的)
LT(level triggered):LT是缺省的工作方式,并且同时支持block和no-block socket。在这种做法中,内核告诉你一个文件描述符是否就绪了,然后你可以对这个就绪的fd进行IO操作。如果你不作任何操作,内核还是会继续通知你的,所以,这种模式编程出错误可能性要小一点。传统的select/poll都是这种模型的代表。
Netty为啥去掉支持AIO?
根据这个疑问搜索了下,查看到github上面的说明:https://github.com/netty/netty/issues/2515。

备注:总的来说可能支持AIO Not faster than NIO (epoll) on unix systems (which is true) 而且性价比不高,可能觉得不值得,反正netty已经封装好,用户调用起来也很简单和底层用nio或者aio其实用户不需要关心的,只要快就行。
由于自己水平问题,可能很多理解不到位,欢迎大家积极在留言区进行留言讨论,感谢。在后面合适的机会我们继续讨论,AIO Not faster than NIO (epoll) on unix systems (which is true) 这是为什么呢? 目前我还是先学习netty主干,后续会继续回到这个话题上面。
如果读完觉得有收获的话,欢迎点赞、关注、加公众号【匠心零度】,查阅更多精彩历史!!!

Netty(二):Netty为啥去掉支持AIO?的更多相关文章
- Netty对Protocol Buffer的支持(七)
Netty对Protocol Buffer的支持(七) 一.简介 在上一篇博文中笔者已经介绍了google的Protocol Buffer的使用,那么本文笔者就开始介绍netty对Protocol B ...
- Netty序章之BIO NIO AIO演变
Netty序章之BIO NIO AIO演变 Netty是一个提供异步事件驱动的网络应用框架,用以快速开发高性能.高可靠的网络服务器和客户端程序.Netty简化了网络程序的开发,是很多框架和公司都在使用 ...
- Netty学习——Netty和Protobuf的整合(二)
Netty学习——Netty和Protobuf的整合(二) 这程序是有瑕疵的,解码器那里不通用,耦合性太强,有两个很明显的问题,但是要怎么解决呢?如:再加一个内部类型 Person2,之前的代码就不能 ...
- Netty学习笔记(二)——netty组件及其用法
1.Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端. 原生NIO存在的问题 1) NIO的类库和API繁杂,使用麻烦:需要熟练掌握Selector.Se ...
- 【Netty】Netty入门之WebSocket小例子
服务端: 引入Netty依赖 <!-- netty --> <dependency> <groupId>io.netty</groupId> <a ...
- Netty学习——Netty和Protobuf的整合(一)
Netty学习——Netty和Protobuf的整合 Protobuf作为序列化的工具,将序列化后的数据,通过Netty来进行在网络上的传输 1.将proto文件里的java包的位置修改一下,然后再执 ...
- JS table内容转成二维数组,支持colspan和rowspan
思路:1.先初始化colspan的数据到数组2.根据rowspan和colspan计算th和td的矩阵二次填充数组 说明:需要引用到第三方库jQuery,table中的th和td行和列跨度必须正确 & ...
- PHP 二维数组去掉重复值并保持原结构
PHP 二维数组去掉重复值并保持原结构 直接上代码,解释很详细 //二维数组去掉重复值 function arrunique($a){ foreach($a[0] as $k => $v){ / ...
- 3. 彤哥说netty系列之Java BIO NIO AIO进化史
你好,我是彤哥,本篇是netty系列的第三篇. 欢迎来我的公从号彤哥读源码系统地学习源码&架构的知识. 简介 上一章我们介绍了IO的五种模型,实际上Java只支持其中的三种,即BIO/NIO/ ...
随机推荐
- 一行代码搭建 Python 静态服务器
如果电脑上安装有Python, 那么进入到目标文件夹,在终端中运行如下命令, 即可搭建映射当前目录的静态文件服务器: python -m SimpleHTTPServer 9000 默认端口号是800 ...
- Java常用代码总结
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/7004474.html 1.日期与字符串之间的转换 public static void m ...
- BZOJ 2683: 简单题 [CDQ分治]
同上题 那你为什么又发一个? 因为我用另一种写法又写了一遍... 不用排序,$CDQ$分治的时候归并排序 快了1000ms... #include <iostream> #include ...
- 第一周 动态规划Dynamic Programming(一)
一.概念 动态规划是运筹学的一个分支,是求解决策过程最优化的数学方法.动态规划是通过拆分问题,定义问题状态和状态之间的关系,使得问题能够以递推(或者说分治)的方式去解决. 1.试用情况: 2.解决步骤 ...
- VC调用Delphi对象接口
说在前头 很久没有碰Delphi的东西了,今天有个朋友让我帮他将一个Delphi中已经实现的功能在VC中进行使用,虽然后来又用VC的方式实现了该功能,但是在实现过程中想到了这样的调用方式,特写下本文以 ...
- mysql 5.7 支持json格式
1.JSON格式的支持:mysql> create table user ( uid int auto_increment, -> data json,primary key(u ...
- WPF字典集合类ObservableDictionary
WPF最核心的技术优势之一就是数据绑定.数据绑定,可以通过对数据的操作来更新界面. 数据绑定最经常用到的是ObservableCollection<T> 和 Dictionary<T ...
- CentOS6.8配置GO语言开发环境
Go语言是谷歌2009发布的第二款开源编程语言,Go语言专门针对多处理器系统应用程序的编程进行了优化,使用Go编译的程序可以媲美C或C++代码的速度,而且更加安全.支持并行进程. 鉴于原来越多的开源项 ...
- 关于Frame加背景的那点事?
最近新生问我一个问题,继承自Frame(可不是继承自JFrame)的框架怎样添加背景图片, 真够坑的,当时还真懵了,废话少说直接上代码: import java.awt.*; import java. ...
- html2canvas在微信中无法使用
html2canvas: https://github.com/niklasvh/html2canvas 本来想在微信网页中使用html2canvas生成图片,结果死活不行 测试发现在Chrome,手 ...