SlideShare a Scribd company logo
1 of 34
Download to read offline
Zero-Copy Event-Driven
   Servers with Netty



               Daniel Bimschas
Institute of Telematics, University of Lübeck
       http://www.itm.uni-luebeck.de



                                                1
Content
•  Basics
   –  Zero-Copy Techniques
   –  Event-Driven Architectures
•  Introduction to Netty
   –  Buffers
   –  Codecs
   –  Pipelines & Handlers
•  Netty Examples
   –  Discard
   –  HTTP Server

                                   2
Zero-Copy Techniques




                       3
Traditional Approach
      •  copying and context switches between kernel
         and user space à poor performance!


                                                                           Socket
                                     Read Buffer                                                                   NIC Buffer
      Fast                                                                 Buffer

     Slow                                                                                                                        Kernel Context
                                                                                                                    Application Context


                                                          Application
                                             App            Buffer


Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany                    4
Zero-Copy Approach
      •  Kernel handles the copy process via Direct Memory Access (DMA)
              –  No CPU load
              –  Lower load on bus system
              –  No copying between kernelspace and userspace




                                                                           Socket
                                     Read Buffer                                                                   NIC Buffer
      Fast                                                                 Buffer

                                                                                                                                 Kernel Context
                Perfect!
                                                                Task                                                Application Context


                                                          Application
                                             App            Buffer


Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany                    5
Simple Benchmark: Copy vs. Zero-Copy
              Duration [ms]




                                                                              Data [Mbyte]
Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany   6
Zero-Copy Between Communication Layers
      •  Often copying is not necessary
              –  If data is not modi ed a slice can be passed
                 forward without copying to a different buffer


                                           Ethernet                           IP                          TCP                    HTTP   XML
        Application
                                           Ethernet                           IP                          TCP                    HTTP   XML

          Transport                        Ethernet                           IP                          TCP                    HTTP   XML

          Internet                         Ethernet                           IP                          TCP                    HTTP   XML

         Link Layer                        Ethernet                           IP                          TCP                    HTTP   XML
Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany                7
Zero-Copy Between Communication Layers
  •  Sometimes slices of multiple packages can be
     combined to extract e.g., a payload that is split
     over multiple packages
  •  Newly “created” buffer points to original buffers
     à No copying necessary
Virtual
                 HTTP (Part 1)     HTTP (Part 2)
Buffer




Received   TCP   HTTP (Part 1)    TCP              HTTP (Part 2)
Buffers

                                                                   8
Event-Driven Architecture in Networking




                                          9
Request Processing in Multi-Thread Servers
t1: Thread        S1: ServerSocket                                       Waits most of time              db1: DataBase
      socket = accept()
                            s2: Socket                                    without doing
      <<create>>(socket)
                                          t2: Thread                       actual work!
        run()
      socket = accept()
                                 waitForData()

                                bytes = read()    <<create>>
                                                                  d1: Decoder
                                                  decode(bytes)
                                 waitForData()

                                 bytes = read()
                                                   req = decode(bytes)

                                                   <<create>>
                                                                                     s1: Servlet
                                                           processRequest(req)
                                                                                              query(...)



                                                                  response                     results
                                write(response)




                                                          = thread idle
                                                                                                                         10
Request Processing in Multi-Thread Servers
•  Usually one thread per request
  –  Thread idle most of the time (e.g. waiting for I/O)
  –  Thread even more idle when network slow
  –  Number of simultaneous clients mostly limited by
     maximum number of threads
•  Thread construction is expensive
  –  Higher latency when constructing on request
  –  Can be improved using pools of Threads
     (see Java‘s ExecutorService & Executors classes)
                                                           11
