際際滷

際際滷Share a Scribd company logo
Netty4.x
asynchronous event-driven network application framework
蟾
http://gmind7.github.io
Java Software Developer
Contents
 ろ磯?
 企欧碁
 る覈
 螳覦蟲煙
 螳覦蟲
 螳覦ろ
ろ磯?
 螳旧螳
 蟲煙
 旧貉危
- 企欧碁
- 危殊
 覦 ろ語 危襴貅伎 
 觜蠍 企伎 企欧 蠍磯
 tomcat < 10,000 (connection) VS netty < 100,000 ~ 1,000,000 (connection)
 I/O 豌襴襯  豢 API 螻
 NIO, OIO, AIO 豌襴  所 所 覦蠖  蟆 Netty I/O API  螻
   企欧 覈瑚骸 る 覈 螻
  襷崎, 一危磯ゼ 覲企願 覦螻,    企 企欧瑚 覦讌 Netty螳   螻
  貊螳 企 る 語 ろ  讌, 覿 蠍壱 覦讌..焔 Netty螳   螻
 壱 企欧 豌襴  bi-directional chain of responsibility pattern
 讌 蟲 覯狩 伎 焔 伎 螻
 Buffer Zero-file-copy, Buffer Automatic Capacity Extession
ろ磯?
 蟲煙
- I/O 伎 (Netty), 襦貊 貊 (Netty or User), 觜讌る讌 (User)
Buffers
I/O Abstraction  Channels, Event Loops, and Pilelines
TCP UDP In-VM
Event Handlers
Codec Framework
HTTP
Custom EventHandlers & Codecs
Business Logic
Handler
Core
Transports
SSL SPDY
User Code
ろ磯?
 旧貉危(eventloop, pipeline)
eventloop (Windows event dispatcher, Swing event loop, Reactor)
Is Eventloop ?
(single thread)
tasks
User I/O
taskYES
NO
task
Queue
(Scheduling)
Execute
(pipeline call)
ろ磯?
 旧貉危(eventloop, pipeline)
pipeline (企欧碁 企欧碁ゼ 覦 碁る  )
eventloop 2
protocol
decoder
protocol
encoder
business
logic
3 4
  : 1 > 2 > 4
 ′ : 4 > 3 > 1
1
pipeline
(bi-directional chain of responsibility pattern)
* inbound event
- 企欧 襭螳 覦  企欧 (貅郁屋, 一危一 )襯 燕 inbound event handler蟆 
* outbound event
- 螳 豌  (郁鍵, 所鍵 殊譴 ) 燕 outbound event handler蟆 
- 豕譬朱 企欧 襭  I/O螳 襦 .
ろ磯?
 旧襦
ろ磯?
eventloop
1 2
pipeline context
3 4
handler
1 1 1 n 1 n
企欧
覈
 蠍一ヾ 企欧 覈
  企欧 覈
 蠍一ヾ 企欧 覈 (螳豌危語)
企欧碁
  企欧 覈 (覃語)
Channel DisConnectedChannel UnboundChannel Closed
Message Event(in,out)
Channel ConnectedChannel boundChannel Open
Flush (Messag Event豌)Channel InActiveChannel Unregistered
InboundBufferUpdatedChannel ActiveChannel Registered
覯殊 一危磯ゼ  豈 
Flush 豌 れ I/O
旧螳レ
旧覿螳
* UserEventTriggered 覃 豢螳
る覈
 企欧 襭  炎 る襦 ろ 伎
 觜蠍 豌  蟆郁骸 給慨 企欧 襭 る 企伎
 碁る 覃襯 語  螳 語 伎 happens-before 蟯螻 焔
 @Sharable 螳 覿 讌  蟆曙 碁る 覃襯  語 讌 
る覈
eventloop
(single thread) pipeline handler
method
method
happens-before
volatile ()
ChannelFuture<T> handler  語(X)
螳覦
蟲煙
 旧貉危
 企るれ伎願係
 API れ 蟲
 覦危碁
 Bootstrap
 Bootstrap : Client-side Channel襯   譯手 襦 郁屋   Helper Class
 ServerBootstrap : Server-side Channel襯   譯手 襦 郁屋   Helper Class
