verteiltes caching mit windows server appfabric
DESCRIPTION
Verteiltes Caching mit Windows Server AppFabric. Ingo Rammer thinktecture [email protected]. Unterstützung und Consulting von Software- Entwicklern und – Architekten im Windows- und .NET- Umfeld Entwickler -Coaching und –Mentoring Architektur -Consulting und –Prototyping - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/2.jpg)
Ingo Rammer und thinktecture
Unterstützung und Consulting von Software-Entwicklern und –Architekten im Windows- und .NET-Umfeld
• Entwickler-Coaching und –Mentoring• Architektur-Consulting und –Prototyping• Architektur- und Code-Reviews• Anwendungsoptimierung, Troubleshooting, Debugging
http://[email protected]
![Page 3: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/3.jpg)
Caching in 30 Seconds
•AppFabric Caching (Velocity) is a Windows Service for highly scalable distributed caching•Multiple physical nodes are combined to form one big virtual cache
![Page 4: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/4.jpg)
So first … let‘s start the virtual machines …
![Page 5: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/5.jpg)
WebServer #1
WebServer #2
WebServer #3
WebServer #n
Load Balancer
Data
User
![Page 6: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/6.jpg)
Web Server
Data
Application
Session State
LocalCaching
![Page 7: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/7.jpg)
Today‘s Issues
Session stateInProc, Session server, database?Availability, Single-Point-Of-Failure, Performance
CachingCache consistency when using multiple servers
![Page 8: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/8.jpg)
WebServer
#1
WebServer
#2
WebServer
#3
WebServer
#n
Load Balancer
CacheServer
#1
CacheServer
#2
AppFabric Caching
![Page 9: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/9.jpg)
WebServer
#1
WebServer
#2
WebServer
#3
WebServer
#n
Load Balancer
CacheServer #1
CacheServer
#2
![Page 10: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/10.jpg)
Configuring AppFabric
AdministrationPowershellCluster config centrally in XML file or in SQL Server
![Page 11: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/11.jpg)
Notebook directly: Windows 7 with IIS and Visual StudioFour virtual machines:
VCacheDC
Domain ControllerSQL Server
VCache01
AppFabric
VCache02
AppFabric
VCache03
AppFabric
![Page 12: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/12.jpg)
Named Caches
VCache01 VCache02 VCache03Cache: default
Cache: sessiondata
Additional caches … with different configuration
![Page 13: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/13.jpg)
Cache Administration
Administration via PowershellLoading the module
Import-Module DistributedCacheAdministrationGet-CacheHelp
Creating a new cache: New-Cache democacheStarting the Cluster: Start-CacheClusterStatus: Get-CacheHost
![Page 14: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/14.jpg)
AppFabric Caching w/o Security
Export-CacheClusterConfig c:\test.xmlAdd advancedProperties
Import-CacheClusterConfig c:\test.xml
<dataCache> <advancedProperties> <securityProperties mode="None" protectionLevel="None" /> </advancedProperties> <caches>…</caches> <hosts>…</hosts></dataCache>
![Page 15: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/15.jpg)
AppFabric Caching „Hello World“
Configuring the client
<configuration> <configSections> <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></configSections>
<dataCacheClient> <hosts> <host name="VCache01" cachePort="22233“ /> </hosts> <securityProperties mode="None" protectionLevel="None"/></dataCacheClient>
![Page 16: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/16.jpg)
AppFabric Caching „Hello World“
•Adding References from C:\Windows\System32\AppFabricMicrosoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.CoreHave to be copied first
DataCacheFactory fact = new DataCacheFactory();DataCache myCache = fact.GetCache("democache2");
string someKey = "myKey";string someValue = "testing"; // anything [Serializable]
myCache.Put(someKey, someValue);
string result = (string) myCache[someKey];
![Page 17: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/17.jpg)
VCache01 VCache02 VCache03
Cache: default
Storing and Distribution.NET Client
Prod-1Prod-2
Prod-4 Prod-3
DataCache defaultcache = GetCache("default");Product prod = GetProduct(...);defaultcache.Put("Prod-1",prod);
defaultcache.Put("Prod-2",prod2);defaultcache.Put("Prod-3",prod3);defaultcache.Put("Prod-4",prod4);
Other named caches …
![Page 18: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/18.jpg)
Scaling the Cache
Scaling sizeMore machines == more memory
Scaling throughputMore machines == higher throughput
„Local Cache“Directly at client == massively lower latencyHigher throughput when readingBut also: items are older, can get stale
![Page 19: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/19.jpg)
Item Routing
Velocity #1 Velocity #2 Velocity #3
Prod-1
.NET ClientDynamic Routing
Table
Prod-2Prod-4
Prod-3
defaultcache.Put("Prod-1",prod);
![Page 20: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/20.jpg)
Node Failure
Velocity #1 Velocity #2 Velocity #3
Prod-1
.NET ClientDynamic Routing
Table
Prod-2
Prod-4Prod-3
object p1 = defaultcache["Prod-1"];object p1 = defaultcache["Prod-1"];
if (p1==null){ p1 = GetProductFromDatabase(...) defaultcache.Put("Prod-1", p1);}
Prod-1
![Page 21: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/21.jpg)
Regions and Tags
•Optional•All elements in a region live on the same node•Can be tagged•Allow BulkGet and bulk delete
![Page 22: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/22.jpg)
Kinds of Data
Reference Data: "never" changes (catalog data, price lists, …)Activity data: non-concurrent changes (session data, shopping cart, …)Resource data: high concurrency data, constantly changing (inventory level, …)
![Page 23: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/23.jpg)
Analysing DataPerformance – Throughput and latencyConsistency – Guaranteed or eventualRecoverability – Can the data be restored from DB (cache eviction?)Availability – What happens at node failure
![Page 24: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/24.jpg)
Local CacheChosen in config or codeIn practice: often code, because only specific parts should be cached locally (DataCacheFactory)Good for reference dataSynchronization
Age of itemsNotification
![Page 25: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/25.jpg)
Notifications
Pub/sub on cache item changesCallbacks for complete cache, for a region or for a single itemAre currently (beta 2) queued at server side and regularily polled by the clientCache has to be configured for notifications
New-Cache <name> -NotificationsEnabled true
![Page 26: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/26.jpg)
Concurrency
•Optimistic and pessimistic locking
DataCacheItemVersion ver = default(DataCacheItemVersion);object itm = defaultCache.Get("region", "key", ref ver);
// after change (throws an exception if modified in meantime)defaultCache.Put("region","key", itm, ver);
DataCacheLockHandle lockHandle;object itm = defaultCache.GetAndLock("region", "key", TimeSpan.FromSeconds(30), out lockHandle);
// after change:defaultCache.PutAndUnlock("region", "key", itm, lockHandle, null);
![Page 27: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/27.jpg)
Session State
<sessionState mode="Custom" customProvider="Velocity"> <providers> <add name="Velocity" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider, Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" cacheName="sessiondata" retryCount="5"/>
</providers></sessionState>
![Page 28: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/28.jpg)
High Availability
Velocity #1 Velocity #2 Velocity #3
Sess-1(Primary)
sessionCache.put("Sess-1", se1);
Sess-1 (Secondary)
Sess-2(Primary)
Sess-2 (Secondary)
sessionCache.put("Sess-1", se1);sessionCache.put("Sess-2", se2);
![Page 29: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/29.jpg)
Failover with High Availability
Velocity #1 Velocity #2 Velocity #3
Sess-1(Primary)
sessionCache.put("Sess-1", se1);
Sess-1 (Secondary)
Sess-2(Primary)
Sess-2 (Secondary)
sessionCache.put("Sess-1", se1);sessionCache.put("Sess-2", se2);
Sess-2(Primary)Sess-2 (Secondary)
Sess-1(Secondary)
![Page 30: Verteiltes Caching mit Windows Server AppFabric](https://reader035.vdocuments.site/reader035/viewer/2022062305/568160f2550346895dd029b2/html5/thumbnails/30.jpg)
Configuring High Availability
•Powershell• New-Cache <name> -Secondaries 1 •Maybe also:• –Eviction None • –NotExpirable trueStarting with Beta2: Only supported on Enterprise (and Data Center) operating system editions