Request Processing in Event-Driven Servers
    s1: Socket          s2: Socket         io1: NioWorker                  e1: ExecutorThread                       = request 1
                     dataAvailable()                                                                                = request 2
                      bytes = read()                     handleEvent(s1, bytes)
                                                                                           <<create>>
                                 dataAvailable()                                                               d1: Decoder
                                                                                            decode(bytes)
                                   bytes = read()        handleEvent(s2, bytes)
                                                                                            <<create>>
                      dataAvailable()                                                                                        d2: Decoder
                                                                                            decode(bytes)
                      bytes = read()                     handleEvent(s1, bytes)
                                                                                            req = decode(bytes)

                                                                                                 resp = processRequest(bytes)

                                                                       write(resp)
                                 dataAvailable()
                                   bytes = read()        handleEvent(s2, bytes)
                                                                                            req = decode(bytes)

                                                                                                resp = processRequest(bytes)

                                                                        write(resp)


Disclaimer: this slide may contain errors and is far away from real implementation code but should do good for illustrative purposes       12
Request Processing in Event-Driven Servers
•  Calls to I/O functions of OS are non-blocking
•  Heavy usage of zero-copy strategies
•  Everything is an event
   –  Data available for reading
   –  Writing data
   –  Connection established / shut down
•  Different requests share threads
•  Work is split into small tasks
   –  Tasks are solved by worker threads from a pool
   –  Thread number and control decoupled from individual
      connections / simultaneous requests
•  Number of simultaneous clients can be very high
   –  Netty: 50.000 on commodity hardware!

                                                            13
Introduction to Netty




                        14
Introduction to Netty
•  „The Netty project is an effort to provide an asynchronous
   event-driven network application framework for rapid
   development of maintainable high-performance protocol
   servers & clients.“
   Source: http://netty.io

•  Good reasons to use Netty:
    •  Simpli es development
    •  Amazing performance
    •  Amazing documentation (Tutorials, JavaDocs), clean concepts
    •  Lots of documenting examples
    •  Unit testability for protocols
    •  Heavily used at e.g., twitter for performance critical applications


                                                                             15
Netty – Feature Overview




                           16
Introduction to Netty - Buffers
•  Netty uses a zero-copy strategy for efficiency
•  Primitive byte[] are wrapped in a ChannelBuffer
•  Simple read/write operations, e.g.:
   –    writeByte()
   –    writeLong()
   –    readByte()
   –    readLong()
   –  …
•  Hides complexities such as byte order
•  Uses low overhead index pointers for realization:




                                                       17
Introduction to Netty - Buffers
  •  Combine & slice ChannelBuffers without copying
     any payload data by e.g.,
          –  ChannelBuffer.slice(int index, int length)
          –  ChannelBuffers.wrappedBuffer(ChannelBuffer... Buffers)

  •  Pseudo-Code Example:
          requestPart1 = buffer1.slice(OFFSET_PAYLOAD,
                   buffer1.readableBytes() – OFFSET_PAYLOAD);
          requestPart2 = buffer2.slice(OFFSET_PAYLOAD,
                   buffer2.readableBytes() – OFFSET_PAYLOAD);
          request = ChannelBuffers.wrappedBuffer(requestPart1, requestPart2);

Virtual
                            HTTP (Part 1)            HTTP (Part 2)
Buffer

Received       TCP          HTTP (Part 1)          TCP               HTTP (Part 2)
Buffers

                                                                                     18
Netty – Feature Overview




                           19
Introduction to Netty - Codes
•  Many protocol encoders/decoders included
  –  Base64
  –  Zlib
  –  Framing/Deframing
  –  HTTP
  –  WebSockets
  –  Google Protocol Buffers
  –  Real-Time Streaming Protocol (RTSP)
  –  Java Object Serialization
  –  String
  –  (SSL/TLS)

                                              20
Introduction to Netty - Codecs
•  Abstract base classes for easy implementation
  –  OneToOneEncoder
  –  OneToOneDecoder
     •  Converts one Object (e.g. a ChannelBuffer) into another (e.g.
        a HttpServletRequest)

  –  ReplayingDecoder
     •  The bytes necessary to decode an Object (e.g. a
        HttpServletRequest) may be split over multiple data events
     •  Manual implementation forces to check and accumulate data
        all the time
     •  ReplayingDecoder allows you to implement decoding
        methods just like all required bytes were already received

                                                                       21
