1
votes

I implemented AppFabric 1.1 to my ASP.NET web application. I am using Read Through approach because I just need to read images from my SQL database and store them in the cache. So I will have chance to retrieve those data as fast as possible.

I am checking shell and I can see that my application is reading successfully from cache and write to the cache if cache is empty. However, AppFabric is not as fast as I expected. The version without AppFabric is faster than the one with AppFabric. In addition to that, when I use Appfabric, I can see that there is high CPU and memory usage.

What are the potential reasons of that? What do you suggest to me?

Appreciated to your ideas,

1

1 Answers

0
votes

So without more details, it's hard to tell for sure, but I can try to help from my experience with AppFabric. Are we talking about high memory usage on the AppFabric server, or the client computer(not sure if you are using a web app, or something else)

  1. AppFabric will be slower than in-proc memory, also AF should not be on the same server as you application.
  2. How are you creating the AppFabric DataCacheFactory? Are you creating for every request? That is bad, as it is expensive, so it should be a static/singleton. I do something like

public class AppFabricDistributedCacheManagerFactory {

private static DataCacheFactory _dataCacheFactory;
    public void Initialize()
    {
        if (_dataCacheFactory == null)
        {
            _dataCacheFactory = new DataCacheFactory();
        }
    }
......
  1. Do you have local cache enabled in AppFabric, for images it seems appropriate.
  2. Make sure your Provider is not throwing exceptions and is only calling Appfabric when it really should. Put fiddler on you dev box and watch the requests. So watch for

    1. First call to AF, are you using regions? Make you create it.
    2. If you are creating regions? Do you make it exists before you save? Just in case you are look at this code.. before did this.. I had a few issues

      public void SaveToProvider(string key,TimeSpan duration ,string regionName,object toSave)
      try
      {
          Cache.Put(key, toSave, duration , regionName);
      }
      catch (DataCacheException cacheError)
      {
          // Look at the ErrorCode property to see if the Region is missing
          if (cacheError.ErrorCode == DataCacheErrorCode.RegionDoesNotExist)
          {
              // Create the Region and retry the Put call
              Cache.CreateRegion(_regionName);
              Cache.Put(key, toSave, duration , regionName);
          }
      }
      
  3. Watch the requests when you request a item not is cache.. see that is call AF then loads the image and call AF again to save.

  4. Watch the request when you know the item in already loaded, if you are using local cache you should see no AF requests..One if you are not.