locked
Azure AppFabric Caching in a Service RRS feed

  • Question

  • I"m trying to implement Azure AppFabric Cache with our local web server (farm).  I've gotten everything working, but I'm running into connection throttling (along with the failure messages that EVERYBODY is running into.)

     

    One of the things that I'm trying to do is to implement caching in a WCF service.  We have a service that pulls a list of items from a database that generates a dropdown list on our asp.net web site.  That list appears on multiple pages.  Rather than put caching in all pages, it would be much easier to maintain caching in the service.  

     

    The problem is that about 50% of the time, I am getting a connection throttling error.  I'm only pulling from the cache in a single method of the service.  I'm not really sure how to persist the factory across multiple service calls, so I create and dispose the factory in the method.  But it's almost like AppFabric is not clearing the connections in the dispose.  The site gets hit quite often, but I find it pretty unbelievable that we could have 10 concurrent users hitting within the same sub-second all the time.

     

    I've tried all of the suggestions on the boards.  I've dropped my receiveTimeout to 45 seconds (even took it down to 5 seconds), still didn't help.  In fact, I've played with all of the connection and configuration settings and nothing seems to help this.  I've increased my cache to the next size to get 10 connections.  Still get the connection throttling error.  I'd consider upgrading to the next level, but that's getting ridiculous.  

     

    Caching is what allows the sites like facebook and twitter to perform.  But there are millions of users hitting those sites at once.  Azure seems to have the bandwidth and cache size about right, but the connection limit seems lacking.  It might even be ok, if I could get the connections to dispose properly.

     

    The random server unavailable message that EVERYBODY seems to be encountering also seems to be pretty flaky.

     

    My question pretty much boils down to the following:

     

    Is there a way to persist my connection on my server(s) for subsequent WCF calls to reuse connections?

    Even if the object persists, I could have multiple services for different objects that would each consume a connection.  Are there any plans to increase the connection limit for multiple pages/services to reuse an existing cache?  

    Any ETA of the CTP for the caching 2.0 to go live?  Are some of these problems fixed with 2.0?

     

    Thanks,

     

    CT



    Tuesday, August 23, 2011 9:18 PM

Answers

  • Hi CriticalThinker,

    A Singleton pattern should help for reusing the DataCacheFactory. For thread-safety, you may need to implement lock mechanism for some operations in case of some weird results when the same DataCacheFactory object is used concurrently. For example:

    public static class DataCacheFactorySingleton
    {
      static DataCacheFactory _instance = null;
      static readonly object sync = new object();
      public static DataCacheFactory Instance
      {
        get
        {
          lock (sync)
          {
            if (_instance == null)
            {
              // Code to configure and create a DataCacheFactory instance.
              // ...
    
              _instance = new DataCacheFactory();
            }
            return _instance;
          }
        }
      }
    }
    

    Additional reading: Implementing the Singleton Pattern in C#.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Wenchao Zeng Thursday, September 1, 2011 8:49 AM
    Thursday, August 25, 2011 7:40 AM

All replies

  • Hi CriticalThinker,

    From your description, it seems that you are using Azure AppFabric Cache in your local web server. If so, I don't think it is recommended as there will be a latency between on-premise servers and Azure servers that slows down the performance.

    > Is there a way to persist my connection on my server(s) for subsequent WCF calls to reuse connections? Are there any plans to increase the connection limit for multiple pages/services to reuse an existing cache?

    By the way, to reuse the connection, you can store a DataCacheFactory instance in a static member and reuse it. For example:

        public static class DataCacheFactorySingleton
        {
            static DataCacheFactory _instance;
            public static DataCacheFactory Instance
            {
                get
                {
                    if (_instance == null)
                    {
                        // Code to configure and create a DataCacheFactory instance.
                        // ...

                        _instance = new DataCacheFactory();
                    }

                    return _instance;
                }
            }
        }

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Wednesday, August 24, 2011 9:54 AM
  • Thanks for the reply.  I realize this isn't ideal.  But we're transitioning from our local servers to Azure.  We implemented caching and didn't to use a local cache because we're not going to set up any new servers.  Now we just have to move the web code over to azure as well.  

     

    Btw... the caching is still more effecient than our db hit and is still subsecond when it works.  

    Wednesday, August 24, 2011 3:36 PM
  • Hi CriticalThinker,

    A Singleton pattern should help for reusing the DataCacheFactory. For thread-safety, you may need to implement lock mechanism for some operations in case of some weird results when the same DataCacheFactory object is used concurrently. For example:

    public static class DataCacheFactorySingleton
    {
      static DataCacheFactory _instance = null;
      static readonly object sync = new object();
      public static DataCacheFactory Instance
      {
        get
        {
          lock (sync)
          {
            if (_instance == null)
            {
              // Code to configure and create a DataCacheFactory instance.
              // ...
    
              _instance = new DataCacheFactory();
            }
            return _instance;
          }
        }
      }
    }
    

    Additional reading: Implementing the Singleton Pattern in C#.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Wenchao Zeng Thursday, September 1, 2011 8:49 AM
    Thursday, August 25, 2011 7:40 AM
  • Hi,

    I will mark the reply as answer. If you find it no help, please feel free to unmark it and follow up.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Thursday, September 1, 2011 8:49 AM