Ծ֧ǵĹҵ

10Ԫ 50Ԫ





֤룺  ֤,?ˢ֤



  Ҫ Ŀ Lib Ƶ Code iProcess γ ֤ ѯ   ɳ֮·  
Ա   
 
   
 
  
ÿ15ƪ
ı
׷
 
 
     
   
 
 
һƪ£Nettyĸܼܹ֮
 
ߣַ Դ:ļܹ ڣ2016-10-18
891     ۣ      
 

Nettyһܡ첽¼NIOܣṩ˶TCPUDPļ֧֣Ϊһ첽NIOܣNettyIO첽ģͨFuture-ListenerƣûԷȡ֪ͨͨƻIO

ΪǰеNIOܣNettyڻ򡢴ݷֲʽϷҵͨҵȻ˹㷺ӦãһЩҵĿԴҲNettyNIOܹ

ΪʲôѡNetty

NettyҵеNIO֮һĽ׳ԡܡܡɶԺͿչͬжһָģѾõɰǧĿ֤HadoopRPCavroʹNettyΪײͨſܣܶҵRPCܣҲʹNettyܵ첽ͨ

ͨNettyķǽŵܽ:

1.APIʹü򵥣żͣ

2.ǿԤ˶ֱ빦ܣֶ֧Э飻

3.ǿͨChannelHandlerͨſܽչ

4.ܸߣͨҵNIOܶԱȣNettyۺţ

5.졢ȶNetty޸ѾֵJDK NIO BUGҵ񿪷ԱҪΪNIOBUGգ

6.Ծ汾ڶֵ̣BUGԱʱ޸ͬʱ¹ܻ룻

˴ģҵӦÿ飬õ֤ڻݡϷҵӦáڶҵõɹã֤Ѿȫܹ㲻ͬҵҵӦˡ

Nettyܹ

Netty ˱Ƚϵ͵ܹƣ߼ܹͼʾ

һ㣺Reactor ͨŵȲ㣬һϵиɣ Reactor ߳ NioEventLoop Լ丸ࡢNioSocketChannel/NioServerSocketChannel Լ丸 ࡢByteBuffer Լĸ BufferUnsafe Լĸ ȡòҪְǼĶдӲ ȡڴ滺УȻ󴥷¼ӴӼ д¼ȵȣЩ¼ PipeLine У PipeLine 䵱ְ кĴ

ڶ㣺ְ PipeLine¼ְе򴫲ͬʱ̬ ְְѡʹԼĵ¼ش /ǰ¼ͬӦõ Handler ڵĹҲͬͨ£ Ὺ Hanlder Ϣı룬ԽⲿЭϢתڲ POJO ϲҵֻҪĴҵ߼ɣҪ֪ײ Э߳ģͲ죬ʵ˼ܹķֲ롣

㣺ҵ߼㣬ԷΪࣺ

1.ҵ߼ 綩

2.ӦòЭHTTPЭ顢FTPЭȡ

ҴӰͨܵ棨I/Oģ̵߳͡ģ͡лʽ̸̸Nettyļܹ

I/Oģ

ͳͬI/Oģʽͼʾ

ı׶кࣺܶ

1.⣺һһ߳ģ͵·˵IJϵͳܵƣ

2.ɿ⣺I/OͬģʽӵͨŶԶ˴ᵼI/O̱߳סʱ޷Ԥ⣻

3.ά⣺I/O߳޷ЧơԴ޷Ч̲߳⣩ϵͳάԲ

I/Oģ͵ĹܺԶԱȣ

NettyI/OģͻڷI/Oʵ֣ײJDK NIOܵSelector

SelectorṩѡѾSelector᲻ϵѯעϵChannelijChannelµTCPӽ롢д¼Channelʹھ״̬ᱻSelectorѯȻͨSelectionKeyԻȡChannelļϣкI/O

һ·SelectorͬʱѯChannelJDK1.5_update10汾+ʹepoll()洫ͳselectʵ֣ûӾ1024/2048ơҲζֻҪһ̸߳SelectorѯͿԽǧĿͻˣȷʵǸdz޴ļ

ʹ÷I/Oģ֮Netty˴ͳͬI/OܡͿɿ⡣

̵߳ģ

õReactor߳ģֱ֣£

1.Reactor߳ģͣReactor߳ģָͣеI/OͬһNIO߳ɡһЩСӦóʹõ߳ģ͡

2.Reactor߳ģͣRector߳ģ뵥߳ģһNIO̴߳I/OҪڸ߲ҵ

3.Reactor߳ģͣReactor߳ģ͵صǷڽտͻӵIJǸ1NIỌ߳һNIO̳߳ءNIO߳ģͣԽ1˼߳޷Чпͻӵܲ⡣

ʵϣNetty߳ģͲǹ̶䣬ͨдͬEventLoopGroupʵͨʵIJãͿ֧Reactor߳ģ͡

ڴ£ж̴߳ϵͳIJܡǣڹԴIJʴصջᵼܵ½Ϊ˾ܵıģͨлƣϢĴͬһ߳ɣڼ䲻߳лͱ˶߳̾ͬ

