Netty Message RefCount
ByteBuf is always reference counted
To control the life cycle of a ByteBuf in a more predictable way, Netty does not rely on the garbage collector anymore but employs an explicit reference counter. Here's the basic rule:
- When a buffer is allocated, its initial reference count is 1.
- If the reference count of the buffer is decreased to 0, it is deallocated or returned to the pool it originated from.
- The following attempts trigger an
IllegalReferenceCountException:- Accessing a buffer whose reference count is 0,
- Decreasing the reference count to a negative value, or
- Increasing the reference count beyond
Integer.MAX_VALUE.
- Derived buffers (e.g. slices and duplicates) and swapped buffers (i.e. little endian buffers) share the reference count with the buffer it was derived from. Note the the reference count does not change when a derived buffer is created.
When a ByteBuf is used in a ChannelPipeline, there are additional rules you need to keep in mind:
- Each inbound (a.k.a. upstream) handler in a pipeline has to release the received messages. Netty does not release them automatically for you.
- Note that codec framework does release the messages automatically and a user has to increase the reference count if he or she wants to pass a message as-is to the next handler.
- When an outbound (a.k.a. downstream) message reaches at the beginning of the pipeline, Netty will release it after writing it out.
Automatic buffer leak detection
Although reference counting is very powerful, it is also error-prone. To help a user find where he or she forgot to release the buffers, the leak detector logs the stack trace of the location where the leaked buffer was allocated automatically.
Because the leak detector relies on PhantomReference and obtaining a stack trace is a very expensive operation, it samples approximately 1% of allocations only. Therefore, it's a good idea to run the application for a reasonably long time to find all possible leaks.
Once all leaks are found and fixed. You can turn this feature off to remove its runtime overhead completely by specifying the -Dio.netty.noResourceLeakDetection JVM option.
Netty Message RefCount的更多相关文章
- netty——私有协议栈开发案例
netty--私有协议栈开发案例 摘要: 在学习李林峰老师的Netty权威指南中,觉得第十二章<私有协议栈开发>中的案例代码比较有代表性,讲的也不错,但是代码中个人认为有些简单的错误,个人 ...
- 基于Protostuff实现的Netty编解码器
在设计netty的编解码器过程中,有许多组件可以选择,这里由于咱对Protostuff比较熟悉,所以就用这个组件了.由于数据要在网络上传输,所以在发送方需要将类对象转换成二进制,接收方接收到数据后,需 ...
- alluxio源码解析-netty部分(2)
netty简介 Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端. netty作为alluxio中重要的通讯组件 在常见的客户端上传,下载中,都会有n ...
- Eclipse 4.2 failed to start after TEE is installed
--------------- VM Arguments--------------- jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...
- netty系列之:选byte还是选message?这是一个问题
目录 简介 类型的定义 搭建UDT stream服务器 搭建UDT message服务器 Stream和Message的handler 总结 简介 UDT给了你两种选择,byte stream或者me ...
- netty SimpleChannelInboundHandler<Message>和ChannelInboundHandlerApter
一个兄弟的测试体验:https://blog.csdn.net/linuu/article/details/51307060 比较官方:https://www.imooc.com/article/28 ...
- 从netty-example分析Netty组件续
上文我们从netty-example的Discard服务器端示例分析了netty的组件,今天我们从另一个简单的示例Echo客户端分析一下上个示例中没有出现的netty组件. 1. 服务端的连接处理,读 ...
- 从netty-example分析Netty组件
分析netty从源码开始 准备工作: 1.下载源代码:https://github.com/netty/netty.git 我下载的版本为4.1 2. eclipse导入maven工程. netty提 ...
- Netty实现高性能RPC服务器优化篇之消息序列化
在本人写的前一篇文章中,谈及有关如何利用Netty开发实现,高性能RPC服务器的一些设计思路.设计原理,以及具体的实现方案(具体参见:谈谈如何使用Netty开发实现高性能的RPC服务器).在文章的最后 ...
随机推荐
- ps -aux与ps -ef
ps -aux与ps -ef这两个命令显示的结果是差不多的. 不同之处就是显示风格不同,前者是BSD风格,后者SYSTEM V(其实我不太明白这尼玛风格是什么跟什么,我看起来都差不多啊) 然后重要的不 ...
- P2858 [USACO06FEB]奶牛零食Treats for the Cows
P2858 [USACO06FEB]奶牛零食Treats for the Cows区间dp,级像矩阵取数, f[i][i+l]=max(f[i+1][i+l]+a[i]*(m-l),f[i][i+l- ...
- 高能天气——团队Scrum冲刺阶段-Day 3
高能天气--团队Scrum冲刺阶段-Day 3 今日完成任务 于欣月:完成天气预报部分收尾工作 余坤澎:进行特别关心的实现 康皓越:实现闹钟部分添加音乐 范雯琪:初步开始界面优化,寻找天气预报部分的背 ...
- ssh端口转发(之kettle ssh方式连接数据库)
ssh参数解释 格式 ssh [user@]host [command] 选项: -1:强制使用ssh协议版本1: -2:强制使用ssh协议版本2: -4:强制使用IPv4地址: -6:强制使用IP ...
- odoo国际化翻译
翻译功能简述 每个模块的翻译文件放在该模块目录下i18n目录里. 模块内相关字符串一般用英语写成,然后通过翻译模板导出功能,导出一个翻译模板po文件. 翻译人员使用翻译软件(poedit)进行翻译后, ...
- vue-video-player的使用总结
由于公司的项目是网上教育的,像网易云课堂那种教育网站,因而会有很多课程需要在线观看的,所以视频插件是必不可少的. 由于我用vue开发项目,所以找视频插件也找和vue贴近的.最后选择了vue-video ...
- AMD K7以来核心架构一览表
转载或拿走使用请注明出处,谢谢! 注:K10以前AMD的CPU型号主要用PR值标称,故此表中未表示其准确型号
- [Java]进程与线程的区别(转)
线程是指进程内的一个执行单元,也是进程内的可调度实体. 与进程的区别: (1)地址空间:进程内的一个执行单元;进程至少有一个线程;它们共享进程的地址空间;而进程有自己独立的地址空间; (2)资源拥有: ...
- phpexcel错误 You tried to set a sheet active by the out of bounds index: 1解决办法
$objPHPExcel->createSheet($k);
- 让IIS支持10万并发
适用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0 适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows ...