39

Windows Server AppFabric Caching - What it is & when you should use it?

Embed Size (px)

DESCRIPTION

This is from my Tech-Ed Africa 2010 talk. For more information see: http://www.sadev.co.za/content/teched-africa-2010-slides-scripts-and-demos-my-talks This session looks at what AppFabric Caching is from start to deep dive.

Citation preview

Page 1: Windows Server AppFabric Caching - What it is & when you should use it?
Page 2: Windows Server AppFabric Caching - What it is & when you should use it?

Robert MacLeanTechnology SpecialistBB&D

Windows Server AppFabric Caching: What it is & When you should use it?

Page 3: Windows Server AppFabric Caching - What it is & when you should use it?

3

Who am I?

Robert MacLeanMicrosoft ALM MVPMicrosoft ALM RangerProud Community Lead

Information WorkerS.A. Architect

www.sadev.co.za@rmaclean

Page 4: Windows Server AppFabric Caching - What it is & when you should use it?

4

Overture

Level 300State of playBriefly what is AppFabric?What do we get from AppFabric Caching and how to use it!

Page 5: Windows Server AppFabric Caching - What it is & when you should use it?

5

Advert Time

AppFabric:Wed, 11:15pm - WCF Made Easy with .NET 4 and Windows Server AppFabric

Other:Wed, 8:30pm - Tales From the field – Best practices and guidance on implementing TFS2010

Page 6: Windows Server AppFabric Caching - What it is & when you should use it?

6

State of play

.NET prior to 4ASP.NET CachingEnterprise Library Caching

.NET 4 brings us.NET 4 Caching

All are local in-memory caches!

Page 7: Windows Server AppFabric Caching - What it is & when you should use it?

.NET 4 Caching

Demo

Page 8: Windows Server AppFabric Caching - What it is & when you should use it?

8

What is the issue with these?

Limited to memory of current machineLimited to current process

Imagine if I need 50Gb of cache?What about load balancing?

Page 9: Windows Server AppFabric Caching - What it is & when you should use it?

9

A rose by any other name…

Windows Server AppFabric contains two key componentsHosting

EndPoint, Windows App Server Extensions, DublinCaching

VelocityNot to be confused with Azure AppFabric

Page 10: Windows Server AppFabric Caching - What it is & when you should use it?

10

N.B. AppFabric

Requires .NET 4 on ServerNot all applications need .NET 4, depends on features used

Standalone download or Web Platform InstallerHigh Availability is only in Windows Server 2008 Enterprise & Data Centre

Page 11: Windows Server AppFabric Caching - What it is & when you should use it?

11

What is AppFabric Cache?

An in-memory distributed cache which you can call from any .NET applicationOptimised for the cache-aside pattern

Programming against the cache is explicitChanging the cache doesn’t update the original data store

Page 12: Windows Server AppFabric Caching - What it is & when you should use it?

12

AppFabric Cache Single View

Cache Server

Single view from code

Cache Server

Cache Server

Services

Data 1

Data 2

Data 3

Data 4

Cache Server

Page 13: Windows Server AppFabric Caching - What it is & when you should use it?

13

AppFabric Caching Info

Common Configuration StoreXMLDatabase

Runs as Windows ServiceCommunication Between Nodes

WCF net.tcpSelf Adjusting

Page 14: Windows Server AppFabric Caching - What it is & when you should use it?

14

AppFabric Server Types

Dedicated Cache ServerAll it does is AppFabric caching – good for lots of memory and great performation

Hybrid Cache ServerRuns AppFabric caching & other tools. SQL + AppFabricWeb + AppFabric

Local Cache ServerRuns AppFabric per application locallyUsed in conjunction with hybrid and/or dedicated

Page 15: Windows Server AppFabric Caching - What it is & when you should use it?

15

What can I cache?

Anything that can be serialisedXMLPOCOBinary Data

Page 16: Windows Server AppFabric Caching - What it is & when you should use it?

16

Data Cache Planning

Reference DataCities, provinces, product info, etc…

Activity DataSession, per user etc..

Resource DataData with contention We will look at this more later…

NB: Plan, plan and plan some more

Page 17: Windows Server AppFabric Caching - What it is & when you should use it?

17

Management

All Configuration and Administration is done via PowerShell

From the MVP’s: http://mdcadmintool.codeplex.com/

Page 18: Windows Server AppFabric Caching - What it is & when you should use it?

AppFabric from IT Pro to Developer

Demo

Page 19: Windows Server AppFabric Caching - What it is & when you should use it?

19

Cache Structure ReviewServer Server Server

Named Cache: Default

Named Cache: Products

Named Cache: UsersRegion: Male

Region: Female

Items & Tags

Page 20: Windows Server AppFabric Caching - What it is & when you should use it?

20

Expiration of cache items

Put & AddTimeout

NotificationPolling Default: 300 secs

Expiration timeout defaults can be controlled on a cache level

Page 21: Windows Server AppFabric Caching - What it is & when you should use it?

21

Eviction

@ Low watermarkExpired items removed

@ High watermarkItems, expired or not, can be removed or allocated to another serverItems picked by using LRU Can disable if needed

Page 22: Windows Server AppFabric Caching - What it is & when you should use it?

22

ORM’s

Some ORM’s implement second level cachingIt is possible to change the second level to AppFabricExamples: NHibernate & Entity Framework