Netty – Putting it all together




                                  22
Introduction to Netty – Pipelines & Handlers
                      •  Every socket is attached
                         to a ChannelPipeline
                      •  It contains a stack of
                         handlers
                        –  Protocol
                           Encoders / Decoders
                        –  Security Layers
                           (SSL/TLS, Authentication)
                        –  Application Logic
                        –  ...
                                                       23
Introduction to Netty – Pipelines & Handlers
                      •  One ChannelPipeline per
                         Connection
                      •  Handlers can handle
                        –  Downstream events
                        –  Upstream events
                        –  Or both
                      •  Everything is an event
                        –  Data available for reading
                        –  Writing data
                        –  Connection established /
                           shut down
                        –  …
                                                        24
Netty – ChannelPipeline Example: HTTP(S) Client
                        Client Application                                                        •  Applications based
   read(httpResponse)                              write(httpRequest)                                on Netty are built as
                                 Channel                                                             a stack
           httpResponse                             httpRequest
                                                                                                  •  Application Logic

                                                                                ChannelPipeline
       HttpRequestDecoder                    HttpRequestEncoder

                      String                        String
                                                                                                     sites on top of the
            StringDecoder                         StringEncoder                                      channel
         ChannelBuffer                              ChannelBuffer
                                                                                                  •  Everything else
             SSLDecoder                            SSLEncoder
                                                                                                     (decoding,
         ChannelBuffer                              ChannelBuffer
                                                                                                     securing, ...) is done
                        OS Socket object
                                                                                                     inside the pipeline
Disclaimer: this slide is imprecise, may contain errors and there’s no one-to-one implementation. It shows a logic conceptual view of the Netty pipeline.   25
Netty Examples


DISCARD Server




                 26
Netty Examples – DISCARD Server
http://tools.ietf.org/html/rfc863




Source: Netty project source code @ http://github.com/netty/netty
                                                                    27
Netty Examples – DISCARD Server Bootstrap




Source: Netty project source code @ http://github.com/netty/netty
                                                                    28
Netty Examples – DISCARD Server




Source: Netty project source code @ http://github.com/netty/netty

                                                                    29
Netty Examples – Echo Server




Source: Netty project source code @ http://github.com/netty/netty
                                                                    30
Netty Examples – Static HTTP File Server




Source: Netty project source code @ http://github.com/netty/netty
                                                                    31
Netty Examples – Static HTTP File Server




Source: Netty project source code @ http://github.com/netty/netty
                                                                    32
Netty Examples – Static HTTP File Server




                                                 ...
Source: Netty project source code @ http://github.com/netty/netty
                                                                    33
References
•  Netty
  –  Project: http://netty.io
  –  Tutorial: http://netty.io/docs/
  –  JavaDoc: http://netty.io/docs/3.2.6.Final/api/
  –  Sources: http://netty.io/docs/3.2.6.Final/xref/
  –  Development: https://github.com/netty/netty




                                                       34

More Related Content

What's hot

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorReactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorVMware Tanzu
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explainedconfluent
 
Distributed load testing with k6
Distributed load testing with k6Distributed load testing with k6
Distributed load testing with k6Thijs Feryn
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache KafkaAmir Sedighi
 
Introduction to the Disruptor
Introduction to the DisruptorIntroduction to the Disruptor
Introduction to the DisruptorTrisha Gee
 
Local Apache NiFi Processor Debug
Local Apache NiFi Processor DebugLocal Apache NiFi Processor Debug
Local Apache NiFi Processor DebugDeon Huang
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes NetworkingCJ Cullen
 
Deep dive into Kubernetes Networking
Deep dive into Kubernetes NetworkingDeep dive into Kubernetes Networking
Deep dive into Kubernetes NetworkingSreenivas Makam
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - CopenhagenClaus Ibsen
 
A visual introduction to Apache Kafka
A visual introduction to Apache KafkaA visual introduction to Apache Kafka
A visual introduction to Apache KafkaPaul Brebner
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseenissoz
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 ObservabilityKnoldus Inc.
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringScyllaDB
 

