Search code examples
javadatabaseconnection-poolinghikaricplettuce

Single connection vs Connection Pool


According to lettuce, we don't need connection pool and it uses single thread safe shared connection https://github.com/lettuce-io/lettuce-core/wiki/Connection-Pooling

But, according to hikari-cp we need to have pool of connections of preferably size connections = ((core_count * 2) + effective_spindle_count) https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing

I am confused why we don't need pooling in one case but required in other?


Solution

  • JDBC is blocking, so only 1 request can be in flight at a time on a connection. Because of this, Hikari pools are used to efficiently share the resources of multiple connections so many threads can make requests simultaneously. The more requests you need to serve, and the longer they take, the larger your pool needs to be.

    Lettuce, on the other hand, is non-blocking, a single connection can have many requests in flight at once. And because the connections are thread-safe, the connection can be safely shared by multiple threads too.