netty源码学习-课堂5
2012-11-22 21:53
363 查看
要学的东西,还很多,例如:
1)详细写过程write
2)bytebuffer设计
3)upstream/downstream各种设计与handler维护
4)各种协议,大架子
喘口气,我们不可能一口气吃下个胖子哈,那么好,我们书接上回,谈谈这详细的写过程。
在写的时候,channel的getInterestOps(),会根据目前的“写情况”来自动更新OP_WRITE相关的interestops,换句话说,OP_WRITE完全由netty自己get/set,业务层无法显式set的。前面刚提到,根据目前的“写情况”,那究竟如何标识写情况呢,我们不得不拎出这两个变量来打量一番。关于highwatermark和lowwatermark这两个变量:
1)详细写过程write
2)bytebuffer设计
3)upstream/downstream各种设计与handler维护
4)各种协议,大架子
喘口气,我们不可能一口气吃下个胖子哈,那么好,我们书接上回,谈谈这详细的写过程。
在写的时候,channel的getInterestOps(),会根据目前的“写情况”来自动更新OP_WRITE相关的interestops,换句话说,OP_WRITE完全由netty自己get/set,业务层无法显式set的。前面刚提到,根据目前的“写情况”,那究竟如何标识写情况呢,我们不得不拎出这两个变量来打量一番。关于highwatermark和lowwatermark这两个变量:
"low"watermarkindicatedthesafelevel,thatwhentheamountofbytesqueuedtobesentwentunderthisvaluewriting couldresume(isWriteable()=true).
"high"watermarkwouldindicatethedangerlevel,thanwhentheamountofbytesqueuedtobesentwentoverthisvaluethenwritingshouldstop(isWriteable()=false).Thedocumentationsaystheinverseofthis.
>1.Ifwehadpreviouslyexceededthehighwatermark(counter>0)and
>wearestillabovethelowwatermark,writeremainsdisabled.
>2.Ifwehadpreviouslyexceededthehighwatermark(counter>0)and
>wearenowbelowthelowwatermark,writeisenabled.
>3.Ifwewerebeneaththehighwatermark(counter<=0)andweare
>stillbelowthehighwatermark,writeremainsenabled.
>4.Ifwewerebeneaththehighwatermark(counter<=0)andwearenow
>abovethehighwatermark,writeisdisabled.
也就是说,
【安全】low水位以下,isWriteable=true可以往外写
【不安全】high水位以上,isWritable=false只能排队
[b][b]1.【不安全】如果危险系数比较低(counter<=0),[b]且目前写任务的个数>高水位,那么只能排队;容易理解[/b][/b][/b]
2.【安全】如果危险系数比较高(counter>0),[b]且目前写任务的个数<低水位,那么可以往外[/b]写;容易理解
3.【不安全】如果危险系数比较高(counter>0),且目前写任务的个数>低水位,那么只能[b]排队; 容易理解[/b]
4.【安全】如果危险系数比较低(counter<=0),[b]且目前写任务的个数<高水位,那么可以往外写;容易理解
[/b]
那详细的写过程,又是什么样子的呢?nioworker怎么就把数据写到socket里了?遭遇超超大数据会怎样?我们一起来看。
.........................................TOBECONTINUED超超大数据基于流来写?
附录:
channel的interestops,究竟应该如何理解呢?
InterestOps
AhasapropertycalledChannel
whichissimilartothatofinterestOps
.ItisrepresentedasaNIOSelectionKey
-Ifset,amessagesentbyaremotepeerwillbereadimmediately.Ifunset,themessagefromtheremotepeerwillnotbereaduntiltheOP_READ
flagissetagain(i.e.readsuspension).OP_READ
-Ifset,awriterequestwillnotbesenttoaremotepeeruntiltheOP_WRITE
flagisclearedandthewriterequestwillbependinginaqueue.Ifunset,thewriterequestwillbeflushedoutassoonaspossiblefromthequeue.OP_WRITE
-ThisisacombinationofOP_READ_WRITE
andOP_READ
,whichmeansonlywriterequestsaresuspended.OP_WRITE
-Thisisacombinationof(NOTOP_NONE
)and(NOTOP_READ
),whichmeansonlyreadoperationissuspended.OP_WRITE
Youcansetorclearthe
flagtosuspendandresumereadoperationviaOP_READ
.setReadable(boolean)
Pleasenotethatyoucannotsuspendorresumewriteoperationjustlikeyoucansetorclear
.TheOP_READ
flagisreadonlyandprovidedsimplyasameantotellyouifthesizeofpendingwriterequestsexceededacertainthresholdornotsothatyoudon'tissuetoomanypendingwritesthatleadtoanOP_WRITE
.Forexample,theNIOsockettransportusestheOutOfMemoryError
writeBufferLowWaterMarkand
writeBufferHighWaterMarkpropertiesin
todeterminewhentosetorcleartheNioSocketChannelConfig
flag.OP_WRITE
相关文章推荐
- netty源码学习—课堂3
- netty源码学习—课堂1
- netty源码学习—课堂2
- netty源码学习—课堂4
- 【Netty源码学习】EventLoopGroup
- (二)Netty源码学习笔记之服务端启动
- 一起学Netty(十九)netty源码学习之netty server端源码初读(下)
- netty源码学习第三章:ByteBuf
- Netty源码学习(四)Netty服务器是如何启动的?
- Netty学习之旅------再谈线程模型之源码分析NioEventLoopGroup、SingleThreadEventExecutor
- (一)Netty源码学习笔记之概念解读
- Netty学习之旅------源码分析Netty内存池分配机制初探--PoolArena、PoolChunk、PoolSubpage等数据结构分析
- NETTY源码学习-DELIMITERBASEDFRAMEDECODER
- Netty学习之旅------源码分析Netty线程本地分配机制与PooledByteBuf线程级对象池原理分析
- Netty源码学习(二)NioEventLoopGroup
- 【转】Netty源码的阅读学习
- Netty 之 netty源码学习之netty server端源码初读(上)
- Netty源码学习(六)ChannelPipeline
- Netty学习之旅----ByteBuf源码解读之初探UnpooledHeapByteBuf、UnpooledDirectByteBuf
- Netty源码学习-ServerBootstrap启动及事件处理过程