Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ingo Rammer thinktecture

Similar presentations


Presentation on theme: "Ingo Rammer thinktecture"— Presentation transcript:

1 Ingo Rammer thinktecture ingo.rammer@thinktecture.com

2 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://www.thinktecture.com ingo.rammer@thinktecture.com

3 AppFabric Caching (Velocity) is a Windows Service for highly scalable distributed caching Multiple physical nodes are combined to form one big virtual cache

4 So first … let‘s start the virtual machines …

5 Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Data User

6 Web Server Data Application Session State Local Caching Local Caching

7 Session state InProc, Session server, database? Availability, Single-Point-Of-Failure, Performance Caching Cache consistency when using multiple servers

8 Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Cache Server #1 Cache Server #2 AppFabric Caching

9 Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Cache Server #1 Cache Server #2

10 Administration Powershell Cluster config centrally in XML file or in SQL Server

11 Notebook directly: Windows 7 with IIS and Visual Studio Four virtual machines: Notebook directly: Windows 7 with IIS and Visual Studio Four virtual machines: VCacheDC Domain Controller SQL Server VCacheDC Domain Controller SQL Server VCache01 AppFabric VCache02 AppFabric VCache03 AppFabric

12 VCache01 VCache02 VCache03 Cache: default Cache: sessiondata Additional caches … with different configuration

13 Administration via Powershell Loading the module Import-Module DistributedCacheAdministration Get-CacheHelp Creating a new cache: New-Cache democache Starting the Cluster: Start-CacheCluster Status: Get-CacheHost

14 Export-CacheClusterConfig c:\test.xml Add advancedProperties Import-CacheClusterConfig c:\test.xml … …

15 Configuring the client

16 Adding References from C:\Windows\System32\AppFabric Microsoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.Core Have 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]; 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];

17 VCache01 VCache02 VCache03 Cache: default.NET Client Prod-1 Prod-2 Prod-4 Prod-3 DataCache defaultcache = GetCache("default"); Product prod = GetProduct(...); defaultcache.Put("Prod-1",prod); 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); defaultcache.Put("Prod-2",prod2); defaultcache.Put("Prod-3",prod3); defaultcache.Put("Prod-4",prod4); Other named caches …

18 Scaling size More machines == more memory Scaling throughput More machines == higher throughput „Local Cache“ Directly at client == massively lower latency Higher throughput when reading But also: items are older, can get stale

19 Velocity #1 Velocity #2 Velocity #3 Prod-1.NET Client Dynamic Routing Table Prod-2 Prod-4 Prod-3 defaultcache.Put("Prod-1",prod);

20 Velocity #1 Velocity #2 Velocity #3 Prod-1.NET Client Dynamic Routing Table Prod-2 Prod-4 Prod-3 object p1 = defaultcache["Prod-1"]; if (p1==null) { p1 = GetProductFromDatabase(...) defaultcache.Put("Prod-1", p1); } object p1 = defaultcache["Prod-1"]; if (p1==null) { p1 = GetProductFromDatabase(...) defaultcache.Put("Prod-1", p1); } Prod-1

21 Optional All elements in a region live on the same node Can be tagged Allow BulkGet and bulk delete

22 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, …)

23 Performance – Throughput and latency Consistency – Guaranteed or eventual Recoverability – Can the data be restored from DB (cache eviction?) Availability – What happens at node failure

24 Chosen in config or code In practice: often code, because only specific parts should be cached locally (DataCacheFactory) Good for reference data Synchronization Age of items Notification

25 Pub/sub on cache item changes Callbacks for complete cache, for a region or for a single item Are currently (beta 2) queued at server side and regularily polled by the client Cache has to be configured for notifications New-Cache -NotificationsEnabled true

26 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); 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); DataCacheLockHandle lockHandle; object itm = defaultCache.GetAndLock("region", "key", TimeSpan.FromSeconds(30), out lockHandle); // after change: defaultCache.PutAndUnlock("region", "key", itm, lockHandle, null);

27

28 Velocity #1 Velocity #2 Velocity #3 Sess-1 (Primary) Sess-1 (Primary) sessionCache.put("Sess-1", se1); Sess-1 (Secondary) Sess-2 (Primary) Sess-2 (Primary) Sess-2 (Secondary) sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2);

29 Velocity #1 Velocity #2 Velocity #3 Sess-1 (Primary) Sess-1 (Primary) sessionCache.put("Sess-1", se1); Sess-1 (Secondary) Sess-2 (Primary) Sess-2 (Primary) Sess-2 (Secondary) sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); Sess-2 (Primary) Sess-2 (Primary) Sess-2 (Secondary) Sess-1 (Secondary) Sess-1 (Secondary)

30 Powershell New-Cache -Secondaries 1 Maybe also: –Eviction None –NotExpirable true Starting with Beta2: Only supported on Enterprise (and Data Center) operating system editions


Download ppt "Ingo Rammer thinktecture"

Similar presentations


Ads by Google