servlet vs reactive choosing the right stack
play

Servlet vs Reactive Choosing the Right Stack Rossen Stoyanchev - PowerPoint PPT Presentation

Servlet vs Reactive Choosing the Right Stack Rossen Stoyanchev This talk Servlet and Reactive stacks Spring Framework 5 Big shift towards async Learn about the options, make choices About me Spring Framework committer Web development


  1. Servlet vs Reactive Choosing the Right Stack Rossen Stoyanchev

  2. This talk Servlet and Reactive stacks Spring Framework 5 Big shift towards async Learn about the options, make choices

  3. About me Spring Framework committer Web development Spring WebFlux from inception to GA

  4. Ask Me Anything (immediately after this session) Also featuring: Phil Webb → Spring Boot lead Stephane Maldini → Reactor lead

  5. Motivation for change

  6. ??

  7. Asynchronicity Thread pools

  8. Asynchronicity Actors Fibers / Project Loom Coroutines Event loop Thread pools

  9. Servlet Reactive 100s, 1000s threads Small, fixed # of threads (blocked) (running)

  10. Non-blocking concurrency Even Loop

  11. Declarative composition of asynchronous logic CompletableFuture, ReactiveX, Reactor, …

  12. Java 8 lambdas Functional programming models

  13. Stack choices and why choice matters

  14. @Controller @Controller Servlet Reactive

  15. Reactive client Reactive client @Controller @Controller Servlet Reactive

  16. Reactive client Reactive client Functional endpoint @Controller @Controller Servlet Reactive

  17. Reactive client Reactive client Functional endpoint @Controller @Controller Servlet Reactive Tomcat Jetty Tomcat Jetty Servlet container Servlet 3.1 container

  18. Reactive client Reactive client Functional endpoint @Controller @Controller Servlet Reactive Tomcat Jetty Netty Tomcat Jetty Servlet container Servlet 3.1 container Undertow

  19. Demo

  20. Stack architecture

  21. Spring MVC Servlet API Blocking I/O Tomcat, Jetty, …

  22. History of Servlet API 1997 1.0 … … 2009 3.0 Async Servlet 2009 3.1 Servlet non-blocking I/O … …

  23. Controller + Reactive client Async Servlet Servlet API Blocking I/O Tomcat, Jetty, …

  24. History of Servlet API 1997 1.0 … … 2009 3.0 Async Servlet 2009 3.1 Servlet non-blocking I/O … …

  25. Controller + Reactive client Async Servlet Servlet API Blocking I/O Tomcat, Jetty, …

  26. Controller + Reactive client Async Servlet Spring Web API Servlet API Reactor, Reactive Streams Reactor Servlet 3.1 Blocking I/O Netty Non-blocking I/O Tomcat, Jetty, … Netty Tomcat, Jetty, …

  27. Spring MVC Spring WebFlux Spring Web API Servlet API Reactor, Reactive Streams Blocking I/O Non-blocking I/O Tomcat, Jetty, … Netty Tomcat, Jetty, …

  28. Reactive, non-blocking back pressure

  29. Blocking expected Filter Filter Servlet Tomcat, Jetty, …

  30. Blocking not expected WebFilter WebFilter WebHandler Even Loop Netty Tomcat, Jetty, …

  31. WebFilter, WebHandler Mono<Void>

  32. Request Flux<DataBuffer> getBody()

  33. Response writeWith(Flux<DataBuffer>)

  34. Codecs Flux<DataBuffer> Flux<T>

  35. A B C WebFilter WebFilter WebHandler E D request(n) A B C Mono D Mono E Mono Mono onNext(T)

  36. WebFlux Response request(n) request(n) request(n) Spring HTTP Reactive Web Flux Controller Flux Flux WebFlux Adapter Server Client Non-blocking write onNext(T) onNext(T) onNext(T)

  37. WebFlux Request request(n) request(n) request(n) Spring Reactive Data Flux Controller Flux Flux Server WebFlux Adapter Repo Non-blocking read onNext(T) onNext(T) onNext(T)

  38. Spring MVC Response request(1) request(1) Web Servlet Spring Controller Flux Flux Server Client API MVC Blocking write Spring MVC thread onNext(T) onNext(T)

  39. Demo

  40. Choosing The right stack for the job at hand

  41. Spring MVC If it ain’t broken, don’t fix it Imperative logic is the easiest to write and debug Check application dependencies (JDBC, JPA)

  42. Spring MVC + Reactive Client Compose remote service calls Reactive data (Mongo, Cassandra, Redis) Response stream

  43. Spring WebFlux Use cases → easy to stream up or down Scale → efficient at I/O Programming model → functional endpoints

  44. Spring WebFlux Performance Efficient scale with less hardware resources It’s not about speed Latency is key to exhibit differences

  45. Thank You https://github.com/ rstoyanchev/demo-reactive-spring rstoya05

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend