Azure cache interrupt time from WCF REST service

I am building an EF6 web application in Azure and I am using Azure Cache. I test calls to my WCF service, and I get insanely irregular answers - from 300 ms to 15 seconds!

I configured my code according to this example and it works fine locally

I am debugging remotely, and I see that the cache key is located and the data is calling from the cache, so I try to understand why there are huge changes in response time. Most of the time he is 5 + sec, which is obviously too long.

The example I tested looks like this:

WCF service GET request: http://feniksdev-staging.azurewebsites.net/EkckoNewsService.svc/getFriends

// Cache client configured by settings in application configuration file. public DataCacheFactory cacheFactory = new DataCacheFactory(); public DataCache _cache; public DataCache cache { get { if (_cache == null) _cache = cacheFactory.GetDefaultCache(); return _cache; } set { } } ... ... [OperationContract] [System.ServiceModel.Web.WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getFriends")] public string getFriends() { string cachekey = "getFriends/{" + user.Id + "}"; object result = cache.Get(cachekey); if (result == null) { using (EkckoContext entities = new EkckoContext()) { var frnds = entities.UserConnections.Where(uc => uc.UserId == user.Id).Select(uc => new { Name = uc.Friend.Username }).ToList(); JsonSerializerSettings jsonSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }; string json = JsonConvert.SerializeObject(frnds, jsonSettings); cache.Add(cachekey, json); return json; } } else { return (string)result; } } 

UserConnection is a simple table in my db and currently has no data, so the call returns an empty JSON array. user - Session object and defaults to 1 by default for user.Id

With remote debugging, the object is in the cache, and the cached object is returned. Thus, everything good, with the exception of the response time, is still changing 20 times (300 ms - 6 seconds).

When debugging one of the other web service methods remotely, I received the following error when trying to access a cached object using the corresponding key ( object result = cache.Get(cachekey); ):

{"ErrorCode: SubStatus: there is a temporary failure. Try again later. (One or more of the indicated cache servers is unavailable, which may be caused by a busy network or servers. For local cache clusters, also check the following to ensure that permission is granted for this client account for security, and make sure the AppFabric caching service is enabled through the firewall on all cache hosts, and the MaxBufferSize on the server must be greater than or equal to the size of the serialized object sent from the client.) Information: client tried to connect to the server: net.tcp: //ekckodev.cache.windows.net: 22238. " }

Then I set maxBufferSize in my configuration as follows:

  <configSections> <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" /> <section name="cacheDiagnostics" type="Microsoft.ApplicationServer.Caching.AzureCommon.DiagnosticsConfigurationSection, Microsoft.ApplicationServer.Caching.AzureCommon" allowLocation="true" allowDefinition="Everywhere" /> </configSections> ... ... <system.web> ... ... <caching> <outputCache defaultProvider="AFCacheOutputCacheProvider"> <providers> <add name="AFCacheOutputCacheProvider" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheOutputCache" /> </providers> </outputCache> </caching> </system.web> .... .... ... <dataCacheClients> <dataCacheClient name="default"> <autoDiscover isEnabled="true" identifier="ekckodev.cache.windows.net" /> <localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" /> <securityProperties mode="Message" sslEnabled="false"> <messageSecurity authorizationInfo="xxxxxxxxxxxxxxxxxxxxxxx" /> </securityProperties> <transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" receiveTimeout="600000"/> </dataCacheClient> </dataCacheClients> 

But I still get such an unpredictable response time - especially when you press the same service call repeatedly.

After adding the maxbuffersize configuration, cache requests still fail. some retrieve the object; in other cases, I get the same exception, however the port is different

"... The client tried to contact the server: net.tcp: //ekckodev.cache.windows.net: 22233." } "

Could this be a firewall issue? If so, how do I open the corresponding ports?

I also got the following exception when instantiating a DataCache object:

_cache = cacheFactory.GetDefaultCache();

ErrorCode: SubStatus: A temporary error exists. Please try again later. (One or more of the indicated cache servers is unavailable, which may be caused by a busy network or servers. For local cache clusters, also check the following conditions. Verify that the security permission for this client account is valid and that the AppFabric cache service is enabled through the firewall on all nodes of the cache. Also, MaxBufferSize on the server must be greater than or equal to the serialized size of the object sent by the client.)

Any thoughts on why I am getting such results? it, of course, is not faster with a cache than WIHTOUT, so it seems that there is some kind of latency in the cache that does not seem right ...

Thanks in advance for your help!

UPDATE : After a few more searches, it seems that I'm not the only one in this problem: low performance with azure cache

I find it hard to believe that this is the performance I should expect

UPDATE 2 I commented out all the cache related code from my service and repeated the same tests again. Response time is noticeably lower WITHOUT cache! The "getFriends" collapse is about 250 ms with a cache, but reaches a maximum of more than 5 seconds with a cache. My other method, which extracts about 4 kilobytes of data, peaked at 20 seconds with a cache and now is about 2 seconds without a cache.

Again: I find it hard to believe that this is the performance I should expect

UPDATE 3 Now I have abandoned Azure Cache in favor of MemoryCache. A nice example here. My service calls now consistently take about 300 ms in a browser.

I opened a ticket with Microsoft Azure support regarding Azure Cache, so I will update this post when they contact, and I asked them why their cache is so garbage. When my faith in Microsoft rose: /

+6
source share
1 answer

It sounds like you came to the right conclusion that Azure Managed Cache is not using. About 6 months ago, Microsoft began recommending that all new development be done against their Redis-based caching in Azure.

We recommend that all new developments use the Azure Redis cache.

It is strange that they do not show the possibility of creating a Redis cache on the "old" Azure management site (manage.windowsazure.com), but they are in the "preview" of the Azure Management Portal .

0
source

Source: https://habr.com/ru/post/970370/


All Articles