Significant latency when using Spring WebFlux with R2DBC for reactive database calls
I've encountered a strange issue with I tried several approaches but none seem to work... I'm experiencing significant latency when making reactive database calls using Spring WebFlux with R2DBC (version 0.8.3.RELEASE) and PostgreSQL. My application is designed to handle concurrent requests, but I noticed that response times can spike to over 500ms when querying larger datasets. For instance, hereβs a simplified version of my repository method: ```java @Repository public interface UserRepository extends ReactiveCrudRepository<User, Long> { Flux<User> findByLastName(String lastName); } ``` And in my service layer, I'm calling this repository method: ```java @Service public class UserService { private final UserRepository userRepository; public UserService(UserRepository userRepository) { this.userRepository = userRepository; } public Flux<User> getUsersByLastName(String lastName) { return userRepository.findByLastName(lastName); } } ``` Iβve verified that the database indices are properly set up, and basic queries perform well when run directly in the database. However, when I run my reactive service, I can see in the logs that the execution might take a lot longer than expected: ``` 2023-10-10 12:34:56.789 INFO 12345 --- [reactor-http-nio-2] c.e.myapp.service.UserService : Fetching users with last name 'Doe'... (latency: 501ms) ``` Iβve tried increasing the connection pool size in my `application.yml`: ```yaml spring: r2dbc: pool: max-size: 20 ``` I also ensured that I'm using the latest versions of R2DBC and PostgreSQL driver libraries. However, the performance seems to degrade as the number of concurrent users increases. Is there a specific configuration or optimization I might be missing to improve the response time for these calls? Any insights or suggestions would be greatly appreciated! My development environment is Ubuntu. How would you solve this? What am I doing wrong? I'm working on a REST API that needs to handle this. I'd really appreciate any guidance on this.