Base solution for your next web application
Open Closed

Performance issues with cache and GetProfilePictureByUserId #10729


User avatar
0
Ricavir created
  • Abp 6.6.1
  • Angular
  • .NET5

Hi,

I'm getting very long request issues with GetProfilePictureByUserId endpoint. Sometimes more than 1 min ! Here is an example from Azure insights :

As you can see, a lot of time is "waste" before accessing database (which is very short time access).

I slightly change GetProfilePictureByUserId to implement a cache mechanism. Here is the code :

 public async Task<GetProfilePictureOutput> GetProfilePictureByUserId(long userId)
        {
            //Get from cache first
            var outputFromCache = await _cacheManager.GetCache(UserPictureByUserIdCacheName).GetOrDefaultAsync(userId.ToString()) as GetProfilePictureOutput;
            if (outputFromCache != null)
                return outputFromCache;
            else
            {
                var user = await UserManager.GetUserByIdAsync(userId);
                if (user.ProfilePictureId == null)
                {
                    return new GetProfilePictureOutput(string.Empty);
                }

                var output = await GetProfilePictureById(user.ProfilePictureId.Value);
                //Set cache
                await _cacheManager.GetCache(UserPictureByUserIdCacheName).SetAsync(userId.ToString(), output);

                return output;
            }
        }

When testing this code, it runs very fast. But on production, a lot of requests gets stuck sometimes. I'm using Redis cache with azure app service in 2 instances.

I have the same issues with other endpoints like :

  • TokenAuth/Authenticate
  • signalr/negociate

All this seems to be linked with cache management. This is frustrating because the app can be very slow time to time and frustrating lots of users.

I tried to use AbpPerRequestRedisCache but it is throwing exceptions at the moment...

How can I fix this ?


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    I will provide feedback about the AbpPerRequestRedisCache usage problem this week to you.

  • User Avatar
    0
    Ricavir created

    Thank you @ismcagdas

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    I hope that this problem will be solved via https://github.com/aspnetboilerplate/aspnetboilerplate/pull/6334. We will release 6.6.2 tomorrow, you can try it out.

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas, thank you for this. I will try it and provide feedback on all related issues.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Thanks, we will release it today.