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

Going Reactive - High Performance JVM Code with Reactor

Going Reactive - High Performance JVM Code with Reactor

This talk was given at DevFest Vienna 2013, featuring an introduction into the Reactor framework (https://github.com/reactor/reactor) combined with exhaustive demos.

Michael Nitschinger

October 19, 2013
Tweet

More Decks by Michael Nitschinger

Other Decks in Programming

Transcript

  1. 1  
    Going  Reac+ve  
    High  Performance  JVM  Code  with  Reactor  
    Michael  Nitschinger  
     

    View Slide

  2. 2  
    Who  is  that  guy?  
    •  Developer  Advocate  at  Couchbase  
    ­  Java  SDK  Maintainer  
    ­  Spring-­‐Data-­‐Couchbase  and  more  
     
    •  @daschl  
    •  Contribu+ng  to  Reactor,  NeGy,...  
    •  Living  here  in  Vienna  

    View Slide

  3. 3  
    Reac+ve?  

    View Slide

  4. 4  
    The  Manifesto  
    •  hGp://www.reac+vemanifesto.org/  
     
    h>p://www.reacCvemanifesto.org/images/full-­‐[email protected]  

    View Slide

  5. 5  
    The  Manifesto  
    •  Event-­‐Driven  
    ­  Loosely  coupled  components  
    ­  Sharing  resources  
    ­  Async  execuCon  
    •  Scalable  
    •  Resilient  
    ­  IsolaCng  failure  
    ­  Build  supervision  hierachies  
    •  Responsive  

    View Slide

  6. 6  
    Yo  dawg,  I  heard  you  like  ships  events!  

    View Slide

  7. 7  
    Meet  Reactor.  

    View Slide

  8. 8  
    What  is  Reactor?  
    •  A  founda+onal  library  to  build    
    reac+ve  applica+ons.  
     
    •  Gray  area  between  user-­‐  and  low-­‐level  code.  
    •  Build  your  applica+on  cores  on  top  of  it.  
    •  Helps:  drivers,  servers,  libraries,  evented  architectures.  
    •  Maintained  by,  but  no  dependency  on  Spring.  
    •  Currently  in  RC  state!                                        (hGps://github.com/reactor/reactor)  

    View Slide

  9. 9  
    Landscape  

    View Slide

  10. 10  
    A  first  look  

    View Slide

  11. 11  
    Dispatchers  
    •  Created  on  an  Environment-­‐basis.  
    •  Dispatchers  manage  Task  Execu+on.  
     
    ­  ThreadPoolExecutorDispatcher  
    execuCng  tasks  in  a  thread  pool  
    ­  BlockingQueueDispatcher  
    event-­‐loop  style  
    ­  RingBufferDispatcher  
    uses  the  LMAX  Disruptor  RingBuffer  
    ­  SynchronousDispatcher  
    for  tesCng  

    View Slide

  12. 12  
    Selectors  
    •  LeY-­‐hand  side  of  an  equality  comparison.  
    •  Can  be  created  from  any  object.  
    ­  $(object)  
    ­  Selectors.object(obj)  
    •  Can  extract  data  from  the  matched  key.  

    View Slide

  13. 13  
    Selectors  -­‐  Regex  
    •  A  RegexSelector  will  match  a  String  by  execu+ng  the  
    regex.  

    View Slide

  14. 14  
    Selectors  -­‐  Templates  
    •  A  UriTemplateSelector  will  match  a  String  by  extrac+ng  
    bits  from  a  URI.  

    View Slide

  15. 15  
    Func+ons  
    •  Perform  work  on  T.  
     
    public  interface  Consumer  {  
     void  accept(T  t);  
    }  
    •  Supply  the  caller  with  T.  
     
    public  interface  Supplier  {  
     T  get();  
    }  
    •  Perform  work  on  T  and  return  V.  
     
    public  interface  Function  {  
     V  apply(T  t);  
    }  
    •  Check  if  the  input  matches  the  criteria.  
     
    public  interface  Predicate  {  
     boolean  test(T  t);  
    }  

    View Slide

  16. 16  
    Promises  
    •  Promises  allow  for  composi+on  of  func+ons  
    ­  Shares  common  funcCons  with  a  Stream  

    View Slide

  17. 17  
    Streams  
    •  Streams  allow  the  composi+on  of  func+ons  
    ­  Callback++  
    ­  NeYlix  RxJava  Observable,  JDK  8  Stream  

    View Slide

  18. 18  
    Processor  
    •  Thin  wrapper  around  the  Disruptor  RingBuffer  
    ­  Converts  Disruptor  API  to  Reactor  API  
    ­  Really  fast!  

    View Slide

  19. 19  
    Integra+on:  Spring  
    •  Helpers  to  integrate  Reactor  into  ApplicationContext  
    ­  @EnableReactor  
    ­  Wiring  annotated  handlers  
    •  DispatcherTaskExecutor  
    ­  Not  intended  for  “high  scale”  
    ­  Used  to  get  Spring  components  running  in  the  same  thread  as  Reactor  
    consumers.  

    View Slide

  20. 20  
    Integra+on:  Groovy  
    •  First  class  ci+zen  language  implementa+on  
     
    ­  @CompileStaCc  ready  
    ­  Prominent  use  of  Closure  as  Consumers,  FuncCons  and  more  
    ­  Operator  overloading  
    ­  Full  Reactor  system  Builder  

    View Slide

  21. 21  
    Integra+on:  Clojure  
    •  Meltdown:  A  Clojure  binding  by  @michaelklishin  and  
    @ifesdjeen  
    ­  h>ps://github.com/clojurewerkz/meltdown    

    View Slide

  22. 22  
    What  else?  
    •  Too  much  to  show  today!  
     
    ­  TCP  Client/Server  based  on  Ne>y  4  
    ­  Buffer  tooling  
    ­  Sequencing  for  event  ordering  
    ­  Work  Queue  support  on  top  of  Java  Chronicle  
    ­  Logback  Appender  
    ­  Language  Constructs  (Composables,  Tuples,…)  

    View Slide

  23. 23  
    Demo  

    View Slide

  24. 24  
    Ques+ons?  

    View Slide

  25. 25  

    View Slide