What's hot (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorReactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Distributed load testing with k6
Distributed load testing with k6Distributed load testing with k6
Distributed load testing with k6
 
gRPC Overview
gRPC OverviewgRPC Overview
gRPC Overview
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache Kafka
 
Introduction to the Disruptor
Introduction to the DisruptorIntroduction to the Disruptor
Introduction to the Disruptor
 
Local Apache NiFi Processor Debug
Local Apache NiFi Processor DebugLocal Apache NiFi Processor Debug
Local Apache NiFi Processor Debug
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
HDFS Selective Wire Encryption
HDFS Selective Wire EncryptionHDFS Selective Wire Encryption
HDFS Selective Wire Encryption
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes Networking
 
Deep dive into Kubernetes Networking
Deep dive into Kubernetes NetworkingDeep dive into Kubernetes Networking
Deep dive into Kubernetes Networking
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
A visual introduction to Apache Kafka
A visual introduction to Apache KafkaA visual introduction to Apache Kafka
A visual introduction to Apache Kafka
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBase
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 Observability
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
 

Viewers also liked

深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.toleone
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transferVictor Cherkassky
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 
Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Jaap ter Woerds
 
Netty - a pragmatic introduction
Netty - a pragmatic introductionNetty - a pragmatic introduction
Netty - a pragmatic introductionRaphael Stary
 
Netty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsNetty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsRick Hightower
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenchesJordi Gerona
 
Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of nettyBing Luo
 
Real time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaReal time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaTrieu Nguyen
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System DevelopmentAllan Huang
 
Nettyらへん
NettyらへんNettyらへん
NettyらへんGo Tanaka
 
Netty Notes Part 2 - Transports and Buffers
Netty Notes Part 2 - Transports and BuffersNetty Notes Part 2 - Transports and Buffers
Netty Notes Part 2 - Transports and BuffersRick Hightower
 
자바 네트워크 소녀 Netty 리뷰
자바 네트워크 소녀 Netty 리뷰자바 네트워크 소녀 Netty 리뷰
자바 네트워크 소녀 Netty 리뷰Woojin Joe
 
Asynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyAsynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyErsin Er
 
High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)Chris Bailey
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internalsNgoc Dao
 

Viewers also liked (20)

深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.t
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transfer
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...
 
Notes on Netty baics
Notes on Netty baicsNotes on Netty baics
Notes on Netty baics
 
Netty - a pragmatic introduction
Netty - a pragmatic introductionNetty - a pragmatic introduction
Netty - a pragmatic introduction
 
Building Netty Servers
Building Netty ServersBuilding Netty Servers
Building Netty Servers
 
Netty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsNetty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoops
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenches
 
Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of netty
 
Netty
NettyNetty
Netty
 
Netty4
Netty4Netty4
Netty4
 
Real time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaReal time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, Kafka
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
 
Nettyらへん
NettyらへんNettyらへん
Nettyらへん
 
Netty Notes Part 2 - Transports and Buffers
Netty Notes Part 2 - Transports and BuffersNetty Notes Part 2 - Transports and Buffers
Netty Notes Part 2 - Transports and Buffers
 
자바 네트워크 소녀 Netty 리뷰
자바 네트워크 소녀 Netty 리뷰자바 네트워크 소녀 Netty 리뷰
자바 네트워크 소녀 Netty 리뷰
 
Asynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyAsynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with Netty
 
High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internals
 

Similar to Zero-Copy Event-Driven Servers with Netty

ARM LPC2300/LPC2400 TCP/IP Stack Porting
ARM LPC2300/LPC2400 TCP/IP Stack PortingARM LPC2300/LPC2400 TCP/IP Stack Porting
ARM LPC2300/LPC2400 TCP/IP Stack PortingMathivanan Elangovan
 
OpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosOpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosBrent Salisbury
 
