Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of Spring WebFlux over standard Spring Boot, TomCat, Jetty, Servlet 3.1, Netty?

As I understand - there is an opportunity to consume fewer of RAM and CPU.

As I know Servlet 3.1 already has been using NIO too. Are there any advantages in speed and/or loading?

like image 203
wikk Avatar asked Oct 05 '17 17:10

wikk


1 Answers

This is a rather broad topic - but let's clear things up first.

  • Spring MVC is a web framework based on the Servlet API; such apps can be deployed on Servlet containers (like Jetty, Tomcat, Undertow).
  • Spring WebFlux is a reactive web framework based on a reactive HTTP layer; such apps can be deployed on Netty or Undertow (with native adapters) or Jetty/Tomcat/any Servlet 3.1 container (thanks to a Servlet 3.1 adapter).
  • Spring Boot applications can use Spring MVC or Spring WebFlux

Spring Framework 5.0 provides an FAQ about that with several useful resources. In short, this approach can be beneficial for efficiency and scalability for workloads dealing with lots of latency and concurrency.

Indeed, Servlet 3.1 async I/O does address those issues as well, but using that API requires to depart from using the other bits of the Servlet API which are blocking. This is why Spring WebFlux doesn't expose the Servlet API in its programming model but leverages a Servlet adapter.

like image 75
Brian Clozel Avatar answered Sep 24 '22 07:09

Brian Clozel