Upgrade to Pro — share decks privately, control downloads, hide ads and more …

High Performance JVM Networking with Netty

High Performance JVM Networking with Netty

This talk, given at JDK.io, is an introduction into Netty with lots of real world examples and experiences building clients and servers on top of it. Recording may be found through jdk.io at some point.

Michael Nitschinger

September 14, 2016
Tweet

More Decks by Michael Nitschinger

Other Decks in Programming

Transcript

  1. JVM Networking
    with Netty
    Michael Nitschinger, Couchbase, Inc.
    High Performance!

    View Slide

  2. View Slide

  3. “Netty is an asynchronous and
    event-driven network application
    framework for rapid development
    of maintainable high
    performance protocol servers &
    clients.“

    View Slide

  4. “Netty is an asynchronous and
    event-driven network application
    framework for rapid development
    of maintainable high
    performance protocol servers &
    clients.“

    View Slide

  5. It’s simple.

    View Slide

  6. Half-Duplex
    Full-Duplex

    View Slide

  7. View Slide

  8. ChannelHandler
    ChannelHandler
    ChannelHandler
    ChannelHandler
    Pipeline

    View Slide

  9. Encoder
    Encoder
    Decoder
    Decoder

    View Slide

  10. OutboundHandler
    OutboundHandler
    InboundHandler
    InboundHandler

    View Slide

  11. Encoder
    Encoder
    Decoder
    Decoder
    Codec
    Codec

    View Slide

  12. BinaryMemcacheObjectAggregator
    KeyValueAuthHandler
    KeyValueFeatureHandler
    BinaryMemcacheClientCodec
    KeyValueHandler

    View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. “Each Handler receives events
    from the pipeline and emits
    events into the pipeline.“

    View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. Handlers Codecs
    ByteToByte
    ByteToMessage
    MessageToByte
    MessageToMessage
    Replay
    FixedLengthFrame
    LengthFieldBasedFrame
    LineBasedFrame
    DelimiterBasedFrame
    ….
    HTTP
    HTTP2
    Memcache
    MQTT
    Redis
    Smtp
    SSL
    Websockets
    Xml
    Zlib

    View Slide

  24. Handlers Codecs
    ByteToByte
    ByteToMessage
    MessageToByte
    MessageToMessage
    Replay
    FixedLengthFrame
    LengthFieldBasedFrame
    LineBasedFrame
    DelimiterBasedFrame
    ….
    HTTP
    HTTP2
    Memcache
    MQTT
    Redis
    Smtp
    SSL
    Websockets
    Xml
    Zlib

    View Slide

  25. Magic
    (1)
    Opcode
    (1)
    Key Length
    (2)
    Extras Length
    (1)
    Data Type
    (1)
    Status
    (2)
    Total Body Length
    (4)
    Opaque
    (4)
    CAS
    (8)
    Memcached Binary Header (24 Bytes)

    View Slide

  26. View Slide

  27. It’s fast.

    View Slide

  28. 1 JVM, 1 CB Node, localhost

    View Slide

  29. https://github.com/Netflix-Skunkworks/WSPerfLab/blob/master/test-results/RxNetty_vs_Tomcat_April2015.pdf

    View Slide

  30. https://github.com/Netflix-Skunkworks/WSPerfLab/blob/master/test-results/RxNetty_vs_Tomcat_April2015.pdf

    View Slide

  31. Techempower, Round 12
    https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=plaintext&l=27wqyn

    View Slide

  32. Techempower, Round 12
    https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=plaintext&l=27wqyn

    View Slide

  33. Why?
    Efficient EventLoop/Socket Multiplexing
    GC Optimized
    Less Allocations
    Pooling
    Statics & Reuse
    Selected use of sun.misc.Unsafe
    Lots of “Mechanical Sympathy”

    View Slide

  34. Why?
    Efficient EventLoop/Socket Multiplexing
    GC Optimized
    Less Allocations
    Pooling
    Statics & Reuse
    Selected use of sun.misc.Unsafe
    Lots of “Mechanical Sympathy”

    View Slide

  35. Why?
    Efficient EventLoop/Socket Multiplexing
    GC Optimized
    Less Allocations
    Pooling
    Statics & Reuse
    Selected use of sun.misc.Unsafe
    Lots of “Mechanical Sympathy”

    View Slide

  36. Wait! There is more.

    View Slide

  37. View Slide

  38. View Slide

  39. http://i3.kym-cdn.com/photos/images/original/000/006/933/Massimo.jpg

    View Slide

  40. NioEventLoopGroup → EpollEventLoopGroup
    NioEventLoop → EpollEventLoop
    NioServerSocketChannel → EpollServerSocketChannel
    NioSocketChannel → EpollSocketChannel

    View Slide

  41. View Slide

  42. https://blog.twitter.com/2013/netty-4-at-twitter-reduced-gc-overhead

    View Slide

  43. Where Next?

    View Slide

  44. Make Norman Rich!
    https://www.manning.com/books/netty-in-action

    View Slide

  45. Start Here
    Web netty.io
    IRC #netty on Freenode
    Mailing List groups.google.com/forum/#!forum/netty
    StackOverflow “netty” tag
    Bugs github.com/netty/netty/issues

    View Slide

  46. Thanks!
    Michael Nitschinger, Couchbase, Inc.
    twitter: @daschl

    View Slide