Seastar at Linux Foundation Collaboration Summit
Seastar at Linux Foundation Collaboration SummitSeastar at Linux Foundation Collaboration Summit
Seastar at Linux Foundation Collaboration SummitDon Marti
 
Notes on a High-Performance JSON Protocol
Notes on a High-Performance JSON ProtocolNotes on a High-Performance JSON Protocol
Notes on a High-Performance JSON ProtocolDaniel Austin
 
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Sho Shimizu
 
Internet of Threads (IoTh), di Renzo Davoli (VirtualSquare)
Internet of Threads (IoTh), di  Renzo Davoli (VirtualSquare)  Internet of Threads (IoTh), di  Renzo Davoli (VirtualSquare)
Internet of Threads (IoTh), di Renzo Davoli (VirtualSquare) Codemotion
 
Stefano Giordano
Stefano GiordanoStefano Giordano
Stefano GiordanoGoWireless
 
Stefano Giordano
Stefano  GiordanoStefano  Giordano
Stefano GiordanoGoWireless
 
Holistic Aggregate Resource Environment
Holistic Aggregate Resource EnvironmentHolistic Aggregate Resource Environment
Holistic Aggregate Resource EnvironmentEric Van Hensbergen
 
Workload consolidation on ATCA with the advantech mic 5333 universal platform
Workload consolidation on ATCA with the advantech mic 5333 universal platformWorkload consolidation on ATCA with the advantech mic 5333 universal platform
Workload consolidation on ATCA with the advantech mic 5333 universal platformPaul Stevens
 
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...Igalia
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Davide Carboni
 
[OpenStack 하반기 스터디] DPDK & OpenStack why?
[OpenStack 하반기 스터디] DPDK & OpenStack why?[OpenStack 하반기 스터디] DPDK & OpenStack why?
[OpenStack 하반기 스터디] DPDK & OpenStack why?OpenStack Korea Community
 
