azure appfabric caching intro and tips

18

Click here to load reader

Upload: sachin-sancheti

Post on 13-May-2015

5.913 views

Category:

Technology


0 download

DESCRIPTION

Introduction, Gotchas and Guidelines while using Windows Azure AppFabric Caching service.

TRANSCRIPT

Page 1: Azure appfabric caching intro and tips

Page 1

www.cumulux.com

Azure App Fabric Caching

Sachin Sancheti

[email protected]

www.cumulux.com

www.cumulux.com

Page 2: Azure appfabric caching intro and tips

Page 2 www.cumulux.com

• Introduction to Azure App Fabric Cache

• Configuration and Usage

• Session State Provider Gotchas

• Tracing

• Understanding Quota & Common Errors

• Local Cache option

• Limitations of Azure Appfabric Cache

• Guidelines

Page 3: Azure appfabric caching intro and tips

Page 3 www.cumulux.com

• The Caching service – is a distributed, in-memory, application cache that can be used to

accelerate the performance of Windows Azure applications

– Provided as “PaaS”

– Built on top of Windows Server

Appfabric Cache (Velocity)

• Caching Usage – Frequently Accessed Data Caching

– ASP.Net Session State

– ASP.Net Output Caching

Page 4: Azure appfabric caching intro and tips

Page 4 www.cumulux.com

• Configuration (.config) – Portal Demo

• Login to Windows Azure Portal

• Create/Select the cache namespace

• Click on View Client Configuration

• This configuration provides instructions to configure Azure AppFabric

caching for data caching

– Session State Provider

– Output Caching

– .config based configuration

Page 5: Azure appfabric caching intro and tips

Page 5 www.cumulux.com

• Configuration (Code) – Code Block – // Declare array for cache host. DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];

– servers[0] = new DataCacheServerEndpoint("demo101.cache.windows.net", 22233);

– // Setup DataCacheSecurity configuration.

– string strACSKey = "<copy and paste security key from Azure portal or from the client configuration file>";

– var secureACSKey = new System.Security.SecureString();

– foreach (char a in strACSKey)

– {

– secureACSKey.AppendChar(a);

– }

– secureACSKey.MakeReadOnly();

– DataCacheSecurity factorySecurity = new DataCacheSecurity(secureACSKey);

– // Setup the DataCacheFactory configuration.

– DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();

– factoryConfig.Servers = servers; factoryConfig.SecurityProperties = factorySecurity;

– // Create a configured DataCacheFactory object.

– DataCacheFactory cacheFactory = new DataCacheFactory(factoryConfig);

– // Get a cache client for the default cache.

– DataCache defaultCache = cacheFactory.GetDefaultCache();

– // Add and retrieve a test object from the default cache.

– defaultCache.Add("key", "valueobject");

– string strObject = (string)defaultCache.Get("key");

Page 6: Azure appfabric caching intro and tips

Page 6 www.cumulux.com

• Usage – Data Cache (Explicit)

DataCacheFactory cacheFactory = new DataCacheFactory();

dataCache = cacheFactory.GetDefaultCache();

dataCache.Add(“key”,object,[Timeout]);

Object o = dataCache.Get(“key”);

– ASP.Net Session State (Implicit)

• .config DistributedCacheSessionStateStoreProvider

– ASP.Net Output Caching (Implicit)

• .config DistributedCacheOutputCacheProvider

Only one instance of

DataCache is created

per instance of

DataCacheFactory

and

GetDefaultCache()

returns back the

same instance each

time

2

One DataFactory

instance used per

role instance

Page 7: Azure appfabric caching intro and tips

Page 7 www.cumulux.com

• Expiration – By default, items in a Windows Azure AppFabric cache do not expire

– We can explicitly set a timeout while adding an item into the cache

• Eviction – When exceeds maximum cache size, the least recently used items in the

cache are evicted

Page 8: Azure appfabric caching intro and tips

Page 8 www.cumulux.com

• Configuration <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">

<providers>

<add name="AppFabricCacheSessionStoreProvider"

type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"

cacheName="default"

useBlobMode="true“

applicationName=“demo101”

dataCacheClientName="default" />

</providers>

</sessionState>

• Gotchas • By default, site name is considered as applicationName

– Causes issue in Development Emulator due to different site names for multiple instances

• Avoid temptation to change useBlobMode to “false”

– Microsoft Support declared it unsupported for Windows Azure

Page 9: Azure appfabric caching intro and tips

Page 9 www.cumulux.com

• Client Side Tracing – <dataCacheClient>

<tracing sinkType="DiagnosticSink" traceLevel="Verbose"/>

<!-- ... -->

</dataCacheClient>

• Request Tracking – Used by Microsoft Support to diagnose unexpected failures

– Enabling Client Side Tracing is a must

– Each request to the Windows Azure Appfabric cache has a request identifier (GUID)

attached to it. This request identifier is available from the client-side logs

Page 10: Azure appfabric caching intro and tips

Page 10 www.cumulux.com

• 128 MB cache for $45.00/month

• 256 MB cache for $55.00/month

• 512 MB cache for $75.00/month

• 1 GB cache for $110.00month

