300 likes | 437 Views
Verteiltes Caching mit Windows Server AppFabric. Ingo Rammer thinktecture ingo.rammer@thinktecture.com. Unterstützung und Consulting von Software- Entwicklern und – Architekten im Windows- und .NET- Umfeld Entwickler -Coaching und –Mentoring Architektur -Consulting und –Prototyping
E N D
Verteiltes Caching mit Windows Server AppFabric Ingo Rammer thinktecture ingo.rammer@thinktecture.com
Unterstützung und Consulting von Software-Entwicklernund –Architektenim Windows- und .NET-Umfeld Entwickler-Coaching und –Mentoring Architektur-Consulting und –Prototyping Architektur- und Code-Reviews Anwendungsoptimierung, Troubleshooting, Debugging http://www.thinktecture.com ingo.rammer@thinktecture.com Ingo Rammer und thinktecture
AppFabric Caching (Velocity) is a Windows Service forhighlyscalabledistributedcaching Multiple physicalnodesarecombined to form onebigvirtualcache Caching in 30 Seconds
User Load Balancer WebServer #1 WebServer #2 WebServer #3 WebServer #n Data
Web Server Application Local Caching Session State Data
Session state InProc, Session server, database? Availability, Single-Point-Of-Failure, Performance Caching Cache consistencywhenusing multiple servers Today‘sIssues
Load Balancer CacheServer #1 WebServer #1 WebServer #2 WebServer #3 WebServer #n AppFabric Caching CacheServer #2
Load Balancer WebServer #1 WebServer #2 WebServer #3 WebServer #n CacheServer #1 CacheServer #2
Administration Powershell Cluster configcentrally in XML fileor in SQL Server ConfiguringAppFabric
Notebook directly: Windows 7 with IIS and Visual Studio Fourvirtualmachines: VCacheDC Domain Controller SQL Server VCache01 AppFabric VCache02 VCache03 AppFabric AppFabric
Named Caches VCache01 VCache02 VCache03 Cache: default Cache: sessiondata Additional caches … with different configuration
Administration via Powershell Loadingthemodule Import-Module DistributedCacheAdministration Get-CacheHelp Creating a newcache: New-Cache democache Startingthe Cluster: Start-CacheCluster Status: Get-CacheHost Cache Administration
Export-CacheClusterConfig c:\test.xml Add advancedProperties Import-CacheClusterConfigc:\test.xml AppFabric Caching w/o Security <dataCache> <advancedProperties> <securityProperties mode="None" protectionLevel="None" /> </advancedProperties> <caches>…</caches> <hosts>…</hosts> </dataCache>
Configuringtheclient AppFabric Caching „Hello World“ <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>
Adding References fromC:\Windows\System32\AppFabric Microsoft.ApplicationServer.Caching.ClientandMicrosoft.ApplicationServer.Caching.Core Have to becopiedfirst AppFabric Caching „Hello World“ DataCacheFactory fact = new DataCacheFactory(); DataCachemyCache = fact.GetCache("democache2"); string someKey = "myKey"; string someValue = "testing"; // anything [Serializable] myCache.Put(someKey, someValue); string result = (string) myCache[someKey];
Storingand Distribution DataCache defaultcache = GetCache("default"); Product prod = GetProduct(...); defaultcache.Put("Prod-1",prod); .NET Client defaultcache.Put("Prod-2",prod2); defaultcache.Put("Prod-3",prod3); defaultcache.Put("Prod-4",prod4); VCache01 VCache02 VCache03 Cache: default Prod-1 Prod-2 Prod-3 Prod-4 Other namedcaches …
Scalingsize More machines == morememory Scalingthroughput More machines == higherthroughput „LocalCache“ Directlyatclient == massivelylowerlatency Higher throughputwhenreading But also: itemsareolder, cangetstale Scalingthe Cache
Item Routing .NET Client defaultcache.Put("Prod-1",prod); Dynamic Routing Table Prod-1 Velocity #1 Velocity #2 Velocity #3 Prod-2 Prod-3 Prod-4
NodeFailure .NET Client object p1 = defaultcache["Prod-1"]; object p1 = defaultcache["Prod-1"]; if (p1==null) { p1 = GetProductFromDatabase(...) defaultcache.Put("Prod-1", p1); } Dynamic Routing Table Prod-1 Velocity #1 Velocity #2 Velocity #3 Prod-2 Prod-1 Prod-3 Prod-4
Optional All elements in a region live on the same node Can betagged AllowBulkGetandbulkdelete Regionsand Tags
Reference Data: "never" changes (catalogdata, pricelists, …) Activitydata: non-concurrentchanges (sessiondata, shoppingcart, …) Resourcedata: highconcurrencydata, constantlychanging (inventorylevel, …) Kinds of Data
Analysing Data • Performance – Throughputandlatency • Consistency – Guaranteedor eventual • Recoverability – Can thedataberestoredfrom DB (cacheeviction?) • Availability – Whathappensatnodefailure
Chosen in configorcode In practice: oftencode, becauseonlyspecificpartsshouldbecachedlocally (DataCacheFactory) Goodforreferencedata Synchronization Age ofitems Notification Local Cache
Pub/sub on cache item changes Callbacksforcompletecache, for a regionorfor a single item Are currently (beta 2) queuedatserversideandregularilypolledbytheclient Cache has to beconfiguredfornotifications New-Cache <name> -NotificationsEnabledtrue Notifications
Optimisticandpessimisticlocking Concurrency 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);
Session State <sessionStatemode="Custom" customProvider="Velocity"> <providers> <addname="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>
High Availability sessionCache.put("Sess-1", se1); sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); Sess-1 (Primary) Sess-2 (Primary) Sess-1 (Secondary) Sess-2 (Secondary) Velocity #1 Velocity #2 Velocity #3
Failover with High Availability sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); sessionCache.put("Sess-1", se1); Velocity #1 Velocity #2 Velocity #3 Sess-1 (Secondary) Sess-1 (Primary) Sess-1 (Secondary) Sess-2 (Secondary) Sess-2 (Primary) Sess-2 (Primary) Sess-2 (Secondary)
Powershell New-Cache <name> -Secondaries 1 Maybe also: –Eviction None –NotExpirabletrue Startingwith Beta2: Onlysupported on Enterprise (and Data Center) operatingsystemeditions Configuring High Availability