SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Apache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use casesApache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use casesShivji Kumar Jha
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkFlink Forward
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka StreamsGuozhang Wang
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안SANG WON PARK
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planningconfluent
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using KafkaKnoldus Inc.
 
Running Kafka as a Native Binary Using GraalVM with Ozan Günalp
Running Kafka as a Native Binary Using GraalVM with Ozan GünalpRunning Kafka as a Native Binary Using GraalVM with Ozan Günalp
Running Kafka as a Native Binary Using GraalVM with Ozan GünalpHostedbyConfluent
 
톰캣 운영 노하우
톰캣 운영 노하우톰캣 운영 노하우
톰캣 운영 노하우jieunsys
 
The Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systemsThe Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systemsRomain Jacotin
 
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Severalnines
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeperSaurav Haloi
 
How to Lock Down Apache Kafka and Keep Your Streams Safe
How to Lock Down Apache Kafka and Keep Your Streams SafeHow to Lock Down Apache Kafka and Keep Your Streams Safe
How to Lock Down Apache Kafka and Keep Your Streams Safeconfluent
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxFlink Forward
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotFlink Forward
 
Introduction to Apache NiFi dws19 DWS - DC 2019
Introduction to Apache NiFi   dws19 DWS - DC 2019Introduction to Apache NiFi   dws19 DWS - DC 2019
Introduction to Apache NiFi dws19 DWS - DC 2019Timothy Spann
 

Tendances (20)

Apache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use casesApache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use cases
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Kafka Security
Kafka SecurityKafka Security
Kafka Security
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka Streams
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
 
Running Kafka as a Native Binary Using GraalVM with Ozan Günalp
Running Kafka as a Native Binary Using GraalVM with Ozan GünalpRunning Kafka as a Native Binary Using GraalVM with Ozan Günalp
Running Kafka as a Native Binary Using GraalVM with Ozan Günalp
 
톰캣 운영 노하우
톰캣 운영 노하우톰캣 운영 노하우
톰캣 운영 노하우
 
The Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systemsThe Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systems
 
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
How to Lock Down Apache Kafka and Keep Your Streams Safe
How to Lock Down Apache Kafka and Keep Your Streams SafeHow to Lock Down Apache Kafka and Keep Your Streams Safe
How to Lock Down Apache Kafka and Keep Your Streams Safe
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptx
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
 
Introduction to Apache NiFi dws19 DWS - DC 2019
Introduction to Apache NiFi   dws19 DWS - DC 2019Introduction to Apache NiFi   dws19 DWS - DC 2019
Introduction to Apache NiFi dws19 DWS - DC 2019
 
Tomcatx performance-tuning
Tomcatx performance-tuningTomcatx performance-tuning
Tomcatx performance-tuning
 

En vedette

深入浅出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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.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
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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