[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in Containernet[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in ContainernetAndrew Wang
 

Similar to Zero-Copy Event-Driven Servers with Netty (20)

ARM LPC2300/LPC2400 TCP/IP Stack Porting
ARM LPC2300/LPC2400 TCP/IP Stack PortingARM LPC2300/LPC2400 TCP/IP Stack Porting
ARM LPC2300/LPC2400 TCP/IP Stack Porting
 
OpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosOpenStack and OpenFlow Demos
OpenStack and OpenFlow Demos
 
Userspace networking
Userspace networkingUserspace networking
Userspace networking
 
Tftp errors
Tftp errorsTftp errors
Tftp errors
 
Seastar at Linux Foundation Collaboration Summit
Seastar at Linux Foundation Collaboration SummitSeastar at Linux Foundation Collaboration Summit
Seastar at Linux Foundation Collaboration Summit
 
netty_qcon_v4
netty_qcon_v4netty_qcon_v4
netty_qcon_v4
 
Notes on a High-Performance JSON Protocol
Notes on a High-Performance JSON ProtocolNotes on a High-Performance JSON Protocol
Notes on a High-Performance JSON Protocol
 
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
 
Internet of Threads (IoTh), di Renzo Davoli (VirtualSquare)
Internet of Threads (IoTh), di  Renzo Davoli (VirtualSquare)  Internet of Threads (IoTh), di  Renzo Davoli (VirtualSquare)
Internet of Threads (IoTh), di Renzo Davoli (VirtualSquare)
 
Stefano Giordano
Stefano GiordanoStefano Giordano
Stefano Giordano
 
Stefano Giordano
Stefano  GiordanoStefano  Giordano
Stefano Giordano
 
Holistic Aggregate Resource Environment
Holistic Aggregate Resource EnvironmentHolistic Aggregate Resource Environment
Holistic Aggregate Resource Environment
 
Osi 7 layer
Osi 7 layerOsi 7 layer
Osi 7 layer
 
Multipath TCP
Multipath TCPMultipath TCP
Multipath TCP
 
Workload consolidation on ATCA with the advantech mic 5333 universal platform
Workload consolidation on ATCA with the advantech mic 5333 universal platformWorkload consolidation on ATCA with the advantech mic 5333 universal platform
Workload consolidation on ATCA with the advantech mic 5333 universal platform
 
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...
Production high-performance networking with Snabb and LuaJIT (Linux.conf.au 2...
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?
 
A series presentation
A series presentationA series presentation
A series presentation
 
[OpenStack 하반기 스터디] DPDK & OpenStack why?
[OpenStack 하반기 스터디] DPDK & OpenStack why?[OpenStack 하반기 스터디] DPDK & OpenStack why?
[OpenStack 하반기 스터디] DPDK & OpenStack why?
 
[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in Containernet[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in Containernet
 

More from Daniel Bimschas

Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRS
Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRSSoftwerkskammer Lübeck 08/2018 Event Sourcing and CQRS
Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRSDaniel Bimschas
 
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeckDaniel Bimschas
 
2013 09-02 senzations-bimschas-part2-smart-santander-experimentation
2013 09-02 senzations-bimschas-part2-smart-santander-experimentation2013 09-02 senzations-bimschas-part2-smart-santander-experimentation
2013 09-02 senzations-bimschas-part2-smart-santander-experimentationDaniel Bimschas
 
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbedDaniel Bimschas
 
2013 09-02 senzations-bimschas-part3-wiselib
2013 09-02 senzations-bimschas-part3-wiselib2013 09-02 senzations-bimschas-part3-wiselib
2013 09-02 senzations-bimschas-part3-wiselibDaniel Bimschas
 
WISEBED Tutorial @ ADHOCNETS 2011
WISEBED Tutorial @ ADHOCNETS 2011WISEBED Tutorial @ ADHOCNETS 2011
WISEBED Tutorial @ ADHOCNETS 2011Daniel Bimschas
 

More from Daniel Bimschas (6)

Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRS
Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRSSoftwerkskammer Lübeck 08/2018 Event Sourcing and CQRS
Softwerkskammer Lübeck 08/2018 Event Sourcing and CQRS
 
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck
2013 09-02 senzations-bimschas-part1-smart-santander-facility-luebeck
 
2013 09-02 senzations-bimschas-part2-smart-santander-experimentation
2013 09-02 senzations-bimschas-part2-smart-santander-experimentation2013 09-02 senzations-bimschas-part2-smart-santander-experimentation
2013 09-02 senzations-bimschas-part2-smart-santander-experimentation
 
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed
2013 09-02 senzations-bimschas-part4-setting-up-your-own-testbed
 
2013 09-02 senzations-bimschas-part3-wiselib
2013 09-02 senzations-bimschas-part3-wiselib2013 09-02 senzations-bimschas-part3-wiselib
2013 09-02 senzations-bimschas-part3-wiselib
 
WISEBED Tutorial @ ADHOCNETS 2011
WISEBED Tutorial @ ADHOCNETS 2011WISEBED Tutorial @ ADHOCNETS 2011
WISEBED Tutorial @ ADHOCNETS 2011
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Zero-Copy Event-Driven Servers with Netty

  • 1. Zero-Copy Event-Driven Servers with Netty Daniel Bimschas Institute of Telematics, University of Lübeck http://www.itm.uni-luebeck.de 1
  • 2. Content •  Basics –  Zero-Copy Techniques –  Event-Driven Architectures •  Introduction to Netty –  Buffers –  Codecs –  Pipelines & Handlers •  Netty Examples –  Discard –  HTTP Server 2
  • 4. Traditional Approach •  copying and context switches between kernel and user space à poor performance! Socket Read Buffer NIC Buffer Fast Buffer Slow Kernel Context Application Context Application App Buffer Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany 4
  • 5. Zero-Copy Approach •  Kernel handles the copy process via Direct Memory Access (DMA) –  No CPU load –  Lower load on bus system –  No copying between kernelspace and userspace Socket Read Buffer NIC Buffer Fast Buffer Kernel Context Perfect! Task Application Context Application App Buffer Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany 5
  • 6. Simple Benchmark: Copy vs. Zero-Copy Duration [ms] Data [Mbyte] Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany 6
  • 7. Zero-Copy Between Communication Layers •  Often copying is not necessary –  If data is not modi ed a slice can be passed forward without copying to a different buffer Ethernet IP TCP HTTP XML Application Ethernet IP TCP HTTP XML Transport Ethernet IP TCP HTTP XML Internet Ethernet IP TCP HTTP XML Link Layer Ethernet IP TCP HTTP XML Slide Source: Distributed Systems Course 2011/2012 by Dennis Pfisterer, Institute of Telematics, University of Lübeck, Germany 7
  • 8. Zero-Copy Between Communication Layers •  Sometimes slices of multiple packages can be combined to extract e.g., a payload that is split over multiple packages •  Newly “created” buffer points to original buffers à No copying necessary Virtual HTTP (Part 1) HTTP (Part 2) Buffer Received TCP HTTP (Part 1) TCP HTTP (Part 2) Buffers 8
  • 10. Request Processing in Multi-Thread Servers t1: Thread S1: ServerSocket Waits most of time db1: DataBase socket = accept() s2: Socket without doing <<create>>(socket) t2: Thread actual work! run() socket = accept() waitForData() bytes = read() <<create>> d1: Decoder decode(bytes) waitForData() bytes = read() req = decode(bytes) <<create>> s1: Servlet processRequest(req) query(...) response results write(response) = thread idle 10
  • 11. Request Processing in Multi-Thread Servers •  Usually one thread per request –  Thread idle most of the time (e.g. waiting for I/O) –  Thread even more idle when network slow –  Number of simultaneous clients mostly limited by maximum number of threads •  Thread construction is expensive –  Higher latency when constructing on request –  Can be improved using pools of Threads (see Java‘s ExecutorService & Executors classes) 11
  • 12. Request Processing in Event-Driven Servers s1: Socket s2: Socket io1: NioWorker e1: ExecutorThread = request 1 dataAvailable() = request 2 bytes = read() handleEvent(s1, bytes) <<create>> dataAvailable() d1: Decoder decode(bytes) bytes = read() handleEvent(s2, bytes) <<create>> dataAvailable() d2: Decoder decode(bytes) bytes = read() handleEvent(s1, bytes) req = decode(bytes) resp = processRequest(bytes) write(resp) dataAvailable() bytes = read() handleEvent(s2, bytes) req = decode(bytes) resp = processRequest(bytes) write(resp) Disclaimer: this slide may contain errors and is far away from real implementation code but should do good for illustrative purposes 12
  • 13. Request Processing in Event-Driven Servers •  Calls to I/O functions of OS are non-blocking •  Heavy usage of zero-copy strategies •  Everything is an event –  Data available for reading –  Writing data –  Connection established / shut down •  Different requests share threads •  Work is split into small tasks –  Tasks are solved by worker threads from a pool –  Thread number and control decoupled from individual connections / simultaneous requests •  Number of simultaneous clients can be very high –  Netty: 50.000 on commodity hardware! 13
  • 15. Introduction to Netty •  „The Netty project is an effort to provide an asynchronous event-driven network application framework for rapid development of maintainable high-performance protocol servers & clients.“ Source: http://netty.io •  Good reasons to use Netty: •  Simpli es development •  Amazing performance •  Amazing documentation (Tutorials, JavaDocs), clean concepts •  Lots of documenting examples •  Unit testability for protocols •  Heavily used at e.g., twitter for performance critical applications 15
  • 16. Netty – Feature Overview 16
  • 17. Introduction to Netty - Buffers •  Netty uses a zero-copy strategy for efficiency •  Primitive byte[] are wrapped in a ChannelBuffer •  Simple read/write operations, e.g.: –  writeByte() –  writeLong() –  readByte() –  readLong() –  … •  Hides complexities such as byte order •  Uses low overhead index pointers for realization: 17
  • 18. Introduction to Netty - Buffers •  Combine & slice ChannelBuffers without copying any payload data by e.g., –  ChannelBuffer.slice(int index, int length) –  ChannelBuffers.wrappedBuffer(ChannelBuffer... Buffers) •  Pseudo-Code Example: requestPart1 = buffer1.slice(OFFSET_PAYLOAD, buffer1.readableBytes() – OFFSET_PAYLOAD); requestPart2 = buffer2.slice(OFFSET_PAYLOAD, buffer2.readableBytes() – OFFSET_PAYLOAD); request = ChannelBuffers.wrappedBuffer(requestPart1, requestPart2); Virtual HTTP (Part 1) HTTP (Part 2) Buffer Received TCP HTTP (Part 1) TCP HTTP (Part 2) Buffers 18
  • 19. Netty – Feature Overview 19
  • 20. Introduction to Netty - Codes •  Many protocol encoders/decoders included –  Base64 –  Zlib –  Framing/Deframing –  HTTP –  WebSockets –  Google Protocol Buffers –  Real-Time Streaming Protocol (RTSP) –  Java Object Serialization –  String –  (SSL/TLS) 20
  • 21. Introduction to Netty - Codecs •  Abstract base classes for easy implementation –  OneToOneEncoder –  OneToOneDecoder •  Converts one Object (e.g. a ChannelBuffer) into another (e.g. a HttpServletRequest) –  ReplayingDecoder •  The bytes necessary to decode an Object (e.g. a HttpServletRequest) may be split over multiple data events •  Manual implementation forces to check and accumulate data all the time •  ReplayingDecoder allows you to implement decoding methods just like all required bytes were already received 21
  • 22. Netty – Putting it all together 22
  • 23. Introduction to Netty – Pipelines & Handlers •  Every socket is attached to a ChannelPipeline •  It contains a stack of handlers –  Protocol Encoders / Decoders –  Security Layers (SSL/TLS, Authentication) –  Application Logic –  ... 23
  • 24. Introduction to Netty – Pipelines & Handlers •  One ChannelPipeline per Connection •  Handlers can handle –  Downstream events –  Upstream events –  Or both •  Everything is an event –  Data available for reading –  Writing data –  Connection established / shut down –  … 24
  • 25. Netty – ChannelPipeline Example: HTTP(S) Client Client Application •  Applications based read(httpResponse) write(httpRequest) on Netty are built as Channel a stack httpResponse httpRequest •  Application Logic ChannelPipeline HttpRequestDecoder HttpRequestEncoder String String sites on top of the StringDecoder StringEncoder channel ChannelBuffer ChannelBuffer •  Everything else SSLDecoder SSLEncoder (decoding, ChannelBuffer ChannelBuffer securing, ...) is done OS Socket object inside the pipeline Disclaimer: this slide is imprecise, may contain errors and there’s no one-to-one implementation. It shows a logic conceptual view of the Netty pipeline. 25
  • 27. Netty Examples – DISCARD Server http://tools.ietf.org/html/rfc863 Source: Netty project source code @ http://github.com/netty/netty 27
  • 28. Netty Examples – DISCARD Server Bootstrap Source: Netty project source code @ http://github.com/netty/netty 28
  • 29. Netty Examples – DISCARD Server Source: Netty project source code @ http://github.com/netty/netty 29
  • 30. Netty Examples – Echo Server Source: Netty project source code @ http://github.com/netty/netty 30
  • 31. Netty Examples – Static HTTP File Server Source: Netty project source code @ http://github.com/netty/netty 31
  • 32. Netty Examples – Static HTTP File Server Source: Netty project source code @ http://github.com/netty/netty 32
  • 33. Netty Examples – Static HTTP File Server ... Source: Netty project source code @ http://github.com/netty/netty 33
  • 34. References •  Netty –  Project: http://netty.io –  Tutorial: http://netty.io/docs/ –  JavaDoc: http://netty.io/docs/3.2.6.Final/api/ –  Sources: http://netty.io/docs/3.2.6.Final/xref/ –  Development: https://github.com/netty/netty 34