jborgers / PMD-jPinpoint-rules

PMD rule set for responsible Java and Kotlin coding: performance, sustainability, multi-threading, data mixup and more.
Apache License 2.0
43 stars 10 forks source link

Rule Request: AvoidParallelFlux #278

Closed jborgers closed 10 months ago

jborgers commented 11 months ago

Observation: Project Reactor Flux.parallel().runOn() is used.
Problem: The data is divided on a number of 'rails' matching the number of CPU cores. This is only useful in case much CPU processing is performed: if the sequential form takes more than 0,1 ms of CPU time. With remote calls this is usually not the case. In addition, it introduces more complexity with risk of failures.
Solution: Remove parallel().runOn. For pure CPU processing: use ordinary sequential streaming unless the work takes more than about 0,1 ms in sequential form and proves to be faster with parallelization. So only for large collections and much processing.