sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.6k stars 347 forks source link

[QUESTION] how to use ConnectionPoolOptions effective #588

Closed mkzz115 closed 2 weeks ago

mkzz115 commented 1 month ago

My Project use connect pool to request redis, and I set pool size is 5, sometimes I find request redis to slow, perhaps more than 5 threads request it, blocked.

I don't want it to block my request, and I want it to be as efficient as possible.

Do you have some suggestions?

sewenew commented 1 month ago

Normally, compared to socket operations between client and Redis, fetching connection from the underlying connection pool is negligible. However, if you have too many threads competing a small number of connections, these threads might block waiting others.

In order to mitigate the problem, you can try setting a large number of pool size. However, IMHO, the best solution is to redesign your application to use Redis pipeline to make it more efficient. Also you can try the Async interface, which does not block on IO operations.

Regards

mkzz115 commented 1 month ago

Thank you so much, I changed pool size, and use pipleline can solve it, maybe my redis have some slow query (other modules), I will use another instantion in the future.