State of the Art JVM Networking with Netty 4

State of the Art JVM Networking with Netty 4

I gave this talk at JAX 2014 and it is an introduction into the Netty framework.

D839d9aa56849a71d8a9aa3d292a6ce6?s=128

Michael Nitschinger

May 15, 2014
Tweet

Transcript

  1. 1.

    Michael  Nitschinger  (@daschl)    JVM  Engineer  @  Couchbase,  Inc.  

    State  of  the  Art  JVM   Networking  with  Ne;y  4  
  2. 2.

    2       “Ne#y  is  an  asynchronous  and  event-­‐driven

      network  applica0on  framework  for  rapid   development  of  maintainable  high  performance   protocol  servers  &  clients.“  
  3. 7.
  4. 8.
  5. 10.

    10   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  6. 11.

    11   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  7. 12.

    12   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  8. 13.

    13   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  9. 14.

    14   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  10. 15.

    15   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  11. 16.

    16   Encoder   Encoder   NeCy   Writes  

    NeCy   Reads   Decoder   Decoder  
  12. 17.

    17   Outbound   Handler   Outbound   Handler  

    NeCy   Writes   NeCy   Reads   Inbound   Handler   Inbound   Handler  
  13. 18.
  14. 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  
  15. 21.
  16. 22.
  17. 23.
  18. 24.
  19. 25.

    25   Handler  Types   •  Encoder   ­  MessageToByte

      ­  MessageToMessage   •  Decoder   ­  ByteToMessage   ­  MessageToMessage   •  Hybrid  Codecs   ­  ByteToByte   ­  ByteToMessage   ­  MessageToMessage   •  Useful  Decoders   ­  Replay   ­  FixedLengthFrame   ­  LengthFieldBasedFrame   ­  LineBasedFrame   ­  DelimiterBasedFrame  
  20. 26.

    26   Handler  Types   •  Encoder   ­  MessageToByte

      ­  MessageToMessage   •  Decoder   ­  ByteToMessage   ­  MessageToMessage   •  Hybrid  Codecs   ­  ByteToByte   ­  ByteToMessage   ­  MessageToMessage   •  Useful  Decoders   ­  Replay   ­  FixedLengthFrame   ­  LengthFieldBasedFrame   ­  LineBasedFrame   ­  DelimiterBasedFrame  
  21. 27.

    27   Provided  Codecs   •  HTTP   •  HTTP2

      •  Websockets   •  SPDY   •  Memcache   •  Serializa@on   •  Socks   •  JBoss  Marshaling   •  Protobuf   •  SSL   •  Zlib  
  22. 28.

    28   Provided  Codecs   •  HTTP   •  HTTP2

      •  Websockets   •  SPDY   •  Memcache   •  Serializa@on   •  Socks   •  JBoss  Marshaling   •  Protobuf   •  SSL   •  Zlib  
  23. 34.

    34   Why?   •  Efficient  EventLoop/Socket  Mul@plexing   • 

    GC  op@mized   ­  Less  allocaVons   ­  Caching/Pooling   ­  StaVc  Instances   ­  Selected  use  of  sun.misc.Unsafe   •  Lots  of  „Mechanical  Sympathy“   ­  (hCp://mechanical-­‐sympathy.blogspot.com)  
  24. 35.

    35   ByteBufs   •  java.nio.ByteBuffer  replacement   ­  Simpler

     API   ­  Feature  rich   ­  Embraces  reusability   ­  CompositeByteBuf   Reader     Index   Writer   Index   Capacity  
  25. 37.
  26. 38.

    38   Na@ve  Epoll  Transport   •  JNI  based  wrapper

     around  Linux  Epoll  for  TCP  and  UDP   •  GC  op@mized   •  Support  for:  TCP_CORK  and  SO_REUSEADDR   ­  TCP_CORK:  Helps  with  data  batching   ­  SO_REUSEADDR:  UDP  MulVcast  
  27. 43.

    43   •  Based  on:   ­  Akka‘s  AbstractNodeQueue  

    ­  hCp://www.1024cores.net/home/lock-­‐free-­‐algorithms/queues/non-­‐ intrusive-­‐mpsc-­‐node-­‐based-­‐queue    
  28. 45.
  29. 46.
  30. 47.

    47   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  
  31. 48.

    48   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?  
  32. 49.

    49   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    
  33. 50.

    50   Contribu@ng   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  men@oned  in  the  release  notes