CacheHelper.GetCounterValue performance tuning
Actual Behavior
public long GetCounterValue(string name, AzureWebApEnvironmentVariables environmentVariable)
{
if (!CacheHelper.Instance.IsInCache(name))
{
PerformanceCounterImplementation client = new PerformanceCounterImplementation();
string uncachedJson = client.GetAzureWebAppEnvironmentVariables(environmentVariable);
if (uncachedJson == null)
{
return 0;
}
CacheHelper.Instance.SaveToCache(name, uncachedJson, DateTimeOffset.Now.AddMilliseconds(500));
}
...
Issue
- GetCounterValue method is called a lot of times.
- The method reads a value from an environment variable.
- There are only four environment variables.
- The value of an environment variable is stored to the cache under the key name.
- The reuse of the value is limited due the key name.
Expected Behavior - cache key (high priority)
- It would be more efficient to store the environment value to the cache under environmentVariable key (or somehow derived key).
- The value of the envinronment variable would be reused for a lot of method calls (during the 500ms expiration)
Expected Behavior - environment variable does not exists (low priority)
- When the environment variable does not exists, this information is not cached
- Repetitive method calls call expensive Environment.GetEnvironmentVariable.
Version Info
SDK Version : 2.9.1
This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Hm, I see I need to fix it myself. Lets try some PR...
This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.
Hm, I see I need to fix it myself. Lets try some PR...
This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.
Leave it open.