-1

The Event Loop in Spring Webflux of having 1 core per thread handling incoming requests is supposedly one main advantage of the framework.

At the low level, other than the NIO part, how is that model any different than how tradition Servlet handles requests?

In a traditional Servlet, there's also a loop running and whenever a thread is free it'll pick up the requests.

So how is Event Loop any different? They are the same to me.

Glide
  • 20,235
  • 26
  • 86
  • 135
  • The difference is that in a synchronous model the completion of the request lifecycle is bounded to a single thread a.k.a ThreadLocal, where as in an event loop an NIO callback is executed on a separate thread, different from the one that accepted the request. Both models have thread pool to ensure fast allocation. – aksappy Apr 12 '21 at 20:39
  • And how would that be different with the Servlet is using the 3.0 spec with Async processing - letting another thread pool handle the processing, freeing up the servlet threadpool. In that case, how is the Event Loop different than Async Processing Loop? – Glide Apr 12 '21 at 20:56
  • 1
    There is a good explanation here https://stackoverflow.com/questions/56794263/spring-webflux-differrences-when-netty-vs-tomcat-is-used-under-the-hood. The difference is all around IO. – aksappy Apr 13 '21 at 16:53

1 Answers1

1

Spring WebFlux provides a higher level abstraction than Servlet spec.

Spring WebFlux requires some runtime for it to work and Servlet 3.1+ is one such runtime. Check out this part of the documentation for more details.

This is the most relevant part:

Spring WebFlux relies on Servlet 3.1 non-blocking I/O and uses the Servlet API behind a low-level adapter

artur
  • 1,710
  • 1
  • 13
  • 28
  • Other than the NIO part of the Input/Output Stream, is there anything different in terms on how Webflux handles incoming requests vs an Async Servlet? From how I see it, there's nothing special about the "Event Loop" – Glide Apr 12 '21 at 23:10
  • 1
    The point is that WebFlux in itself doesn't do any of the low level concurrency in http world. It relies on other technologies for that. Like Servlet 3.1+, Netty or Undertow (or whatever else). Those "runtimes" provide that functionality. That way you can express your http request handlin logic in WebFlux and switch to different enviornments without changing your code. In that sense it's higher level abstraction – artur Apr 13 '21 at 05:50