I have performance issue when i get int value from redis cache

Hamza Taha 30 Reputation points
2023-09-26T11:24:01.6533333+00:00

I use Azure Redis cache in the .net core 7 project
and I have an INT value and try to get it in the .net core 7 project.
but my problem is that getting the value from the Redis cache takes too long like 500 milliseconds, is there any reason for that?
this is the sample from the code :

public T Get<T>(string key)
        {
            string data = _cache.StringGet(key);
            if (!string.IsNullOrEmpty(data))
            {
                return JsonSerializer.Deserialize<T>(data);
            }
            return default(T);
        }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,630 questions
Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
260 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 67,016 Reputation points
    2023-10-15T16:56:57.24+00:00

    You don’t really give us any information. What is you azure redis configuration, what is the payload size. What is your server’s latency to azure.

    as it takes 23ms just to deserialize, I assume the payload is a fair size. Your 120ms does not seem unreasonable. A C0 resdis configuration is good for about 100mbps transfer rating, not counting latency.

    See:

    https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-troubleshoot-timeouts


  2. GeethaThatipatri-MSFT 29,477 Reputation points Microsoft Employee
    2023-10-16T23:54:47.95+00:00

    @Hamza Taha So, thanks for the added detail. I assume this isn't actually cross-region.

     I see you're using a synchronous StringGet function, and I wonder what the circumstances you're testing it in are, and whether you are suffering from for instance, thread starvation, where the .net has to spin up more worker threads when you run out -- one reason for running out being blocking the threads with sync APIs like this.

     I'd suggest you to:

    • refactor to await StringGetAsync
    • make sure you set a generous number of MinWorkerThreads so that there is no long delay to acquire worker threads if the thread pool gets empty

    See the managed thread pool - .NET | Microsoft Learn

    Regards

    Geetha

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.