1

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?

Rajat Aggarwal
  • 392
  • 3
  • 16
  • Please link the source of your information – Daniel W. Feb 17 '23 at 11:48
  • 2
    Basically, Lettuce is powered by Netty - that's why. If you read Jedis client recommendation, it would sound a lot like Hikari, since underneath the client operates more like JDBC in a blocking fashion. – Ashwin Prabhu Feb 24 '23 at 11:05

2 Answers2

2

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.

Michael
  • 810
  • 6
  • 18
  • is there some non-blocking JDBC client? – Rajat Aggarwal Feb 22 '23 at 15:42
  • The underlying Java Database Connectivity API is blocking, so you can't write a non-blocking JDBC client. If you want non-blocking you can use R2DBC which is reactive (assuming there's a client available for your DB). – Michael Feb 22 '23 at 22:40
  • 2
    There was one failed attempt in the past at cracking this: https://github.com/oracle-samples/oracle-db-examples/tree/main/java/AoJ. – Ashwin Prabhu Feb 24 '23 at 10:59
  • ALso, I would like to add this is very specific case of Lettuce since it uses Netty under the hood to enable async IO. If you look over the fence to the more popular Jedis client, there pooling is very much recommended. – Ashwin Prabhu Feb 24 '23 at 11:02
  • 1
    I wouldn't say it's specific to Lettuce; Redisson also uses Netty under the hood to achieve non-blocking IO. But you are right, Jedis is more popular and a blocking client which needs pooling for the same reasons JDBC does. – Michael Feb 25 '23 at 12:05
1

Hikari is a JDBC connection pool. Connection pooling is required because database has long things to do and while that connection open and running a query you can not run another query over it, so it is better to have multiple "open" connections ready. Read more here

On the other hand Redis is not a database. Redis is a key value based in memory store/cache used for fast access. There you do not need connection pool because it is simple and fast, you ask to redis is "key1" exist give me the data and you get it or not. On the other hand with database you run long running SQLs sometime stored procedures depends to complexity but it is not one step work.

ozkanpakdil
  • 3,199
  • 31
  • 48