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.

D839d9aa56849a71d8a9aa3d292a6ce6?s=128

Michael Nitschinger

October 19, 2013
Tweet

Transcript

  1. 1   Going  Reac+ve   High  Performance  JVM  Code  with

     Reactor   Michael  Nitschinger    
  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  
  3. 3   Reac+ve?  

  4. 4   The  Manifesto   •  hGp://www.reac+vemanifesto.org/     h>p://www.reacCvemanifesto.org/images/full-­‐reacCve@2x.png

     
  5. 5   The  Manifesto   •  Event-­‐Driven   ­  Loosely

     coupled  components   ­  Sharing  resources   ­  Async  execuCon   •  Scalable   •  Resilient   ­  IsolaCng  failure   ­  Build  supervision  hierachies   •  Responsive  
  6. 6   Yo  dawg,  I  heard  you  like  ships  events!

     
  7. 7   Meet  Reactor.  

  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)  
  9. 9   Landscape  

  10. 10   A  first  look  

  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  
  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.  
  13. 13   Selectors  -­‐  Regex   •  A  RegexSelector  will

     match  a  String  by  execu+ng  the   regex.  
  14. 14   Selectors  -­‐  Templates   •  A  UriTemplateSelector  will

     match  a  String  by  extrac+ng   bits  from  a  URI.  
  15. 15   Func+ons   •  Perform  work  on  T.  

      public  interface  Consumer<T>  {    void  accept(T  t);   }   •  Supply  the  caller  with  T.     public  interface  Supplier<T>  {    T  get();   }   •  Perform  work  on  T  and  return  V.     public  interface  Function<T,  V>  {    V  apply(T  t);   }   •  Check  if  the  input  matches  the  criteria.     public  interface  Predicate<T>  {    boolean  test(T  t);   }  
  16. 16   Promises   •  Promises  allow  for  composi+on  of

     func+ons   ­  Shares  common  funcCons  with  a  Stream  
  17. 17   Streams   •  Streams  allow  the  composi+on  of

     func+ons   ­  Callback++   ­  NeYlix  RxJava  Observable,  JDK  8  Stream  
  18. 18   Processor   •  Thin  wrapper  around  the  Disruptor

     RingBuffer   ­  Converts  Disruptor  API  to  Reactor  API   ­  Really  fast!  
  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.  
  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  
  21. 21   Integra+on:  Clojure   •  Meltdown:  A  Clojure  binding

     by  @michaelklishin  and   @ifesdjeen   ­  h>ps://github.com/clojurewerkz/meltdown    
  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,…)  
  23. 23   Demo  

  24. 24   Ques+ons?  

  25. 25