Slide 1

Slide 1 text

Michael  Nitschinger  (@daschl)   JVM  Engineer  @  Couchbase,  Inc.   Going  Reac6ve   High  Performance  JVM  Code  with  Reactor  

Slide 2

Slide 2 text

2   Reac6ve?  

Slide 3

Slide 3 text

3   4  Traits  of  Reac6ve  Systems   •  h?p://www.reac6vemanifesto.org/     h9p://www.reac>vemanifesto.org/images/full-­‐reac>ve@2x.png  

Slide 4

Slide 4 text

4   Scalable  &  Event-­‐Driven   •  Message-­‐Passing   •  Asynchronous   •  Non-­‐Blocking   •  Immutability   •  Avoiding   Synchroniza6on   h9p://www.reac>vemanifesto.org/images/amdahl@2x.png  

Slide 5

Slide 5 text

5   Resilient   •  Isola6ng  Failure   •  Supervision  Hierachies   •  Self-­‐Healing  Components   h9p://www.reac>vemanifesto.org/images/tank@2x.png  

Slide 6

Slide 6 text

6   Responsive   •  Use  Bounded  Queues  &  Backpressure   •  Apply  Batching  under  Traffic  Bursts   •  Don‘t  forget  the  Big  O!   0   20   40   60   80   100   120   Hockey  S>ck   Linear   Leveling  Off  

Slide 7

Slide 7 text

7   Meet  Reactor.  

Slide 8

Slide 8 text

8   What  is  Reactor?   •  Founda6onal  library   •  Lives  between  user  and  low-­‐level  code.   •  Suite  for:  drivers,  libraries,  event-­‐driven  systems   •  Part  of  Spring  IO   •  1.1.0  Released  (h?ps://github.com/reactor/reactor)  

Slide 9

Slide 9 text

9   Landscape  

Slide 10

Slide 10 text

10   A  first  look  

Slide 11

Slide 11 text

11   Dispatchers   •  Per  Environment   •  Manage  Task  Execu6on.     ­  ThreadPoolExecutorDispatcher   execu>ng  tasks  in  a  thread  pool   ­  EventLoopDispatcher   mul>ple  event  loops  dispatching  tasks   ­  RingBufferDispatcher   uses  the  LMAX  Disruptor  RingBuffer   ­  ActorDispatcher   to  pin  keys  to  threads   ­  SynchronousDispatcher   for  tes>ng  

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

15   Selectors  –  Class  Types   •  A  ClassSelector  will  match  the  same  or  a  supertype  of   the  given  class.  

Slide 16

Slide 16 text

16   Func6ons   •  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);   }  

Slide 17

Slide 17 text

17   Promises   •  Promises  allow  for  composi6on  of  func6ons   ­  Shares  common  func>ons  with  a  Stream  

Slide 18

Slide 18 text

18   Streams   •  Streams  allow  the  composi6on  of  func6ons   ­  Callbacks  on  steroids   ­  Akka  Streams,  RxJava  Observables,  JDK  8  Stream  

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

20   Integra6on:  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.  

Slide 21

Slide 21 text

21   Integra6on:  Groovy   •  First  class  ci6zen  language  implementa6on     ­  @CompileSta>c  ready   ­  Prominent  use  of  Closure  as  Consumers,  Func>ons  and  more   ­  Operator  overloading   ­  Full  Reactor  system  Builder  

Slide 22

Slide 22 text

22   Integra6on:  Clojure   •  Meltdown:  A  Clojure  binding  by  @michaelklishin  and   @ifesdjeen   ­  h9ps://github.com/clojurewerkz/meltdown    

Slide 23

Slide 23 text

23   Wait  –  there  is  more!  

Slide 24

Slide 24 text

24   Networking   •  TCP  and  UDP  Support   •  ZeroMQ,  SSL,  Codecs,...  

Slide 25

Slide 25 text

25   Networking  -­‐  Server  

Slide 26

Slide 26 text

26   Allocators   •  Control  Memory  Usage  (RingBuffer,  Refcoun>ng)  

Slide 27

Slide 27 text

27   What  else?   •  Too  much  to  show  today!     ­  Buffer  tooling   ­  Sequencing/EventOrdering   ­  Work  Queue  support  on  top  of  Java  Chronicle   ­  Logback  Appender   ­  Language  Constructs  (i.e.  Tuples,…)  

Slide 28

Slide 28 text

28   Demo  

Slide 29

Slide 29 text

29   Ques6ons?  

Slide 30

Slide 30 text

30