SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...
[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...
[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...オラクルエンジニア通信
 
単なるキャッシュじゃないよ!?infinispanの紹介
単なるキャッシュじゃないよ!?infinispanの紹介単なるキャッシュじゃないよ!?infinispanの紹介
単なるキャッシュじゃないよ!?infinispanの紹介AdvancedTechNight
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013mumrah
 
Using Wildcards with rsyslog's File Monitor imfile
Using Wildcards with rsyslog's File Monitor imfileUsing Wildcards with rsyslog's File Monitor imfile
Using Wildcards with rsyslog's File Monitor imfileRainer Gerhards
 
Networking in Java with NIO and Netty
Networking in Java with NIO and NettyNetworking in Java with NIO and Netty
Networking in Java with NIO and NettyConstantine Slisenka
 
Running Apache NiFi with Apache Spark : Integration Options
Running Apache NiFi with Apache Spark : Integration OptionsRunning Apache NiFi with Apache Spark : Integration Options
Running Apache NiFi with Apache Spark : Integration OptionsTimothy Spann
 
Building a Streaming Microservice Architecture: with Apache Spark Structured ...
Building a Streaming Microservice Architecture: with Apache Spark Structured ...Building a Streaming Microservice Architecture: with Apache Spark Structured ...
Building a Streaming Microservice Architecture: with Apache Spark Structured ...Databricks
 
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3Ji-Woong Choi
 
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)Hironobu Suzuki
 
AWS Black Belt Online Seminar 2017 Amazon Aurora
AWS Black Belt Online Seminar 2017 Amazon AuroraAWS Black Belt Online Seminar 2017 Amazon Aurora
AWS Black Belt Online Seminar 2017 Amazon AuroraAmazon Web Services Japan
 
Data discovery & metadata management (amundsen installation)
Data discovery & metadata management (amundsen installation)Data discovery & metadata management (amundsen installation)
Data discovery & metadata management (amundsen installation)창언 정
 
Pacemakerを使いこなそう
Pacemakerを使いこなそうPacemakerを使いこなそう
Pacemakerを使いこなそうTakatoshi Matsuo
 
Monitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaArvind Kumar G.S
 
NiFi Developer Guide
NiFi Developer GuideNiFi Developer Guide
NiFi Developer GuideDeon Huang
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...HostedbyConfluent
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudNoritaka Sekiyama
 

Was ist angesagt? (20)

[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...
[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...
[Oracle Cloud Days Tokyo 2015] Oracle Database 12c最新情報 ~Maximum Availability ...
 
単なるキャッシュじゃないよ!?infinispanの紹介
単なるキャッシュじゃないよ!?infinispanの紹介単なるキャッシュじゃないよ!?infinispanの紹介
単なるキャッシュじゃないよ!?infinispanの紹介
 
PostgreSQLバックアップの基本
PostgreSQLバックアップの基本PostgreSQLバックアップの基本
PostgreSQLバックアップの基本
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
Using Wildcards with rsyslog's File Monitor imfile
Using Wildcards with rsyslog's File Monitor imfileUsing Wildcards with rsyslog's File Monitor imfile
Using Wildcards with rsyslog's File Monitor imfile
 
Java11へのマイグレーションガイド ~Apache Hadoopの事例~
Java11へのマイグレーションガイド ~Apache Hadoopの事例~Java11へのマイグレーションガイド ~Apache Hadoopの事例~
Java11へのマイグレーションガイド ~Apache Hadoopの事例~
 
Apache spark 2.3 and beyond
Apache spark 2.3 and beyondApache spark 2.3 and beyond
Apache spark 2.3 and beyond
 
Networking in Java with NIO and Netty
Networking in Java with NIO and NettyNetworking in Java with NIO and Netty
Networking in Java with NIO and Netty
 
Running Apache NiFi with Apache Spark : Integration Options
Running Apache NiFi with Apache Spark : Integration OptionsRunning Apache NiFi with Apache Spark : Integration Options
Running Apache NiFi with Apache Spark : Integration Options
 
Building a Streaming Microservice Architecture: with Apache Spark Structured ...
Building a Streaming Microservice Architecture: with Apache Spark Structured ...Building a Streaming Microservice Architecture: with Apache Spark Structured ...
Building a Streaming Microservice Architecture: with Apache Spark Structured ...
 
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
 
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
 
AWS Black Belt Online Seminar 2017 Amazon Aurora
AWS Black Belt Online Seminar 2017 Amazon AuroraAWS Black Belt Online Seminar 2017 Amazon Aurora
AWS Black Belt Online Seminar 2017 Amazon Aurora
 
Data discovery & metadata management (amundsen installation)
Data discovery & metadata management (amundsen installation)Data discovery & metadata management (amundsen installation)
Data discovery & metadata management (amundsen installation)
 
Pacemakerを使いこなそう
Pacemakerを使いこなそうPacemakerを使いこなそう
Pacemakerを使いこなそう
 
Monitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and Grafana
 
NiFi Developer Guide
NiFi Developer GuideNiFi Developer Guide
NiFi Developer Guide
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
 

Andere mochten auch

深入浅出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
 
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
 
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...Menlo Systems GmbH
 

Andere mochten auch (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
 
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
 
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
DASH: A C++ PGAS Library for Distributed Data Structures and Parallel Algorit...
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Kürzlich hochgeladen (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

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