Page 23: Windows Server AppFabric Caching - What it is & when you should use it?

23

A Problem with Caching

DBAppFabric

Cache

ATM

ORM UI

ATM

ORM UI

Name : RobertBalance: 15

Name : RobertBalance: 15

Name : RobertBalance: 1500

Page 24: Windows Server AppFabric Caching - What it is & when you should use it?

24

Solution

.GetAndLock

.PutAndUnlock

.Unlock

Supports locking timeoutLocked items can survive expiration

Unlock can prolong expiration

Page 25: Windows Server AppFabric Caching - What it is & when you should use it?

25

Data Cache Planning

Reference DataCities, provinces, product info, etc…

Activity DataSession, per user etc..

Resource DataData with contention

NB: Plan, plan and plan some more

Great with defaults

Region per user

Locking per item

Page 26: Windows Server AppFabric Caching - What it is & when you should use it?

26

Cluster Configuration

First node initialises clusterOther nodes join

During install you must configure projected sizeSmall: 1 – 5 nodes Medium: 6 – 15 nodesLarge: > 15 nodes

Performance based on this setting – adding/removing nodes does not effect this

Page 27: Windows Server AppFabric Caching - What it is & when you should use it?

27

Security

Domain:Authentication in AD, Authorisation in AppFabricOnly authorised servers join clustersOnly authorised clients connect to clusters

WorkgroupAuthentication in network share, Authorisation in AppFabric

Transport Level SecuritySigning and Encryption

Page 28: Windows Server AppFabric Caching - What it is & when you should use it?

28

Typical Web Architecture

DB

Web

Se

rver

sU

sers

StateState State Load Balancer

Page 29: Windows Server AppFabric Caching - What it is & when you should use it?

29

ASP.NET

Out of the box caching InProc (Default)StateServerSQLServerAll can be enabled by via config change

Now AppFabric support also just a config change

Page 30: Windows Server AppFabric Caching - What it is & when you should use it?

30

ASP.NET AppFabric Config<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.FileEventSink,FabricCommon" sinkParam="DcacheLog/dd-hh-mm" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon“ sinkName="Microsoft.Data.Caching.ETWSink, CacheBaseLibrary“ sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

Page 31: Windows Server AppFabric Caching - What it is & when you should use it?

31

ASP.NET AppFabric Config<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.FileEventSink,FabricCommon" sinkParam="DcacheLog/dd-hh-mm" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon“ sinkName="Microsoft.Data.Caching.ETWSink, CacheBaseLibrary“ sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary"

allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true"

allowDefinition="Everywhere"/>

</configSections>

Page 32: Windows Server AppFabric Caching - What it is & when you should use it?

32

ASP.NET AppFabric Config<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.FileEventSink,FabricCommon" sinkParam="DcacheLog/dd-hh-mm" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon“ sinkName="Microsoft.Data.Caching.ETWSink, CacheBaseLibrary“ sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

Page 33: Windows Server AppFabric Caching - What it is & when you should use it?

33

ASP.NET AppFabric Config<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.FileEventSink,FabricCommon" sinkParam="DcacheLog/dd-hh-mm" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon“ sinkName="Microsoft.Data.Caching.ETWSink, CacheBaseLibrary“ sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon"

sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

Page 34: Windows Server AppFabric Caching - What it is & when you should use it?

34

ASP.NET AppFabric Config<configSections>

<section name="dataCacheClient“ type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>

<section name="fabric“ type="System.Data.Fabric.Common.ConfigFile, FabricCommon“ allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

<dataCacheClient deployment="routing">

<localCache isEnabled="false"/>

<hosts>

<host name="localhost" cachePort="22233“ cacheHostName="DistributedCacheService"/>

</hosts>

</dataCacheClient>

<fabric>

<section name="logging" path="">

<collection name="sinks" collectionType="list">

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Fabric.Common.FileEventSink,FabricCommon" sinkParam="DcacheLog/dd-hh-mm" defaultLevel="-1"/>

<customType className="System.Data.Fabric.Common.EventLogger,FabricCommon“ sinkName="Microsoft.Data.Caching.ETWSink, CacheBaseLibrary“ sinkParam="" defaultLevel="-1"/>

</collection>

</section>

</fabric>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

<system.web>

<sessionState mode="Custom" customProvider="Velocity">

<providers>

<add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider,

ClientLibrary" cacheName="session"/>

</providers>

</sessionState>

</system.web>

Page 35: Windows Server AppFabric Caching - What it is & when you should use it?

35

Summary

Windows Server AppFabric Cache is a distributed application cacheCaching is important to application scalabilityExplicit caching API available to .NET 3.5 SP1 and .NET 4.0ASP.NET Session provider an implicit way to take advantage of the Cache’s capabilitiesPlan, plan and plan some more

Page 36: Windows Server AppFabric Caching - What it is & when you should use it?

36

[email protected] @rmaclean

Meet me at the community lounge

Page 37: Windows Server AppFabric Caching - What it is & when you should use it?

37

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

SMS [ Your Name ] and the word “AppServer” to 41491Need more Information?

Page 38: Windows Server AppFabric Caching - What it is & when you should use it?

Complete an evaluation via CommNet and Tag to win amazing prizes!

Page 39: Windows Server AppFabric Caching - What it is & when you should use it?

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED

OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.