Appfabric local cache vs host cache

Réponse proposée Appfabric local cache vs host cache

  • 2012年4月6日 下午 04:57
     
     

    I have configured appfabric cache using XML with lcoal cache enabled. When first time a call is made it stored in host and in subsequent calls local cache is used.

    1. How do I know (subsequent calls) are not going to host and is being used from local cache ?

    2. What is the maximum no of cache objects that can be stored in local cache (Default is 10000)

    3. When using configuration model do we still need some programming for local cache ?

    Thanks,

    Sri

所有回覆

  • 2012年4月7日 上午 03:04
     
     

    1. How do I know (subsequent calls) are not going to host and is being used from local cache ?

    There is not easy way to know, one of the things that I did to prove was working was simple, using a profiler. Doing the connection to the host and retrieving the items from the cache is a 'sort of expensive' operation (especially with big data items). Take a look with your profiler and you'll see the difference. Another option is just to look at network traffic using a tool like TCPView from sysinternals. If you are not using the local cache you'll see the traffic from the AppFabric cache to your application for every request.

    2. What is the maximum no of cache objects that can be stored in local cache (Default is 10000)

    You can configure this with your application configuration, take a look at the objectCount parameter, the limit is of course how many local memory you can handle (this is for the process with the local cache), and of course every arch has memory limits. You can also control expiration time and expiration mode.

    3. When using configuration model do we still need some programming for local cache ?

    No, enough with specify the local cache in the client configuration, this will work transparently.

    Take a look (if you haven't yet) to the local cache configuration document:

    http://msdn.microsoft.com/en-us/library/ee790880.aspx

    One of the things I found interesting is that with big datasets and compression and local cache enabled, you would save a lot of CPU cycles waiting for the data to transfer from the cache server.


  • 2012年4月9日 下午 12:30
     
     
    1. One possible approach is to check the performance counters for total operations on the server(s). With local cache serving some of the requests on the client, the perf counters ought to show lower values with local cache enabled. A more approach that can be used to verify that local cache is indeed working would be to calculate end-to-end latencies for each operation. Local cache and server operation latencies ought to be orders of magnitude different.
    2. You can change the default to whatever you want, only that it should be within the limits of your available system memory on the client. There is no limit imposed by AppFabric Cache. If you object sizes are in the order of MBs, and you have a local cache with 100,000 operations on a cache client with, say, 4 GB RAM, older items in your local cache might keep getting evicted to ease physical memory pressure and your performance may suffer.
    3. No, there is no extra code necessary for using local cache.

    The link shared out by cpreito provides more information on the topic.

    -Arijit

  • 2012年4月9日 下午 02:43
     
     

    Thank you cpreito and Arijit For my first question I have checked TCP traffic with TCPView and found some interseting stats, I have my local cache enabled with timout based ttlvalue of 600, and I have one host with 2 max connections.

    Process    Rmt Address PID Protocol Sent Packets Sent Bytes Received Packets Rcvd Bytes  

    w3wp.exe -------         2460 TCP      159              364,850     314                    88,629  Load First call
    w3wp.exe -------         2460 TCP      165              372,596     554                    582,283  Second Call
    w3wp.exe -------         2460 TCP      169              376,804     714                    911,186  Third Call

    Without Local cache

    w3wp.exe -------         6828 TCP      176              421,760     356                    98,650  Load First call
    w3wp.exe -------         6828 TCP      180              426,924     516                    427,761  Second Call
    w3wp.exe -------         6828 TCP      181              428,215     556                    510,188  Third Call

    sent and received bytes between client and host is more when using local cache (I havent added 2 connection stats which also shows similar to above) any thoughts please ?

    -Sri


    Srinivas Peasapati

  • 2012年4月9日 下午 02:57
     
     

    Hi Srinivas,

    How many Get/Write (Put/Add...) requests are you using in either case? Also, would it be possible for you to share out the cache client benchmarking code? My tests show the network traffic to be far lower with local cache enabled for the same number of client operations reusing a large subset of keys in a defined time period.

    Thanks,
    Arijit

  • 2012年4月9日 下午 03:29
     
      包含代碼

    Hi Arijit,

    we have main list object (say Products) which drives the application, intial call check if there is data in cache if not gets and from database and puts in cache, all subsequent calls use GetObjectBytag.

    In pagebase class we have have something like this

    public Product GetProduct(string prodcutId)
            {
                Product product;
                product = GetProdcuts().Where(z => z.prodcutId == prodcutId).ToArray().FirstOrDefault();
                return product;
            }
    
            public Product[] GetProducts()
            {
                Product[] products;
                products = ProductCacheObject.GetProducts();
                return products;
            }

    ProductCacheObject is a cache library dll

    public static Products[] GetProducts()
            {
                Product[] products = null;
                products = dataCache
                    .GetObjectsByTag(ProductsTag, Region)
                    .Cast<Product>()
                    .ToArray();
    
                if (!products.Any())
                    products = GetProductList(); -- Gets from database and puts in cache
    
                return products;
            }

    Thanks,

    Srinivas


    Srinivas Peasapati


    • 已編輯 Peasapati S 2012年4月9日 下午 03:29 nothing
    •  
  • 2012年4月9日 下午 03:54
     
     提議的解答 包含代碼

    Hi Srinivas,

    GetObjectsByTag skips the local cache and makes a direct server call. The reason being that it is impractical to maintain a local tag-index enumeration in sync with the server.

    Cache is optimized for CRUD operations on keys. The queries which you've written are inefficient for that reason. I do have a few concerns:

    1. You're storing all 'Products' in a single region. Since regions are stored on a single server, this may hinder you from scaling out.
    2. The GetProduct gets all products from the server and runs a query on the client. If you have 1000 products, you'll end up copying 1000 products from the server to the client to get a single product. Consider indexing individual Product by key/tag instead. [This may be less of a problem depending on your scenario.]
    3. You're accessing the product list by tags. It would be preferable to access it by key instead.

    For 3, the updated code block might look like:

    public static Products[] GetProducts()
    {
        Product[] products = (Products[])dataCache.Get("products")
    
        if (!products.Any())
           products = GetProductList(); // Gets from database and puts in cache key "products" as an array
    
        return products;
    }

    Thanks,
    Arijit

  • 2012年4月9日 下午 04:58
     
     

    Thanks for information hope this are my final question. When Product is dropdown list then GetProducts should return all the products

    when putting the cache dataCache.Put(z => z.ProductId, list, ProductsTag)

    datacache.Get("products") returns only 1 object (correct me if I am wrong) so we are using GetObjectByTag which requires region. In such case we can not store this in local cache since tags skip the local cache.


    Srinivas Peasapati

  • 2012年4月10日 上午 09:55
     
     
    I'm sorry I don't follow the syntax dataCache.Put(z => z.ProductId, list, ProductsTag). My recommendation would be to store the entire array using Put/Add in a single object and retrieve it using Get.