Your SlideShare is downloading. ×
Building High Performance and Scalable Applications Using AppFabric Cache- Impetus White Paper
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Building High Performance and Scalable Applications Using AppFabric Cache- Impetus White Paper

938
views

Published on

For Impetus’ White Papers archive, visit- http://www.impetus.com/whitepaper …

For Impetus’ White Papers archive, visit- http://www.impetus.com/whitepaper

Most applications face challenges related to robustness, speed, and scalability. This paper focuses on Windows Server AppFabric, which provides a distributed in‐memory cache for applications data.

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
938
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building High Performance andScalable Applications usingAppFabric CacheW H I T E P A P E RAbstractMost applications face challenges related to robustness, speed,and scalability. This white paper focuses on Windows ServerAppFabric, which provides a distributed in-memory cache forapplications data.The paper talks about AppFabric cache’s ability to helpsorganization create scalable, available, high-performanceapplications by exposing a unified view of distributed memoryfor client application consumption. It focuses on how AppFabricallows companies to significantly improve applicationperformance by avoiding repetitive calls to the data source andhow it enables applications to scale with increasing demand, byusing a cache cluster that automatically handles the complexitiesof load balancing.Impetus Technologies, Inc.www.impetus.com
  • 2. Building High Performance and Scalable Applications using AppFabric Cache2Table of ContentsIntroduction...........................................................................................................3Key challenges........................................................................................................3The solution ...........................................................................................................3AppFabric Caching .................................................................................................4Windows Server AppFabric Architecture...............................................................4Key features of AppFabric Caching........................................................................6How AppFabric Caching works ..............................................................................7AppFabric Cache API............................................................................................11Best Practices.......................................................................................................12Constraints...........................................................................................................12Summary..............................................................................................................13References ...........................................................................................................13
  • 3. Building High Performance and Scalable Applications using AppFabric Cache3IntroductionIn the programming world, data is captured and stored into the file system,database and other sources. Sometimes, the cost of storing and retrieving thedata is expensive. While advanced technologies allow the capturing and storingof data in a relatively inexpensive way, however organizing and accessing data isa big challenge. Technologies such as AppFabric cache can help organizationsdevelop next-generation applications that are data-driven, where the data canreside in the memory.Key ChallengesNormally an in-memory cache is used to store frequently used application datathat helps improve the performance of the application. Reading and writingdata into memory is faster than reading from and writing to a database or disk.However, some challenges exist in the traditional in-memory cache.• Due to limited memory available for an Application, the in-memory cachesize is limited. Only a limited size of data can be stored into the in-memorycache.• Data stored in an in-memory can be lost if the Application goes down due toany failure.• There is no simple technique that can reduce pressure from the data-tierwithout complex data partitioning techniques.• Storing big data mash-ups from multiple data repositories is also achallenge.The SolutionTo overcome the above challenges, the Impetus engineering team hasundertaken a research on Microsoft’s AppFabric cache. AppFabric caching hasthe capability to combine multiple computers into a single unified cache cluster.By using AppFabric caching, users can scale out their .Net applications easily andinexpensively. Here’s how:• AppFabric Caching Services use a cache cluster that automatically managesthe complexities of load balancing. It also enables organizations to achievebetter scalability by adding more computers on demand.
  • 4. Building High Performance and Scalable Applications using AppFabric Cache4• Users can achieve even higher availability by allowing Caching Services tostore copies of the data across the cluster. They can run AppFabric CachingServices with any distributed application on the same server, or access theservices over a network on a remote server.• AppFabric Caching Services enables users to improve applicationperformance significantly by avoiding unnecessary calls to the data source.In addition, there is seamless integration with ASP.Net for storing session statein the cache. This can provide ASP.Net sites with a cost-effective path for quicklyimproving site performance and scale. The performance, scalability, andavailability of AppFabric caching services, in conjunction with AppFabric richdata services, can facilitate rich Web and enterprise applications developmentand deployment.AppFabric CachingWindows AppFabric Caching (previously called Velocity), is a distributed inmemory caching software. ‘Velocity’ fuses memory across multiple computersto provide a single unified cache view to applications. It allows high-performance in memory access to cached data across multiple servers that usecaching access. Thus, it is well suited for applications that run on Web farms.Furthermore, it allows for clustering, so that companies can scale up theircaching solution as their needs grow. Windows AppFabric Caching can beconfigured to run as a service accessed over the network or can be runembedded with the distributed application.Windows Server AppFabric ArchitectureAppFabric Caching Services are not tightly coupled to ASP.Net, and it is possible to usethem at any layer of an application architecture, including clients, workflows, andservices. However, in the context of Web applications, AppFabric caching providesASP.Net developers with a seamless upgrade path to a distributed in-memory cachingoption, when their application requirements exceed the capabilities of the defaultASP.Net caching system. Specifically, AppFabric provides an in-memory cachingsolution that accomplishes the following:• Supports greater scale-out by offloading caching to a dedicated cache tier.• Offers high availability of cached data.• Avoids sticky routing.
  • 5. Building High Performance and Scalable Applications using AppFabric Cache5Most developers are familiar with n-tier application architectures in which theapplication is broken out into tiers. These typically include three classic layers: theuser interface, the business logic layer, and the data layer. Of course, users can breakthese layers down further to provide for additional scalability and flexibility. The figurebelow shows the presence of a fourth layer, the Caching tier. In this case, when usersfirst acquire some item of data, such as information from the ASP.Net application orvalues read from a database, they can use an AppFabric Caching Services tier toexplicitly store this information in the cache cluster under a unique name. Later, theapplication can directly read data from the cache cluster, without needing to go againto the database.Figure-1: AppFabric Cache Architecture
  • 6. Building High Performance and Scalable Applications using AppFabric Cache6Key Features of AppFabric CachingFigure-2: AppFabric CapabilitiesCaching features of Windows Server AppFabric• Data is stored on multiple nodes, improving availability.• There is caching of any serializable CLR object.• There is integration with ASP.Net, making it possible to cache ASP.Netsession data in the cache via the custom session state provider. Thisincreases the performance and scalability of ASP.Net applications.• Automatic load balancing across cache cluster, thereby improvingscalability.• There are regions, where data is segregated into logical segments.• There is an Expiration feature, which allows time span based expiration ofcached data.• The Evictions feature allows memory conservation.• AppFabric cache supports enterprise scale: that is, tens, to hundreds ofcomputers.
  • 7. Building High Performance and Scalable Applications using AppFabric Cache7How AppFabric Caching WorksThis section describes the caching concepts that are useful in programming withAppFabric.Logical HierarchyLogical Hierarchy of AppFabric caching consists of Machine -> Cache Host ->Named Caches -> Regions -> Cache Items -> Objects• The machines are servers which run Cache Hosts.• Cache Hosts are the physical processes that host the AppFabric Cachinginstance. A user can run multiple processes that host a cache instance,called Cache Hosts.• Named Caches are the logical entities which can span across machines. Thenamed cache consists of regions, which store cache items.• Regions are physically co-located Containers of Cache Items and may beimplicitly or explicitly created.• The Cache Item is the key, Payload (Object) and has associated Tags,Timestamps, and Versions.
  • 8. Building High Performance and Scalable Applications using AppFabric Cache8Figure-3: Hierarchy of AppFabric CacheNamed CacheA named cache is a configurable unit of in-memory storage that all applications use tostore data in the distributed cache. Users can configure one or more named caches foreach of their applications. Each cache can be configured independent of the others,which lets users optimize the policies of each cache for their applications. All physicalconfigurations and cache policies such as failover, expiration, eviction, etc., arespecified at this level. All the applications that need to communicate to the samenamed cache must instantiate the same named cache using the Data Cache Factory.All caches are defined in the cluster configuration. The Windows PowerShelladministration tool can be used to create or reconfigure caches. Some settings canonly be configured when the cache is first created. Other settings can be changedlater, but may require the entire cache cluster to be restarted. There is a limit of 128named caches.RegionRegions are an additional data container that can be placed in the cache. Regions are acache construct: they are not defined in the cluster configuration settings. Regions are
  • 9. Building High Performance and Scalable Applications using AppFabric Cache9optional; if required, they must be explicitly created at run time with the applicationcode by using the Create Region method.An application is not required to use Regions and can use the put/get/remove APIswith just the key to the object. In fact, the application will scale better when not usingRegions because the keys can be distributed across the named cache. If no Region isspecified, the system automatically partitions the keys into multiple implicitly createdRegions.Cache ItemThe Cache Item actually contains the object. The Cache Item stores the object with thekey, the object payload, tags, and the time to live (TTL), the created timestamp, theversion, and other internal book keeping information. A Region contains one or moreof these Cache Items.AvailabilityThis is one of the important features of the Windows Server AppFabric Cache. If onenode (machine) of the distributed cache gets down, users can get data from thesecondary node. When using a partitioned cache, it is possible to specify a number ofnodes as secondary cache. By doing this, users can store the same data on multiplecomputers. Therefore, if one node fails then one of the secondary nodes becomes aprimary node and enables applications to continue accessing the data that was storedon the computer.
  • 10. Building High Performance and Scalable Applications using AppFabric Cache10Figure-4: Primary Cache and Secondary Cache routingLocal CacheThe Local Cache in AppFabric is similar to in-memory cache. Local Cache objects arestored within the same process space in which the application is running. The serverstores objects in a serialized manner in the cache. When a cache client requests anobject from the cache, the server sends it to the client over the network. The cacheclient then desterilizes the object for use by the client application. To speed up theprocess of retrieving an object, users can enable the Local Cache.
  • 11. Building High Performance and Scalable Applications using AppFabric Cache11AppFabric Cache APIThe AppFabric Caching Services API is fairly simple. Users must first create aninstance of the Cache Factory object, which under the hood reads theconfiguration settings from Web.config/app.config of their ASP.Net orWF or WCF service. The need this Cache fFactory Object to retrieve anamed data cache object. These will be the least required steps for userswanting to access the cached objects (data) from the AppFabric CachingServices. The following code excerpt showcases this technique://Create instance of CacheFactoryDataCacheFactory_factory= new DataCacheFactory();//Get a named cache from the factoryDataCache_cache= _factory.GetCache("default");From here, users can deploy simple Get and Put commands to read or writedata from, or to the AppFabric caching storage. This snippet uses these twocommands to write and then read custom data from the AppFabric Cache://Put data into a cache_cache.Put("id01", new Item("Test", "25.00", "..."));...//Get the data from the same or a different clientItem MyItem = (Item) _cache.Get("id01");// If not present in the cacheif (MyItem== null){//Read from the backend layerMyItem= ReadFromDatabase();//Populate the Cache_cache.Put("id01", new Item("Test", "25.00", "..."));returnMyItem;}
  • 12. Building High Performance and Scalable Applications using AppFabric Cache12Best Practices• Expiration time on Velocity should not be set to very small values, which canlead to increasing memory consumption. This occurs because of delaysrelated to garbage collection calls―old data expires, but remains inmemory, and a new copy of the data is added to memory.• Local Cache: For best performance, users are advised to enable only theLocalCaches for objects that change infrequently. Using the Local Cache forfrequently changing data may increase the chance of a client working withstale objects. In instances of frequently changing data, it is best to disablethe Local Cache and pull data directly from the cluster.• The default setting for RequestTimeout is 10 seconds, and therefore usersare advised not to set it at 0. If they do, the application will see a timeout onevery cache call.• Even though having just one Cache Server in the client configuration cansuffice, it is recommended to maintain as many cache server host names inthe config file.ConstraintsThere is no direct support of cache dependency in Window Server AppFabriccaching. If data gets changed in the database, the same does not change in theCache Cluster.
  • 13. Building High Performance and Scalable Applications using AppFabric Cache13SummaryThe primary advantage of using Windows Server AppFabric cache is the creationof scalable, available and high-performance applications. Applications that useAppFabric cache respond faster, because they fetch data from the cache insteadof retrieving it again and again from the database or other sources. As cachestores the same data on multiple computers, it provides application availabilityat all times. Windows Server AppFabric cache also provides integration withASP.Net that enables ASP.Net session objects to be stored in the distributedcache, without having to write to databases. This increases the scalability andperformance of ASP.Net applications.References1. http://msdn.microsoft.com/en-us/library/ee677312.aspx2. http://msdn.microsoft.com/library/cc645013.aspx3. Stephen Kaufman, DannyGarber: Pro Windows Server AppFabric, ApressAbout ImpetusImpetus is a Software Solutions and Services Company with deeptechnical maturity that brings you thought leadership, proactiveinnovation, and a track record of success. Our Services and Solutionsportfolio includes Carrier grade large systems, Big Data, Cloud,Enterprise Mobility, and Test and Performance Engineering.Website: www.impetus.com | Email: inquiry@impetus.com© 2013 Impetus Technologies, Inc.All rights reserved. Product andcompany names mentioned hereinmay be trademarks of theirrespective companies. May 2013