Timeout errors in clients application which is connected with Windows Redis Server

Lata Rajput 16 Reputation points
2021-09-21T14:01:01.843+00:00

Hi ,

I have implmentated multiple instances of StackExchange.Redis ConnectionMultiplexer, storing those objects and when I want to communicate with Redis server I take the least used one from the pool. in my web application by following the link "https://stackoverflow.com/questions/68549760/stackexchange-redis-connectionmultiplexer-pool-for-synchronous-methods/69264124#69264124" . Now i am calling the methods in Application start method like below -

var t = new ConnectionMultiplexerPool(10, ConfigurationManager.ConnectionStrings["RedisConnectionString"].ConnectionString + ",allowAdmin=True,connectTimeout=60000,Ssl=false");

IDatabase db = t.GetDatabase();
Now , i have used the loop to create 10 keys with 1mb size value of each. The issue is I am still getting the timeout error, and observed when i am accessing the application and using the code from shared link in GetDatabase method only one Redis instance is creating in pool and it comes out of the loop. And it never checking this condition var pending = connection.GetCounters().TotalOutstanding; So please help me i am calling this methods wrongly? or is there any other way of doing this. i have googled so many sites but i didnt get solution.

for (int i = 0; i < _pool.Length; i++)
{
var connection = _pool[i]; // at i=0 connection as null
if (connection == null)
{
_pool[i] = ConnectionMultiplexer.Connect(_redisConfigurationOptions);
return _pool[i].GetDatabase(); // at this line it create the instance for 1st count of loop and returns the db
}

var pending = connection.GetCounters().TotalOutstanding;
if (pending < leastPendingTasks)
{
leastPendingTasks = pending;
leastPendingDatabase = connection.GetDatabase();
}
}

return leastPendingDatabase;

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
211 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 16,076 Reputation points Microsoft Employee
    2021-09-23T20:12:51.493+00:00

    Hi @Lata Rajput Thank you for posting your question.

    With current versions of StackExchange.Redis, connection pools are not necessary or recommended. A single ConnectionMultiplexer instance can support a high load and many concurrent requests when configured properly and accessing data using the *Async methods. A pool of ConnectionMultiplexer instances running in the same process can actually add overhead and introduce conflicts and contention issues that lead to errors.

    1MB is very large – Redis’s design is optimized to serve smaller pieces of data with very low latency. Transmitting such large values is likely to cause problems at multiple points in the system, especially where clients read and process the responses. I’d recommend breaking the data into smaller pieces or looking into another data store designed for large values.

    General guidance for diagnosing timeouts:

    Regards,
    Oury