280 likes | 365 Views
Performance Distributed Caching: Introduction to Velocity. Ingo Rammer ingo.rammer@thinktecture.com thinktecture. Ingo Rammer and thinktecture . Support and consulting for software architects and developers Application Optimization, Troubleshooting, Debugging
E N D
Performance Distributed Caching: Introduction to Velocity Ingo Rammer ingo.rammer@thinktecture.com thinktecture
Ingo Rammer and 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 • http://www.thinktecture.com • ingo.rammer@thinktecture.com
30 Second Elevator Pitch • 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
Typical Web Application Users Load Balancer WebServer #1 WebServer #2 WebServer #3 WebServer #n DataStore
Web Server in Detail Web Server Application Memory Local Caching Session State DataStore
Typical Web Application Load Balancer WebServer #1 WebServer #2 WebServer #3 WebServer #n CacheServer #1 Velocity Caching CacheServer #2
Velocity Services Load Balancer WebServer #1 WebServer #2 WebServer #3 WebServer #n CacheServer #1 V V V V V CacheServer #2 V
Installing Velocity • 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
Velocity Hello World • In Powershell admin • New-Cache -cachename democache • Store/Retrieve items DataCacheFactory fact = new DataCacheFactory(); DataCachemyCache = fact.GetCache("democache2"); string someValue = "testing"; // anything [Serializable] string someKey = "myKey"; myCache.Put(someKey, someValue); string result = (string) myCache[someKey];
Velocity Item Storage DataCache defaultcache = GetCache(...); 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); Velocity #1 Velocity #2 Velocity #3 Prod-1 Prod-2 Prod-3 Prod-4
Scaling Velocity • 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
Local Cache • Can be enabled in config or code • Great for reference data which can tolarate staleness • Synchronization • CTP2: Expiration • CTP3: notifications from central caches
Velocity 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
Cache Failure .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
Kinds of Data • 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
Concurrency • 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); DataCacheLockHandle lockHandle; object itm = defaultCache.GetAndLock("region", "key", TimeSpan.FromSeconds(30), out lockHandle); // after change: defaultCache.PutAndUnlock("region", "key", itm, lockHandle, null);
Data Requirements • 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
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
High Availability Failover sessionCache.put("Sess-1", se1); sessionCache.put("Sess-1", se1); sessionCache.put("Sess-2", se2); 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)
Session State // ... here comes the code ... <sessionState mode="Custom" customProvider="SessionStoreProvider"> <providers> <add name="SessionStoreProvider" type="System.Data.Caching.SessionStoreProvider, ClientLibrary" cacheName="CacheName"/> </providers> </sessionState>
Regions • 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
Future • 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
Your MSDN resourcescheck out these websites, blogs & more! PresentationsTechDays: www.techdays.chMSDN Events: http://www.microsoft.com/switzerland/msdn/de/presentationfinder.mspxMSDN Webcasts: http://www.microsoft.com/switzerland/msdn/de/finder/default.mspx MSDN EventsMSDN Events: http://www.microsoft.com/switzerland/msdn/de/events/default.mspxSave the date: Tech•Ed 2009 Europe, 9-13 November 2009, Berlin MSDN Flash (our by weekly newsletter)Subscribe: http://www.microsoft.com/switzerland/msdn/de/flash.mspx MSDN Team BlogRSS: http://blogs.msdn.com/swiss_dpe_team/Default.aspx Developer User Groups & CommunitiesMobile Devices: http://www.pocketpc.ch/Microsoft Solutions User Group Switzerland: www.msugs.ch.NET Managed User Group of Switzerland: www.dotmugs.chFoxPro User Group Switzerland: www.fugs.ch
Your TechNet resourcescheck out these websites, blogs & more! PresentationsTechDays: www.techdays.ch TechNet EventsTechNet Events: http://technet.microsoft.com/de-ch/bb291010.aspx Save the date: Tech•Ed 2009 Europe, 9-13 November 2009, Berlin TechNet Flash (our by weekly newsletter)Subscribe: http://technet.microsoft.com/de-ch/bb898852.aspx Schweizer IT Professional und TechNet BlogRSS: http://blogs.technet.com/chitpro-de/ IT Professional User Groups & CommunitiesSwissITPro User Group: www.swissitpro.chNT Anwendergruppe Schweiz: www.nt-ag.chPASS (Professional Association for SQL Server): www.sqlpass.ch
Save the date for tech·days nextyear! 7. – 8. April 2010Congress Center Basel
Premium Sponsoring Partners Classic Sponsoring Partners Media Partner
Code Template // ... here comes the code ...