Ϊ˾ܣNetty˴ƣI/O߳ڲдв߳̾µ½ϿлƺCPUʲߣ̶ȲǣͨNIO̳߳ص̲߳ͬʱл̲߳У־ֲĴ߳һ-߳ģܸš

лʽ

ӰлܵĹؼܽ£

1.лСռã

2.л&лܣCPUԴռã

3.õܱ֣ȶԡżֵʱë̵

JavaлͶƱֱܲԣ100ΣԽJavaлֻжƱ6.17%ҡ

NettyĬṩ˶Google Protobuf֧֣ͨչNettyıӿڣûʵĸлܣThriftѹƱܡ

ͬӦóлܵҲͬڸӦóNettyĬṩGoogleProtobufлܣûлҲԻNettyṩıչʵ֡

Nettyܹ֮ɿ

NettyٵĿɿս

1.ΪRPCܵĻͨſܣһϽ޷Զ̷񣨽ӿڣá

2.ΪӦòЭĻͨſܣһϽӦЭջ޷

3.绷ӣλͷGSM/3G/WIFI磩ϲɱ⣬ҵȴжϡ

ӦóNettyǻͨſܣһBugҪӦãܵҵжϡĿɿԻӰҵȺͨźͽڵԷֲʽΪܹϵУͨжϾζҵжϣֲʽܹ¶ͨŵĿɿҪdzߡ

лNettyٶӵ绷ҪĿɿҪ㹻ãƽ̨ܹĿɿҪNettyᵼϲûעĵײϣ⽫NettyԣͬʱûĿάɱ

NettyĿɿҪκι϶ܻᵼҵжϣܾ޴ľʧˣNettyڰ汾ĵвϼµĿɿûĸ߿ɿͽ׳

·ЧԼ

NettyṩƷΪ֣

1.У·ʱtûжȡκϢ

2.дУ·ʱtûзκϢ

3.дУ·ʱtûнջ߷κϢ

緢ͨӱǽHangסʱGC̷ͨ߳Ԥ쳣ʱᵼ·Ҳױʱ֡ر쳣賿ҵ͹ڼ䣬糿ҵ߷ڵʱ·ûᵼ˲Ĵҵʧܻ߳ʱ⽫ϵͳĿɿԲشв

Ӽ濴Ҫ·Ŀɿ⣬ԵĶ·ЧԼ⡣Ŀǰкͨõ⡣

ƷΪ棺

1.TCP⣬TCPKeep-AliveƣTCPЭջ

2.Э⣬ҪڳЭСSMPPЭ飻

3.Ӧò⣬ҪɸҵƷͨԼʽʱԷϢʵ֡

Ŀľȷϵǰ·ãԷŲܹպͷϢΪ߿ɿNIOܣNettyҲṩ˻·еƣ

1.У·ʱtûжȡκϢ

2.дУ·ʱtûзκϢ

3.дУ·ʱtûнջ߷κϢ

ΣTraffic ShapingһʵĴʩNettyã

1.ֹԪܲ⵼Ԫѹ壬ҵжϣ

2.ֹͨģϢ죬ҵ̴߳ʱµġ⡣

εԭʾͼ£

ΣTraffic ShapingһʵĴʩһӦǻTPָƱܵҪڣζҪıĽл桪ͨǽǷ뻺ڣҲΣTraffic ShapingTSͰ㹻ʱپȵⷢЩıġܵһǣοܻӳ٣ܼӳ١

Netty֧ģʽ

1.ȫΣȫε÷Χǽ̼ģ㴴˶ٸChannelеChannelûͨãĵĽʡĵķʡڡ

2.·Σ·ȫεԵ·Ϊ򣬿ԶԲͬ·òͬβԡ

ͣ

Nettyͣ

1.ٽϢ

2.˳ǰԤ

3.ԴͷŲ

JavaͣͨͨעJDKShutdownHookʵ֣ϵͳյ˳ָȱϵͳ˳״̬ٽµϢȻ󽫻ѹϢ꣬ԴսӿڽԴ٣߳˳ִС

ͨ˳Ҫгʱƻƣ30SﳬʱʱȻû˳ǰԴյȲͣűֱӵkill -9 pidǿ˳

ʵĿУNettyΪܵ첽NIOͨſܣͨſܸЭĽ롢͵ȵȣRPCͷֲʽУʹNettyΪڲ˽ЭĻͨſܡ Ӧý˳ʱΪͨſܵNettyҲҪ˳Ҫԭ£

ͷNIO̡߳Դ

ʹflushϢͣҪڷͶеĴϢɣ

writereadϢҪ

NioEventLoop̵߳еĶʱҪִл

Nettyܹ֮ȫ

Nettyٵİȫս

Ե

ΪӦòЭĻͨſ

ȫв

ԵŵͨſܣʹNettyRPCܻ˽ЭջRPCŵĵţ罫ڲһЩͨ⿪ųȥʱҪаȫ֤ŵǹIPڰȫҪdzߵһЩ֧ȣҪͨSSL/TLSͨš

