Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpRuntime.Cache settings for Azure?

I'm using HttpRuntime.Cache for memory caching on Azure.

The problem is that the memory goes full - then it hits the 90% percentage limit of Azure, Azure thinks the role is unhealthy and restarts it - bringing the whole site down.

Now I found the EffectivePercentagePhysicalMemoryLimit property and it seems to be set to 98% on Azure, so above the 90% 'unhealthy' limit.

  • How can I change this limit on HttpRuntime.Cache? The property is readonly.
  • It is possible to tweak the Azure auto restart percentage to a bit higher?
  • Are there any other recommended settings for using memory cache? Is there another class that I should use? I can find little information in combination with Azure. Most articles talk about a seperate caching service for if the data needs to be consistent across multiple instances.

To be clear: I want memory caching - I don't need a shared caching through i.e. Redis, because the data has not a great need to be consistent.

like image 729
Dirk Boer Avatar asked Oct 11 '25 22:10

Dirk Boer


1 Answers

You can change the EffectivePercentagePhysicalMemoryLimit by using the percentagePhysicalMemoryUsedLimit attribute of the cache Element in your web.config

<configuration>
  <system.web>
    <caching>
      <cache percentagePhysicalMemoryUsedLimit="60" />
    </caching>
  </system.web>

The EffectivePercentagePhysicalMemoryLimit property can be set with the percentagePhysicalMemoryUsedLimit attribute of the cache Element for caching (ASP.NET Settings Schema) element in the application's configuration file. If the percentagePhysicalMemoryUsedLimit attribute is not set, the cache algorithm determines the maximum size of the cache, and the EffectivePercentagePhysicalMemoryLimit property is calculated.

You can get more information on the documentation : Cache.EffectivePercentagePhysicalLimit


The other option is to disable the Azure auto restart mechanism. It is called Proactive Auto Heal and you can disable it by setting the WEBSITE_PROACTIVE_AUTOHEAL_ENABLED to False :

  1. Go to portal.azure.com and go to your Web App for which you would like to disable the feature.
  2. Under Settings go to Application Settings.
  3. Under App Settings add “WEBSITE_PROACTIVE_AUTOHEAL_ENABLED” and set it to “False”.
  4. That’s it! Proactive Auto Heal is disabled.

enter image description here

like image 79
Cyril Durand Avatar answered Oct 14 '25 16:10

Cyril Durand