覿覈豈 郁屋 覦譯手, 炎概朱 bound 伎 client郁屋 豈
 EventLoop
EventLoop : SingleThread Channel Seletor (OioEventLoop, Nio, Epoll..)
EventLoopGroup : MultiThread Channel Seletor (OioEvnetLoopGroup, Nio, Epoll)
 Channel
NioSocketChannel, OioSocketChannel, EpollSocketChannel
NioServerSocketChannel, OioServerSocketChannel, EpollServerSocketChannel
 ChannelOption
SO_KEEPALIVE, SO_SNDBUF, SO_RCVBUF, SO_TIMEOUT, SO_BACKLOG.
 ChannelFuture
 Channel I/O Operations 襭   蟆郁骸襯 覦   Future 螳豌
螳覦蟲煙 (旧貉危)
 ChannelHandler
 InboundHandler, OutBoundHandler 讌
 Channel I/O Operations Event 豌襴襯  Handler Method襯 讌
 ByteBuf (dynamic buffer)
 UnPooledDirectByteBuf, UnPooledHeapByteBuf, UnPooledUnsafeDirectByteBuf,
PooledDirectByteBuf, PooledHeapByteBuf, PooledUnsafeDirectByteBuf,
CompositeByteBuf.
螳覦蟲煙 (旧貉危)
 EventLoop And EventExecutor
螳覦蟲煙 (企るれ伎願係)
 NIO,OIO Channel
螳覦蟲煙 (企るれ伎願係)
 Bytebuf
螳覦蟲煙 (企るれ伎願係)
螳覦蟲煙 (API れ蟲譟)
螳覦蟲
 ChannelHandler (event, codec)
 Client Run (bootstrap)
 Server Run (ServerBootstrap)
 Bytebuf
 ChannelHandler (event)
Flush
Channel InActive
Channel Unregistered
InboundBufferUpdated
Channel Active
Channel Registered
螳覦蟲
 ChannelHandler (decoder, encoder)
螳覦蟲
 Client Run
螳覦蟲
 Sever Run
螳覦蟲
 Bytebuf
螳覦蟲
 Bytebuf
螳覦蟲
ろ  EmbeddedChannel
 EmbeddedChannel
螳覦ろ
Reference Site
 http://deview.kr/2012/xe/index.php?mid=track&document_srl=379&time_srl=276
 http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html
 http://www.youtube.com/watch?v=_GRIyCMNGGI
 http://hongweiyi.com/2014/01/

More Related Content

