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

Going Reactive - High Performance JVM Code with...

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    
  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. 5   The  Manifesto   •  Event-­‐Driven   ­  Loosely

     coupled  components   ­  Sharing  resources   ­  Async  execuCon   •  Scalable   •  Resilient   ­  IsolaCng  failure   ­  Build  supervision  hierachies   •  Responsive  
  4. 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)  
  5. 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  
  6. 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.  
  7. 13   Selectors  -­‐  Regex   •  A  RegexSelector  will

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

     match  a  String  by  extrac+ng   bits  from  a  URI.  
  9. 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);   }  
  10. 16   Promises   •  Promises  allow  for  composi+on  of

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

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

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

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