Ingo Rammer thinktecture
Support and consulting for software architects and developers Application Optimization, Troubleshooting, Debugging Architectural Consulting and Prototyping Developer-Coaching and -Mentoring Architecture and Code Reviews
Project Velocity is a Windows Service which provides highly scalable, distributed, cache- aside caching infrastructure spanning multiple physical nodes... and it will quite likely be free and released mid 2009
Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Data Store Users
Web Server Data Store Application Memory Session State Local Caching
Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Cache Server #1 Cache Server #2 Velocity Caching
Web Server #1 Web Server #2 Web Server #3 Web Server #n Load Balancer Cache Server #1 Cache Server #2 V V V V V V V V V V V V
Today CTP2/CTP3 Configuration Server: Cluster XML or SQL Server Client: App.Config or code Administration Powershell - can be used from any node in the cluster
In Powershell admin New-Cache -cachename democache Store/Retrieve items DataCacheFactory fact = new DataCacheFactory(); DataCache myCache = fact.GetCache("democache2"); string someValue = "testing"; // anything [Serializable] string someKey = "myKey"; myCache.Put(someKey, someValue); string result = (string) myCache[someKey]; DataCacheFactory fact = new DataCacheFactory(); DataCache myCache = fact.GetCache("democache2"); string someValue = "testing"; // anything [Serializable] string someKey = "myKey"; myCache.Put(someKey, someValue); string result = (string) myCache[someKey];
.NET Client Velocity #1 Velocity #2 Velocity #3 Prod-1 Prod-2 Prod-4 Prod-3 DataCache defaultcache = GetCache(...); Product prod = GetProduct(...); defaultcache.Put("Prod-1",prod); DataCache defaultcache = GetCache(...); 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);
Scale on size More machines == more memory Scale on throughput More machines == higher throughput Local Cache Closer to the client == lower latency, higher throughput, higher staleness
Can be enabled in config or code Great for reference data which can tolarate staleness Synchronization CTP2: Expiration CTP3: notifications from central caches
Velocity #1 Velocity #2 Velocity #3 Prod-1.NET Client Dynamic Routing Table Prod-2 Prod-4 Prod-3 defaultcache.Put("Prod-1",prod);
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
Reference Data Example: product catalog Does not change dynamically, can be cached locally Can be reloaded from database Activity Data Example: Session, shopping cart Frequent changes, highly partitionable Needs high availability Resource Data Example: product inventory level Changes often, needs staleness decision Maybe "exceed first, apologize later", maybe centralized checks on update on partitioned DB
Optimistic (default) 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);
Decide which properties you need Performance - Throughput and Latency Consistency - Staleness Eviction - Can the data be recreated? Security - Who can read/write Availability - Survive node failure Different set of requirements for each kind of data Configuration options in Velocity for these requirements
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);
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)
//... here comes the code... <add name="SessionStoreProvider" type="System.Data.Caching.SessionStoreProvider, ClientLibrary" cacheName="CacheName"/> //... here comes the code... <add name="SessionStoreProvider" type="System.Data.Caching.SessionStoreProvider, ClientLibrary" cacheName="CacheName"/>
Optional Support tagging, enumeration and bulk gets (CTP3) Every item in a region lives on the same node! Example use case Session state in which every property can be stored individually within one region Can be used as unit for deletion
CTP3: Notifications, callback for cache item changed Version 2: Core features Queryable caches with LINQ Cache-Through instead of cache-aside ASP.NET 4.0 Velocity as System.Caching provider Granular session updates (IPartialSessionState) Velocity as Output caching provider Higher compatibility with Azure and HPC
Presentations TechDays: MSDN Events: MSDN Webcasts: MSDN Events MSDN Events: Save the date: TechEd 2009 Europe, 9-13 November 2009, Berlinhttp:// MSDN Flash (our by weekly newsletter) Subscribe: MSDN Team Blog RSS: Developer User Groups & Communities Mobile Devices: Microsoft Solutions User Group Switzerland: Managed User Group of Switzerland: FoxPro User Group Switzerland:
Presentations TechDays: TechNet Events TechNet Events: Save the date: TechEd 2009 Europe, 9-13 November 2009, Berlinhttp://technet.microsoft.com/de-ch/bb aspx TechNet Flash (our by weekly newsletter) Subscribe: Schweizer IT Professional und TechNet Blog RSS: IT Professional User Groups & Communities SwissITPro User Group: NT Anwendergruppe Schweiz: PASS (Professional Association for SQL Server):
7. – 8. April 2010 Congress Center Basel
Classic Sponsoring Partners Media Partner Premium Sponsoring Partners
//... here comes the code...