none
Local Cache vs Host Cache - Performance Issues

    Question

  • With reference to the original thread here, I had some additional questions. Here is our application scenario in more detail

    We have a WCF service(Service - A) that returns a list of records. Due to the volume of records and the quick response required, we decided to use Appfabric as a caching mechanism between the WCF service and another WCF service(Service - B) that is the source of records.

    Our WCF methods check for the data in the Cache first and if the data is there, it just returns whatever is in the Cache. If the data is not found in the Cache, it retrieves it from Service-B and also sets the same data in the Cache. To achieve faster response times, we also use the local cache feature of the Appfabric using a time-out based expiry of 30 minutes. We have another windows service running that gets the data from Service-B and updates the same item in the cache on a timely interval of 30 minutes. This helps us constantly update the cache and the Service-A always gets the data from the Cache and never has to hit Service-B. 

     

    Issues

    1. We were ready for a staleness of data for about 30 minutes, but as per the worse case for the above scenario, it can be stale for about an hour. Can we not get a notification some way that the local cache needs to update itself since the host cache data has changed? The service response is about 0.03 seconds for a local cache fetch, but is about 2-3 seconds if the fetch is from the cache host. This is very slow for our requirements.

     

    2. We don't want to reduce the refresh frequency of the local cache, because when we do that, the first call to the service takes 2-3 seconds and then the subsequent responses are faster until the next refresh. We cannot have a situation where the application slows down by a magnitude of 100, for the first WCF service call. Ideally I wanted the local cache to never expire and wanted a notification based expiry mechanism where it'd refresh itself as soon as the Cache host is updated. Is there a way to achieve this?

    3. When a local cache expires, can we just do something that it refreshes itself automatically with the data and not on the first request to it. This is important to us since our Service-A checks for data in the Cache, and the first fetch after a local cache expiry is expensive in terms of the time taken, by a magnitude of at least 100 and some times 200 or more.

     

    Due to performance concerns in our scenario, we are in the process of ruling out Appfabric and use the database or another 3rd party Caching framework as the Caching mechanism for our application scenario. I was quite happy with the Appfabric Caching framework. It's just the limitation of the local Cache vs Host Cache update mechanism that is impeding my application performance. By the way, we are not using Appfabric as a Cache Cluster as of now. We are just using it as a Cache host. We plan to use the clustering mechanism in the next version.

     

     

     

    Any suggestions/comments on this would be immensely helpful.

     

     



    Wednesday, June 01, 2011 2:10 PM

Answers

  • How do you get the notification that the host cache has updated? Do you hook on to the caching events programatically and then update the local ConcurrentDictionary? I ask this because the notification based mechanism will only expire the local cache whenever there is an update, but it won't pre-emptively fill it up will new data. Would subscribing to the events help in any way? As I believe, I cannot do explicit update operations on the local cache in any way... Correct me if I am wrong.
    Notifications for OOTB local cache invalidate the local object. Instead, I subscribe to those same notifications, and when get an add or replace notification, or remove, I pre-emptively/proactively update the local ConcurrentDictionary.
    Microsoft Community Contributor MCTS: .NET 4.0 Service Communication Applications
    Wednesday, June 01, 2011 6:52 PM

All replies

  • With reference to the original thread here, I had some additional questions. Here is our application scenario in more detail

    We have a WCF service(Service - A) that returns a list of records. Due to the volume of records and the quick response required, we decided to use Appfabric as a caching mechanism between the WCF service and another WCF service(Service - B) that is the source of records.

    Our WCF methods check for the data in the Cache first and if the data is there, it just returns whatever is in the Cache. If the data is not found in the Cache, it retrieves it from Service-B and also sets the same data in the Cache. To achieve faster response times, we also use the local cache feature of the Appfabric using a time-out based expiry of 30 minutes. We have another windows service running that gets the data from Service-B and updates the same item in the cache on a timely interval of 30 minutes. This helps us constantly update the cache and the Service-A always gets the data from the Cache and never has to hit Service-B. 

     

    Issues

    1. We were ready for a staleness of data for about 30 minutes, but as per the worse case for the above scenario, it can be stale for about an hour. Can we not get a notification some way that the local cache needs to update itself since the host cache data has changed? The service response is about 0.03 seconds for a local cache fetch, but is about 2-3 seconds if the fetch is from the cache host. This is very slow for our requirements.

     

    2. We don't want to reduce the refresh frequency of the local cache, because when we do that, the first call to the service takes 2-3 seconds and then the subsequent responses are faster until the next refresh. We cannot have a situation where the application slows down by a magnitude of 100, for the first WCF service call. Ideally I wanted the local cache to never expire and wanted a notification based expiry mechanism where it'd refresh itself as soon as the Cache host is updated. Is there a way to achieve this?

    3. When a local cache expires, can we just do something that it refreshes itself automatically with the data and not on the first request to it. This is important to us since our Service-A checks for data in the Cache, and the first fetch after a local cache expiry is expensive in terms of the time taken, by a magnitude of at least 100 and some times 200 or more.

     

    Due to performance concerns in our scenario, we are in the process of ruling out Appfabric and use the database or another 3rd party Caching framework as the Caching mechanism for our application scenario. I was quite happy with the Appfabric Caching framework. It's just the limitation of the local Cache vs Host Cache update mechanism that is impeding my application performance. By the way, we are not using Appfabric as a Cache Cluster as of now. We are just using it as a Cache host. We plan to use the clustering mechanism in the next version.

     

     

     

    Any suggestions/comments on this would be immensely helpful.

     

     



    Use notification based invalidation instead of timeout based. Then adjust your client polling interval to reflect needs/goals. However AppFabric's local cache will not refresh itself preemptively -- it is demand-based -- implicit cache-aside pattern. I replaced the local cache with a ConcurrentDictionary and use cache notifications, along with a DB-driven list of keys paired with data update timestamps, to maintain consistency.
    Microsoft Community Contributor MCTS: .NET 4.0 Service Communication Applications
    Wednesday, June 01, 2011 5:56 PM
  • How do you get the notification that the host cache has updated? Do you hook on to the caching events programatically and then update the local ConcurrentDictionary? I ask this because the notification based mechanism will only expire the local cache whenever there is an update, but it won't pre-emptively fill it up will new data. Would subscribing to the events help in any way? As I believe, I cannot do explicit update operations on the local cache in any way... Correct me if I am wrong.
    Wednesday, June 01, 2011 6:44 PM
  • How do you get the notification that the host cache has updated? Do you hook on to the caching events programatically and then update the local ConcurrentDictionary? I ask this because the notification based mechanism will only expire the local cache whenever there is an update, but it won't pre-emptively fill it up will new data. Would subscribing to the events help in any way? As I believe, I cannot do explicit update operations on the local cache in any way... Correct me if I am wrong.
    Notifications for OOTB local cache invalidate the local object. Instead, I subscribe to those same notifications, and when get an add or replace notification, or remove, I pre-emptively/proactively update the local ConcurrentDictionary.
    Microsoft Community Contributor MCTS: .NET 4.0 Service Communication Applications
    Wednesday, June 01, 2011 6:52 PM