How to fix and handle memory leak issues in Azure AppService by using IDistributedCache.

Vamshi 151 Reputation points
2024-01-02T17:37:13.3+00:00

Hi Support Team,

My requirement is to generate a Report request with 100 evaluation Ids each. Report request is submitted to generate 100 Reports in PDF format or Word Format. Most of the Reports generated are about 1000 to 1300 pages each.

I have implemented ProofOfConcept on DistributedCache feature on Report data output stream for generating the Report and I was able to achieve the result. I have used this DistributedCache mechanisim to improve performance i.e. to avoid re-processing of the same Report data again when there is no change in the Report data for a certain period of time.

Also, I did test behavior of AbsoluteExpiration vs SlidingExpiration in DistributedCacheEntryOptions. I am planning to use AbsoluteExpiration option.

 var cacheEntryOptions = new DistributedCacheEntryOptions
  {                    
//AbsoluteExpiration = DateTime.Now.AddMinutes(60),                            //AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60)                                                                             SlidingExpiration = TimeSpan.FromMinutes(60)                 
  };


Deployed the DistributedCache feature ProofOfConcept code to AppService in Azure cloud DEV environment. Below are the stats:

PDF Report:

Reportrequest submitted first time with 100 evaluation Ids in Pdf format - 100 reports processing - it takes around 28 mins.

When the Report request is again submitted with same 100 evaluation Ids in Pdf format - same 100 reports are served from Cache - it takes around 12 mins.

Word Report:

Reportrequest submitted first time with 100 evaluation Ids in Word format - 100 reports processing- it takes around 14 mins.

When the Report request is again submitted with same 100 evaluation Ids in Word format - same 100 reports are served from Cache - it takes around 1 Minute..

I was reading about Distributed Cache. DistributedCache

Refer the screenshot above. I was analyzing on the below use case scenarios, Need inputs and best approach to avoid any memory leak issues in the Azure environment using DistributedCache?

Example:

ReportRequest1 : generate Report request with evaluationids 1-100

ReportRequest2 : generate Report request with evaluationids 101-200

ReportRequest3 : generate Report request with evaluationids 201-300

ReportRequest4 : generate Report request with evaluationids 301-400

ReportRequest5 : generate Report request with evaluationids 401-500

ReportRequest6 : generate Report request with evaluationids 501-600

ReportRequest7 : generate Report request with evaluationids 601-700

ReportRequest8 : generate Report request with evaluationids 701-800

ReportRequest9 : generate Report request with evaluationids 801-900

ReportRequest10 : generate Report request with evaluationids 901-1000

If we do all above Report requests in span of 60 mins time, This will end up storing 1000 Reports data in the cache store.

Need inputs and best approach to handle to avoid any memory leak issues in the Azure AppService by using DistributedCache?

Thank you

Vam

Developer technologies | ASP.NET | ASP.NET Core
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
Developer technologies | .NET | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 82,061 Reputation points Volunteer Moderator
    2024-01-02T17:45:52.5133333+00:00

    you are correct. the default is a simple cache that implements the distributed cache interface. if used on a web farm, each server has its own cache. when hosted on a web farm, you are expected to pick a true distributed cache like redis or sqlserver.

    https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedi

    https://www.nuget.org/packages/Microsoft.Extensions.Caching.SqlServer

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 22,721 Reputation points Moderator
    2024-01-05T14:50:02.6233333+00:00

    @Vamshi Thanks for reaching us through multiple forum, as I can see there is descriptive answer provided here for this query, please let us know if further assistance is required here.

    1 person found this answer helpful.
    0 comments No comments

Your answer

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