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

State of the Art JVM Networking with Netty

State of the Art JVM Networking with Netty

I gave this talk at GeeCon 2015 in Krakow. Recording will be available through the GeeCon channels.

Michael Nitschinger

May 12, 2015
Tweet

More Decks by Michael Nitschinger

Other Decks in Programming

Transcript

  1. Michael  Nitschinger  (@daschl)  
     JVM  Engineer  @  Couchbase,  Inc.  
    State  of  the  Art  JVM  
    Networking  with  Ne;y  4  
    The Walking Dead
    A Survival Guide to Resilient Reactive Applications
    Michael Nitschinger @daschl
    Netty
    State of the Art JVM Networking
    Michael Nitschinger @daschl

    View Slide

  2. 2  
     
     
    “Ne#y  is  an  asynchronous  and  event-­‐driven  
    network  applica0on  framework  for  rapid  
    development  of  maintainable  high  performance  
    protocol  servers  &  clients.“  

    View Slide

  3. 3  
    [email protected]  
    Enthusiasm  
    Encouragement  
    Simplicity  

    View Slide

  4. 4  
    [email protected]  
    Enthusiasm  
    Encouragement  
    Simplicity  

    View Slide

  5. View Slide

  6. 6  
    Half-­‐Duplex    
     
    (HTTP)  
    Full-­‐Duplex  
    (Websockets)  

    View Slide

  7. 7  

    View Slide

  8. 8  

    View Slide

  9. 9  
    Pipelines  

    View Slide

  10. 10  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  11. 11  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  12. 12  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  13. 13  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  14. 14  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  15. 15  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  16. 16  
    Encoder  
    Encoder  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Decoder  
    Decoder  

    View Slide

  17. 17  
    Outbound  
    Handler  
    Outbound  
    Handler  
    NeCy  
    Writes  
    NeCy  
    Reads  
    Inbound  
    Handler  
    Inbound  
    Handler  

    View Slide

  18. 18  

    View Slide

  19. 19  
    ChannelHandlers  

    View Slide

  20. 20  
    Handlers  are  your  Workers  
    Each  handler  receives  messages  and  poten;ally  emits  
    messages.  
    •  Use  them  for  
    ­  Encoding  &  Decoding  („Codec“)  
    ­  Business-­‐Logic  
    ­  State  Changes  
    ­  Event  NoVficaVons  

    View Slide

  21. 21  
    Handler  Hierachy  
    ChannelHandler  
    ChannelInboundHandler  
    ChannelInboundHandlerAdapter  
    ChannelOutboundHandler  
    ChannelOutboundHandlerAdapter  

    View Slide

  22. 22  

    View Slide

  23. 23  

    View Slide

  24. 24  

    View Slide

  25. 25  
    Handler  Types  
    •  Encoder  
    ­  MessageToByte  
    ­  MessageToMessage  
    •  Decoder  
    ­  ByteToMessage  
    ­  MessageToMessage  
    •  Hybrid  Codecs  
    ­  ByteToByte  
    ­  ByteToMessage  
    ­  MessageToMessage  
    •  Useful  Decoders  
    ­  Replay  
    ­  FixedLengthFrame  
    ­  LengthFieldBasedFrame  
    ­  LineBasedFrame  
    ­  DelimiterBasedFrame  

    View Slide

  26. 26  
    Handler  Types  
    •  Encoder  
    ­  MessageToByte  
    ­  MessageToMessage  
    •  Decoder  
    ­  ByteToMessage  
    ­  MessageToMessage  
    •  Hybrid  Codecs  
    ­  ByteToByte  
    ­  ByteToMessage  
    ­  MessageToMessage  
    •  Useful  Decoders  
    ­  Replay  
    ­  FixedLengthFrame  
    ­  LengthFieldBasedFrame  
    ­  LineBasedFrame  
    ­  DelimiterBasedFrame  

    View Slide

  27. 27  
    Provided  Codecs  
    •  HTTP  
    •  HTTP2  
    •  Websockets  
    •  SPDY  
    •  Memcache  
    •  [email protected]  
    •  Socks  
    •  JBoss  Marshaling  
    •  Protobuf  
    •  SSL  
    •  Zlib  

    View Slide

  28. 28  
    Provided  Codecs  
    •  HTTP  
    •  HTTP2  
    •  Websockets  
    •  SPDY  
    •  Memcache  
    •  [email protected]  
    •  Socks  
    •  JBoss  Marshaling  
    •  Protobuf  
    •  SSL  
    •  Zlib  

    View Slide

  29. 29  
    Bootstrap  

    View Slide

  30. 30  
    [email protected]  
    Enthusiasm  
    Encouragement  
    Simplicity  

    View Slide

  31. 31  
    Performance  

    View Slide

  32. 32  
    Couchbase  &  Ne;y  

    View Slide

  33. 33  
    Techempower  Round  9  
    Plaintext  i7  

    View Slide

  34. 34  
    Why?  
    •  Efficient  EventLoop/Socket  [email protected]  
    •  GC  [email protected]  
    ­  Less  allocaVons  
    ­  Caching/Pooling  
    ­  StaVc  Instances  
    ­  Selected  use  of  sun.misc.Unsafe  
    •  Lots  of  „Mechanical  Sympathy“  

    View Slide

  35. 35  
    ByteBufs  
    •  java.nio.ByteBuffer  replacement  
    ­  Simpler  API  
    ­  Feature  rich  
    ­  Embraces  reusability  
    ­  CompositeByteBuf  
    Reader    
    Index  
    Writer  
    Index  
    Capacity  

    View Slide

  36. 36  
    The  extra  mile  

    View Slide

  37. 37  

    View Slide

  38. 38  
    [email protected]  Epoll  Transport  
    •  JNI  based  wrapper  around  Linux  Epoll  for  TCP  and  UDP  
    •  GC  [email protected]  
    •  Support  for:  TCP_CORK  and  SO_REUSEADDR  
    ­  TCP_CORK:  Helps  with  data  batching  
    ­  SO_REUSEADDR:  UDP  MulVcast  

    View Slide

  39. 39  
    [email protected]  Bootstrap  

    View Slide

  40. View Slide

  41. 41  
    ByteBuf  Pooling  
    h;ps://blog.twi;er.com/2013/ne;y-­‐4-­‐at-­‐twi;er-­‐reduced-­‐gc-­‐overhead  

    View Slide

  42. 42  
    [email protected]  
    Enthusiasm  
    Encouragement  
    Simplicity  

    View Slide

  43. 43  
    Reusability  

    View Slide

  44. 44  
    Regular  Releases  

    View Slide

  45. 45  
    •  Based  on:  
    ­  Akka‘s  AbstractNodeQueue  
    ­  hCp://www.1024cores.net/home/lock-­‐free-­‐algorithms/queues/non-­‐
    intrusive-­‐mpsc-­‐node-­‐based-­‐queue  
     

    View Slide

  46. 46  
    [email protected]  
    Enthusiasm  
    Encouragement  
    Simplicity  

    View Slide

  47. 47  

    View Slide

  48. 48  

    View Slide

  49. 49  
    Jestan  Nirojan,  Cruz  Julian  Bishop,  Frédéric  Brégier,  Jeff  Pinner,  
    Veebs,  Michael  Nitschinger,  vibul,  Craig  P.  Motlin,  Daniel  Bevenius,  
    Vibul  Imtarnasan,  Luke  Wood,  Cruz  Bishop,  Bill  Gallagher,  ab,  
    alepar,  bgallagher,  Andy  Taylor,  Ngoc  Dao,  John  Fallows,  Jakob  
    Buchgraber,  Andrei  PozoloVn,  Frederic  Bregier,  Shawn  Silverman,  
    Evan  Meagher,  iainmcgin,  Prajwal  Tuladhar,  Derek  Troy-­‐West,  ursa,  
    dantran,  alexey,  kerr,  Aaron  Riekenberg,  Andrei.PozoloVn,  kxbmap,  
    Courtney  Robinson,  Sun  Ning,  zhen9ao,  Alex  Petrov,  Bruce  
    Mitchener,  Chris  Mowforth,  Edwin  Mol,  Evans  Yang,  Guido  García,  
    James  Abley,  Jeff  Griffith,  Jeff  Smick,  Leonardo  Freitas  Gomes,  Mike  
    Heath,  Mike  Schore,  Mirko  Caserta,  Roman  Stoffel  

    View Slide

  50. 50  
    Vladimir  Schafer,  alain,  fredericBregier,  izstas,  radimch,  Greg  SolVs,  
    Michael  Grove,  George  Cao,  MiddleBen,  nibin,  Andrew  Cox,  
    pfisterer,  Felix  Trepanier,  Eric  Charles,  Olaf  Bergner,  Phillip  
    Schichtel,  Dennis  Boldt,  Rogie  Sulzbach,  Adam  Vandenberg,  Ryan  
    Shelley,  Sasha  Zverev,  David  Dossot,  Stephane  Landelle,  Dao  Ngoc,  
    Sunng,  Tony  Rice,  CoNDoRip,  ValenVn  Kovalenko,  Carl  Byström,  
    Brian  Roach,  Vladimir  Krivosheev,  shreyharia,  Will,  William  Kemper,  
    Wolfgang  Profer,  Brendt  Lucas,  tsingxu,  Bourne,  Geoff,  Benoit  
    Sigoure,  Atsuhiko  Yamanaka,  bk1te,  cmcmaugh,  coltnz,  AtKaaZ,  
    Andrej  Golovnin,  hepin1989,  Artur  Dryomov,  irelandKen,  Alexey  
    Diomin,  jwilson,  Arron  Norwell,  Jamie  Furness,  JaVnder,  Andrew  
    Gaul,  James  Roper,  marius  a.  eriksen,  Ionuț  G.  Stan,  Johan  Rask,  Ian  
    Barfield,  Josh  Wilson,  JusVn  Santa  Barbara,  milenkovicm,  MaChias  
    Wessendorf,.....  ...you?  

    View Slide

  51. 51  
    Geing  Help  
    •  Start  here:  ne;y.io  
    •  IRC:  #ne;y  on  Freenode  
    •  Mailing  List:    
    h;ps://groups.google.com/forum/#!forum/ne;y  
    •  Stackoverflow:  „ne;y“  tag  
    •  Bugtracker:  h;ps://github.com/ne;y/ne;y/issues  
     

    View Slide

  52. 52  
    Ne;y  in  [email protected]  
    by  Norman  Maurer  
    manning.com/maurer  
     

    View Slide

  53. 53  
    [email protected]  
    1.  Read:  h;p://ne;y.io/wiki/developer-­‐guide.html  
    2.  Fork:  h;ps://github.com/ne;y/ne;y  
    3.  Submit  PR:  h;ps://github.com/ne;y/ne;y/pulls  
    4.  Be  prepared  for  some  feedback/improvement  cycles!  
    5.  Get  [email protected]  in  the  release  notes  

    View Slide

  54. View Slide