Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Netty로 소켓 통신 개발
전통적인 소켓 통신 프로그래밍
Java에서 구현시
이러한 구현 방식은?
• Blocking IO 방식
• "Blocking" means that the caller waits until
the callee finishes its processing. For
instanc...
요즘의 주된 방식은?
Non blocking IO & Async
multiplexing i/o
Non blocking socket 종류
• select
• poll
• epoll
• iocp
자바에서의 NIO
• Channel
• SocketChannel
• SelectableChannel
• ServerSocketChannel
Asynchronous I/O
• AsynchronousChannel
• AsynchronousSocketChannel
• AsynchronousServerSocketChannel
• AsynchronousFileCha...
Netty?
• Java Network framework
• Asynchronous & event driven
• Well defined event model & thread Model
• JDK 1.5 dependenc...
Feature
• Asynchronous!
• Simple and unified API!
• High-Performing!
• Listeners and Callbacks supported!
• Zero-file-copy!
...
Netty 구조
Support Protocol
• TCP
• UDP
• SCTP
• Serial
• …
© http://www.flickr.com/photos/bdesham/2432400623/
ChannelHandler
Network
BootStrap
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
ChannelPipeLine
!
!
!
!
!
!
!
!
!
!
!
!Decoder/Encoder
ReplayDecoder
Chann...
ChannelHandler
• Thread safe
• EventExecutor에 의해서 호출된
• InBound & OutBind Handler 가 존재함
• User는 Handler만 추가해서 Business log...
기본 제공 Handler
• IdleEventHandler
• StringDecoder/StringEncoder
• ReplayDecoder
• ….
일반적으로는 SimpleChannelInboundHandler 만 사...
ChannelHandlerAdapter
http://www.flickr.com/photos/rickz/2113212191/
ChannelPipeLine
ChannelPipeline
• linux에서 사용하는 Pipe명령과 동일한 구조
• 모든 이벤트는 이것을 통해서 이동함.
• Channel과 ChannelPipeline은 1:1 매핑되어 있음.
Event-loop
• Reactor pattern이라고 함
• single thread 에 event를 등록하고 발생하는 이벤트를 디스
패치 하는 패턴
• 이런 패턴을 적용한 애플리케이션
• IOS
• GNOME
• ...
Event-loop in Netty
• One-to-Many relation between EventLoop and Channel
• Process "events" and hand over work to the
Chan...
Eventloop 작동방식
DATA CONTAINER
http://normanmaurer.me/presentations/2013-wjax-netty/images/containers.jpg
“ByteBuf == ByteBuffer on steroi...
ByteBuf
• Separate index for reader/writer
• CompositeByteBuf
• Direct and Heap implementations
• Resizable with max capac...
ByteBufferAllocator
https://blog.twitter.com/2013/netty-4-at-twitter-reduced-gc-overhead
Echo Server Demo
Q & A
참고자료
• http://normanmaurer.me/presentations/2013-
wjax-netty
• http://www.ibm.com/developerworks/library/j-
zerocopy/
• ht...
Netty
Netty
Netty
Netty
Netty
Netty
Netty
Netty
Upcoming SlideShare
Loading in …5
×

Netty

3,303 views

Published on

netty

Published in: Engineering
  • Be the first to comment

Netty

  1. 1. Netty로 소켓 통신 개발
  2. 2. 전통적인 소켓 통신 프로그래밍
  3. 3. Java에서 구현시
  4. 4. 이러한 구현 방식은? • Blocking IO 방식 • "Blocking" means that the caller waits until the callee finishes its processing. For instance, a "blocking read" from a socket waits until there is data to return; a "non- blocking" read does not, it just returns an indication (usually a count) of whether there was something read
  5. 5. 요즘의 주된 방식은? Non blocking IO & Async
  6. 6. multiplexing i/o
  7. 7. Non blocking socket 종류 • select • poll • epoll • iocp
  8. 8. 자바에서의 NIO • Channel • SocketChannel • SelectableChannel • ServerSocketChannel
  9. 9. Asynchronous I/O • AsynchronousChannel • AsynchronousSocketChannel • AsynchronousServerSocketChannel • AsynchronousFileChannel
  10. 10. Netty? • Java Network framework • Asynchronous & event driven • Well defined event model & thread Model • JDK 1.5 dependency free
  11. 11. Feature • Asynchronous! • Simple and unified API! • High-Performing! • Listeners and Callbacks supported! • Zero-file-copy! • Buffer Pooling! • Gathering / Scattering • ... and many more
  12. 12. Netty 구조
  13. 13. Support Protocol • TCP • UDP • SCTP • Serial • …
  14. 14. © http://www.flickr.com/photos/bdesham/2432400623/ ChannelHandler
  15. 15. Network BootStrap ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ChannelPipeLine ! ! ! ! ! ! ! ! ! ! ! !Decoder/Encoder ReplayDecoder ChannelHandler : : ChannelHandler 구조 ByteBuf
  16. 16. ChannelHandler • Thread safe • EventExecutor에 의해서 호출된 • InBound & OutBind Handler 가 존재함 • User는 Handler만 추가해서 Business login 구현가 능
  17. 17. 기본 제공 Handler • IdleEventHandler • StringDecoder/StringEncoder • ReplayDecoder • …. 일반적으로는 SimpleChannelInboundHandler 만 사용해도 가능
  18. 18. ChannelHandlerAdapter
  19. 19. http://www.flickr.com/photos/rickz/2113212191/ ChannelPipeLine
  20. 20. ChannelPipeline • linux에서 사용하는 Pipe명령과 동일한 구조 • 모든 이벤트는 이것을 통해서 이동함. • Channel과 ChannelPipeline은 1:1 매핑되어 있음.
  21. 21. Event-loop • Reactor pattern이라고 함 • single thread 에 event를 등록하고 발생하는 이벤트를 디스 패치 하는 패턴 • 이런 패턴을 적용한 애플리케이션 • IOS • GNOME • Winmain
  22. 22. Event-loop in Netty • One-to-Many relation between EventLoop and Channel • Process "events" and hand over work to the ChannelPipeline • All tasks executed in Eventloop • Eventloop로 업무나 추가처리를 할 수 있음 • synchronization 처리 필요없음 • blocking 안됨
  23. 23. Eventloop 작동방식
  24. 24. DATA CONTAINER http://normanmaurer.me/presentations/2013-wjax-netty/images/containers.jpg “ByteBuf == ByteBuffer on steroids!”
  25. 25. ByteBuf • Separate index for reader/writer • CompositeByteBuf • Direct and Heap implementations • Resizable with max capacity • Support for reference-counting • Method-Chaining
  26. 26. ByteBufferAllocator https://blog.twitter.com/2013/netty-4-at-twitter-reduced-gc-overhead
  27. 27. Echo Server Demo
  28. 28. Q & A
  29. 29. 참고자료 • http://normanmaurer.me/presentations/2013- wjax-netty • http://www.ibm.com/developerworks/library/j- zerocopy/ • http://netty.io

×