• 2 GB cache for $180.00/month

• 4 GB cache for $325.00/month

Page 11: Azure appfabric caching intro and tips

Page 11 www.cumulux.com

• Memory Quota

– Cache Size selected/updated for consumption

– Surpass Situation

• After maximum size is reached the cache item eviction would

happen with LRU algorithm

Page 12: Azure appfabric caching intro and tips

Page 12 www.cumulux.com

• Network Quota • Transactions (Reset every hour)

• Bandwidth (Reset every hour)

• Concurrent Connections (Static)

• Surpass Situation – Transactions & Bandwidth

• Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCA0017>:SubStatus<ES0009>:There is a temporary failure. Please retry later. (The request failed because user exceeded quota limits for this hour. If you experience this often, upgrade your subscription to a higher one)

– Connections • ErrorCode<ERRCA0017>:SubStatus<ES0009>:There is a temporary failure. Please retry later. (The

request failed, because you exceeded quota limits for this hour. If you experience this often, upgrade your subscription to a higher one). Additional Information : Throttling due to resource : Connections.

Cache Size Transactions

Per Hour

Bandwidth

MB Per

Hour

Concurrent

Connections

128MB 400000 1400 5

256MB 800000 2800 10

512MB 1600000 5600 20

1GB 3200000 11200 40

2GB 6400000 22400 80

4GB 12800000 44800 160

Page 13: Azure appfabric caching intro and tips

Page 13 www.cumulux.com

• Microsoft.ApplicationServer.Caching.DataCacheException:

ErrorCode<ERRCA0017>:SubStatus<ES0009>:There is a temporary failure. Please retry

later. (The request failed because user exceeded quota limits for this hour. If you

experience this often, upgrade your subscription to a higher one)

• ErrorCode<ERRCA0017>:SubStatus<ES0009>:There is a temporary failure. Please retry

later. (The request failed, because you exceeded quota limits for this hour. If you

experience this often, upgrade your subscription to a higher one). Additional Information :

Throttling due to resource : Connections.

• ErrorCode<ERRCA0017>:SubStatus<ES0006>:There is a temporary failure. Please retry

later. (One or more specified cache servers are unavailable, which could be caused

by busy network or servers. For on-premises cache clusters, also verify the following

conditions. Ensure that security permission has been granted for this client account, and

check that the AppFabric Caching Service is allowed through the firewall on all cache

hosts. Also the MaxBufferSize on the server must be greater than or equal to the

serialized object size sent from the client.)

Page 14: Azure appfabric caching intro and tips

Page 14 www.cumulux.com

• Faster Cache – Cache object is served from the local cache (if exists ) and saves a round

trip to AppFabric Cache Server

• Configuration

– <dataCacheClients>

<dataCacheClient name="default">

<localCache isEnabled=“true" ttlValue="300" objectCount="10000"/>

…….

</dataCacheClient>

• Supports only TimeoutBased cache invalidations. As of now doesn’t

support NotificationBased cache invalidations

Page 15: Azure appfabric caching intro and tips

Page 15 www.cumulux.com

• The maximum size of a post-serialized object is 8 MB

• Notifications – Notifications are not supported in Windows Azure AppFabric Caching.

This also means that you cannot use notifications to invalidate the local cache. In Windows Azure AppFabric, local cache can use only a timeout based invalidation policy

• Regions and Tags – Windows Azure AppFabric Caching does not support user-created

regions or tag-based searches

• No support for Named Cache – Supports only GetDefaultCache

• No Clear All

• No Get All

Page 16: Azure appfabric caching intro and tips

Page 16 www.cumulux.com

• Avoid only “Cache Size Based” selection, also consider bandwidth and connection quota too

• Implement Cache Aside Model – Due to Eviction policy applications should be designed to anticipate that items might be

missing and require reloading at any time.

• Decorator pattern might come handy in such scenarios where one class implements the storage with AppFabric Cache and the decorator does it for persistent storage

• Carefully Enable LocalCache – Since it doesn’t support Notifications, application might get stale data

– Generally used for reference data e.g. Country Names, Zip Codes etc.

• DataCacheFactory – Fewer the cache factories recreated better is the performance

– Do not let the DataCacheFactory object get disposed. The life of the DataCache object is tied to the DataCacheFactory object

– Only one instance of DataCache is created per instance of DataCacheFactory and GetDefaultCache() returns back the same instance each time

Page 17: Azure appfabric caching intro and tips

Page 17 www.cumulux.com

• Plan for Quotas – Transaction, Bandwidth Limits

• Implement Cache Aside Policy

• Be aware while load testing and plan accordingly

– Connection Limits • Each DataCacheFactory can create a number of connections. By

default, a single DataCacheFactory will only create one connection

• maxConnectionsToServer – Specifies the maximum number of channels to open to the cache

cluster

– <dataCacheClient name="default" maxConnectionsToServer=“2">

• Singleton implementation would help implement one connection per web role instance for DataCacheFactory

• Do not forget the implicit connections consumed by providers (Session and Output Cache providers)

Page 18: Azure appfabric caching intro and tips

Page 18

www.cumulux.com

Q & A

Thank You