Netty4.x

  • 1. Netty4.x asynchronous event-driven network application framework 蟾 http://gmind7.github.io Java Software Developer
  • 2. Contents ろ磯? 企欧碁 る覈 螳覦蟲煙 螳覦蟲 螳覦ろ
  • 3. ろ磯? 螳旧螳 蟲煙 旧貉危 - 企欧碁 - 危殊
  • 4. 覦 ろ語 危襴貅伎 觜蠍 企伎 企欧 蠍磯 tomcat < 10,000 (connection) VS netty < 100,000 ~ 1,000,000 (connection) I/O 豌襴襯 豢 API 螻 NIO, OIO, AIO 豌襴 所 所 覦蠖 蟆 Netty I/O API 螻 企欧 覈瑚骸 る 覈 螻 襷崎, 一危磯ゼ 覲企願 覦螻, 企 企欧瑚 覦讌 Netty螳 螻 貊螳 企 る 語 ろ 讌, 覿 蠍壱 覦讌..焔 Netty螳 螻 壱 企欧 豌襴 bi-directional chain of responsibility pattern 讌 蟲 覯狩 伎 焔 伎 螻 Buffer Zero-file-copy, Buffer Automatic Capacity Extession ろ磯?
  • 5. 蟲煙 - I/O 伎 (Netty), 襦貊 貊 (Netty or User), 觜讌る讌 (User) Buffers I/O Abstraction Channels, Event Loops, and Pilelines TCP UDP In-VM Event Handlers Codec Framework HTTP Custom EventHandlers & Codecs Business Logic Handler Core Transports SSL SPDY User Code ろ磯?
  • 6. 旧貉危(eventloop, pipeline) eventloop (Windows event dispatcher, Swing event loop, Reactor) Is Eventloop ? (single thread) tasks User I/O taskYES NO task Queue (Scheduling) Execute (pipeline call) ろ磯?
  • 7. 旧貉危(eventloop, pipeline) pipeline (企欧碁 企欧碁ゼ 覦 碁る ) eventloop 2 protocol decoder protocol encoder business logic 3 4 : 1 > 2 > 4 ′ : 4 > 3 > 1 1 pipeline (bi-directional chain of responsibility pattern) * inbound event - 企欧 襭螳 覦 企欧 (貅郁屋, 一危一 )襯 燕 inbound event handler蟆 * outbound event - 螳 豌 (郁鍵, 所鍵 殊譴 ) 燕 outbound event handler蟆 - 豕譬朱 企欧 襭 I/O螳 襦 . ろ磯?
  • 8. 旧襦 ろ磯? eventloop 1 2 pipeline context 3 4 handler 1 1 1 n 1 n
  • 10. 蠍一ヾ 企欧 覈 (螳豌危語) 企欧碁 企欧 覈 (覃語) Channel DisConnectedChannel UnboundChannel Closed Message Event(in,out) Channel ConnectedChannel boundChannel Open Flush (Messag Event豌)Channel InActiveChannel Unregistered InboundBufferUpdatedChannel ActiveChannel Registered 覯殊 一危磯ゼ 豈 Flush 豌 れ I/O 旧螳レ 旧覿螳 * UserEventTriggered 覃 豢螳
  • 12. 企欧 襭 炎 る襦 ろ 伎 觜蠍 豌 蟆郁骸 給慨 企欧 襭 る 企伎 碁る 覃襯 語 螳 語 伎 happens-before 蟯螻 焔 @Sharable 螳 覿 讌 蟆曙 碁る 覃襯 語 讌 る覈 eventloop (single thread) pipeline handler method method happens-before volatile () ChannelFuture<T> handler 語(X)
  • 14. Bootstrap Bootstrap : Client-side Channel襯 譯手 襦 郁屋 Helper Class ServerBootstrap : Server-side Channel襯 譯手 襦 郁屋 Helper Class 覿覈豈 郁屋 覦譯手, 炎概朱 bound 伎 client郁屋 豈 EventLoop EventLoop : SingleThread Channel Seletor (OioEventLoop, Nio, Epoll..) EventLoopGroup : MultiThread Channel Seletor (OioEvnetLoopGroup, Nio, Epoll) Channel NioSocketChannel, OioSocketChannel, EpollSocketChannel NioServerSocketChannel, OioServerSocketChannel, EpollServerSocketChannel ChannelOption SO_KEEPALIVE, SO_SNDBUF, SO_RCVBUF, SO_TIMEOUT, SO_BACKLOG. ChannelFuture Channel I/O Operations 襭 蟆郁骸襯 覦 Future 螳豌 螳覦蟲煙 (旧貉危)
  • 15. ChannelHandler InboundHandler, OutBoundHandler 讌 Channel I/O Operations Event 豌襴襯 Handler Method襯 讌 ByteBuf (dynamic buffer) UnPooledDirectByteBuf, UnPooledHeapByteBuf, UnPooledUnsafeDirectByteBuf, PooledDirectByteBuf, PooledHeapByteBuf, PooledUnsafeDirectByteBuf, CompositeByteBuf. 螳覦蟲煙 (旧貉危)
  • 16. EventLoop And EventExecutor 螳覦蟲煙 (企るれ伎願係)
  • 17. NIO,OIO Channel 螳覦蟲煙 (企るれ伎願係)
  • 20. 螳覦蟲 ChannelHandler (event, codec) Client Run (bootstrap) Server Run (ServerBootstrap) Bytebuf
  • 21. ChannelHandler (event) Flush Channel InActive Channel Unregistered InboundBufferUpdated Channel Active Channel Registered 螳覦蟲
  • 22. ChannelHandler (decoder, encoder) 螳覦蟲
  • 29. Reference Site http://deview.kr/2012/xe/index.php?mid=track&document_srl=379&time_srl=276 http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html http://www.youtube.com/watch?v=_GRIyCMNGGI http://hongweiyi.com/2014/01/