ӦòЭİȫԡΪܡ첽¼NIOܣNettydzʺϹϲӦòЭ顣ھӦòЭ鶼ǹеģζŵײNettyҪϲṩͨŲİȫ书ܡ

SSL/TLS

Nettyȫԣ

1.֧SSL V2V3

2.֧TLS

3.֧SSL֤˫֤͵CA֤

SSL֤ͼ£

NettyͨSslHandlerṩ˶SSLֵ֧֣֧SSLЭͰSSL V2SSL V3TLS

֤֤ͻֻ֤˵ĺϷԣ˲֤ͻˡ

˫֤뵥֤ͬǷҲҪԿͻ˽аȫ֤ζſͻ˵ǩ֤ҲҪ뵽˵ֿ֤С

CA֤ǩSSL˫ֻ֤Ҫͻ˻߷޸Կ֤飬Ҫ½ǩ֤齻ֵԺάǷdzġˣʵʵϵͳʹõCA֤䷢ǩ֤ǵͱ˼õCA_ROOTÿӵվʱֻҪվ֤ǾЩCA_ROOTǩġͿ֤ͨˡ

չİȫ

ͨNettyչԣԶ尲ȫԣ

1.IPַ

2.֤

3.Ϣܻ߹˻

IPַDZȽϳõȫԣصǷͻͨŵĹУԿͻ˵IPַУ飬ֶԷIPںбУܾͨţر·

֤Էdz࣬ͨǽǿİȫ֤ԣû+֤֤üܵķʽBase64+AESȡ

Nettyܹ֮չ

ͨNettyչԣԶ尲ȫԣ

1.߳ģͿչ

2.лʽչ

3.ϲЭջչ

4.ṩ¼棬ûչ

Nettyļܹչ£

5.жչ㣬Ԥչӿڣûζƺչʹã

6.Ҫܵ㶼ڽӿڱ̣ûƺչ

ʴ

ʣ֮ǰ˽⵽JavaNIO selectorײWindowsµʵ˿ڻӻд¼LinuxùܵʵֵģҪռú̶ܶ˿ˣWindows£NIOܣMinaNettyпܻɶ˿ڳͻʲôõĽ

˵ȷʵڣLinuxʹPipeʵWindowsҪ˿ڡĿǰûиõİ취ķʽΪ˵Ķ˿ڿԹ滮һΧȻݽڵͽϢ̬ɣֶ˿ڳͻڹ滮Χڻ㷨һµĶ˿ڡ

ʣңڽSpringNettyϣʹSpringService Nettỵֹ߳ͣʱNettyTCP Server˿ڲͷţ˳ʱʲôõİ취ͷNetty Server˿ô

ʵϣ˭Netty ̲߳ҪҪľǵӦ˳ʱSpring Context٣˳֮ǰNetty ˳ӿڼʵֶ˿ڡNIO߳Դͷšοƪ£http://www.infoq.com/cn/articles/netty-elegant-exit-mechanism-and-principles

ʣʺNettyдWebͨô?

NettyWebܣ޷JSPHTMLJSȣWeb ͨţʹNettyдTomcatHTTP/HTTPS ͨЭջ

ʣܲܽһNettyĴƣڴкͲдﵽţ

Ϊ˾ܣNetty˴ƣIO߳ڲдв߳̾µ½ϿлƺCPUʲߣ̶ȲǣͨNIO̳߳ص̲߳ͬʱл̲߳У־ֲĴ߳һ-߳ģܸšNettyNioEventLoopȡϢֱ֮ӵChannelPipelinefireChannelRead(Object msg)ֻҪûл̣߳һֱNioEventLoopõûHandlerڼ䲻߳лִлʽ˶̲߳µľܽǶȿŵġ

   
 
 

谭ʹҵܹԭ򼰿˷
缶ҵܹҵս
ҵܹSOAܹĽɫں
ʲôʺ֯
ĵ

ҵܹITIL
ҵܹ
Zachmanҵܹܼ
ҵܹSOA
ؿγ

ҵܹ
ܹʵ
Ƕʽܹơ߼ʵ
ҵSOAܹʵ
 

רӽǿITܹ
ܹ
ϵܹҵ
ƶܹ
ܹ֮
̸ƽ̨PaaS
 ...   

Ӧõļܹʵ
Ԫ+ع+ģʽ
ܹʦ߼ʵ
ܹƷʵ
Ƕʽܹơ߼ʵ
SOAϵṹʵ
γ...   

ѯ
Ӧüܹ빹
ѯ...   

񰲿Ƽ ܹƷ
ɶ Ƕʽܹ
Ϻ Ƕʽܹ
ܹ
Ϻ ܹưʵ
ܹƷʵ
ܹƷʵ
Ƕʽܹơ߼ʵ
...   
 
 
ʵ¼ C
α
Linux豸⡷
 
ʵ¼ Tensorflowѧϰ
Ǯ˻
뼯Ŵƽ̨ܹʦ
 
 
 
ÿ2ĵ/Ƶ
ɨ΢Ŷά붩
ļ¿
ÿ300Դ
 
 

| ϵ | ICP10020922 110108001071