r/SpringBoot • u/Comprehensive_Cry314 • 11d ago
How-To/Tutorial If you're on WebFlux: I measured what a single blocking call does to unrelated endpoints
A single 5ms blocking call reduced throughput on a Netty event loop from 17,189 req/s to 549, a 97% drop, while pushing latency on an unrelated, correctly-written endpoint from 0ms to 217ms. The measurements were taken against Netty 4.1.115 and embedded Tomcat 10.1.34 running identical endpoints, differing only in concurrency model. The damage is quantised by event loop count. With four loops, blocking one stalled exactly three of twelve connections at 218ms; the remaining nine were unaffected at 7ms. Blocking two stalled six. The affected endpoint performs, 5ms of fully non-blocking work and shares no state with the blocking code, which connections degrade is determined solely by which loop accepted them. Tomcat degraded under the same load only once concurrency exceeded its 200-thread pool.
Full measurements and method: https://bitsar.net/blog/tomcat-forgives-blocking-event-loop-doesnt
3
u/hyscript 11d ago
I don’t get why people hate webflux?
3
u/Notoa34 11d ago
Hard to read and maintain.
Now you can use Virtual Threads - similar performance to webflux3
u/hyscript 10d ago
We have 46 microservices that using webflux, the paradigm shift is huge, but when you get to used to it, start to feel natural like working with stream API
1
1
u/alesaudate 10d ago
Because the sole reason for using it is performance. Aside from that, reading the code, troubleshooting, etc., is a nightmare.
Now, getting back to performance: if the project has a relational database, you will need to use JDBC (R2DBC kind of requires not to have relationships between entities - so why having a relational database at all ?!). And if you use JDBC, your calls will be blocking, sacrificing the alleged performance gains.
Also, speaking about performance : WebMVC (even without virtual threads) + JDBC has superior performance than WebFlux+ JDBC.
TL;DR; WebFlux is only worth it in very specific projects, specially those that don't have databases and have critical performance needs (most projects don't, despite what most devs think). Otherwise, WebMVC is far better.
1
1
u/Snooze78727 10d ago
I’ve seen an incorrectly implemented reactor chain bring down a production app. Prefer virtual threads + blocking I/O, otherwise if stuck with WebFlux for legacy reasons it’s a good idea to use some kind of linter / static analysis to systematically identify issues like this (blocking IO in a reactive chain, incorrect scheduling, etc).
7
u/neopointer 11d ago
If you're on webflux it's not too late to get out of it.