Vous êtes sur la page 1sur 11

WHITEPAPER

BuildingHighPerformanceandScalable ApplicationsusingAppFabricCache

Abstract
Mostapplicationsfacechallengesrelatedto robustness,speed,andscalability.Thiswhitepaper focusesonWindowsServerAppFabric,whichprovides adistributedinmemorycacheforapplicationsdata. ThepapertalksaboutAppFabriccachesabilityto helpsorganizationcreatescalable,available,high performanceapplicationsbyexposingaunifiedviewof distributedmemoryforclientapplication consumption.ItfocusesonhowAppFabricallows companiestosignificantlyimproveapplication performancebyavoidingrepetitivecallstothedata sourceandhowitenablesapplicationstoscalewith increasingdemand,byusingacacheclusterthat automaticallyhandlesthecomplexitiesofload balancing.

ImpetusTechnologies,Inc. www.impetus.com September2011

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Tableo ofConte ents


Introduction..... ...................... ............................................................... .......2 ychallenges. ...................... ............................................................... .......3 Key The esolution..... ...................... ............................................................... .......3 AppFabricCachi ing................ ............................................................... .......4 Architecture............................................ .......4 WindowsServerAppFabricA yfeaturesofAppFabricCa aching..................................................... .......5 Key HowAppFabricCachingwork ks........................................................... .......6 eAPI............. ............................................................... .......9 AppFabricCache stPractices... ...................... ............................................................... .....10 Bes Con nstraints....... ...................... ............................................................... .....10 Sum mmary.......... ...................... ............................................................... .....11 Ref ferences....... ...................... ............................................................... .....11

In ntroduct tion
Intheprogrammingworld,dataisca apturedands storedintothefilesystem, , mes,thecostofstoringan ndretrievingt the databaseandothersources.Sometim dataisexpe ensive.While eadvancedte echnologiesa allowthecapt turingandsto oring ofdataina arelativelyine expensivewa ay,howevero organizingand daccessingdatais abigchalle enge.Technol logiessuchas sAppFabriccachecanhelp porganizations developne extgeneration napplications sthataredat tadriven,wherethedatacan resideinth hememory.

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Keychallenges
Normallyaninmemory ycacheisused dtostorefrequentlyusedapplicationd data thathelpsi improvethep performanceoftheapplication.Readin ngandwriting g dataintom memoryisfast terthanread dingfromandwritingtoadatabaseord disk. However,s somechalleng gesexistinth hetraditionalinmemoryc cache. Duetolimitedm memoryavailableforanApplication,th heinmemory y cac chesizeislimited.Onlyalimitedsizeof fdatacanbestoredintothein me emorycache. Dat tastoredina aninmemory ycanbelostiftheApplicat tiongoesdow wn due etoanyfailure. The ereisnosimp pletechnique ethatcanred ducepressure efromthedat ta tier rwithoutcom mplexdatapa artitioningtec chniques. Sto oringbigdatamashupsfro ommultipled datareposito oriesisalsoa cha allenge.

Th hesolut tion
Toovercom metheabovechallenges,t theImpetuse engineeringte eamhas undertaken naresearcho onMicrosoftsAppFabricc cache.AppFabriccachingh has thecapabilitytocombin nemultipleco omputersinto oasingleunif fiedcacheclu uster. ByusingAp ppFabriccach hing,userscan nscaleoutth heir.Netapplicationseasilyand inexpensive ely.Heresho ow: ingServicesu useacachecl lusterthatau utomatically AppFabricCachi anagesthecomplexitiesof floadbalancing.Italsoena ables ma org ganizationsto oachievebett terscalability ybyaddingm morecompute erson dem mand. Use erscanachiev veevenhighe eravailability ybyallowingCachingServi ices tos storecopieso ofthedataac crosstheclus ster.Theycan nrunAppFabr ric Cac chingServiceswithanydis stributedapp plicationonth hesameserve er,or acc cesstheservicesoverane etworkonare emoteserver r. AppFabricCachi ingServicese enablesuserstoimprovea application per rformancesig gnificantlybyavoidingunn necessarycall lstothedata sou urce.

Inaddition, ,thereisseam mlessintegra ationwithASP P.Netforstor ringsessionst tate inthecache.Thiscanpr rovideASP.Ne etsiteswitha acosteffectiv vepathforqu uickly

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

improvings siteperforma anceandscale.Theperfor rmance,scalability,and availabilityofAppFabric ccachingserv vices,inconju unctionwithA AppFabricrich h es,canfacilitaterichWebandenterpri iseapplicationsdevelopment dataservice anddeploy yment.

AppFab bricCach hing


WindowsA AppFabricCac ching(previou uslycalledVe elocity),isadistributedin memoryca achingsoftware.Velocity fusesmemo oryacrossmu ultiplecomput ters toprovideasingleunifie edcacheview wtoapplications.Itallows shigh performanc ceinmemory yaccesstoca acheddataac crossmultiple eserversthatuse cachingacc cess.Thus,itiswellsuited dforapplicati ionsthatrunonWebfarm ms. Furthermore,itallowsfo orclustering, ,sothatcomp paniescansc caleuptheir cachingsolutionastheir rneedsgrow.WindowsAp ppFabricCach hingcanbe configuredtorunasase erviceaccessedoverthen networkorca anberun embeddedwiththedist tributedappli ication.

Windo owsServ verAppF FabricA Architecture


AppFabricC CachingServi icesarenotti ightlycoupled dtoASP.Net, ,anditispossibletouse thematanylayerofanapplicationarchitecture,includingclien nts,workflow ws,and owever,inthecontextofW Webapplicat tions,AppFab briccachingprovides services.Ho ASP.Netde eveloperswith haseamlessupgradepath htoadistribu utedinmemo orycaching option,whe entheirappli icationrequir rementsexce eedthecapab bilitiesofthedefault ASP.Netcachingsystem.Specifically,AppFabricprovidesanin memorycaching solutiontha ataccomplish hesthefollow wing: Sup pportsgreate erscaleoutby yoffloadingc cachingtoad dedicatedcac che tier r. Off fershighavailabilityofcac cheddata. Avo oidsstickyrouting.

Mostdevel lopersarefam miliarwithnt tierapplicatio onarchitecturesinwhicht the applicationisbrokenou utintotiers.T Thesetypically yincludethre eeclassiclaye ers:the userinterfa ace,thebusin nesslogiclaye er,andtheda atalayer.Ofc course,userscanbreak theselayer rsdownfurthertoprovide eforadditiona alscalabilitya andflexibility y.Thefigure belowshow wsthepresen nceofafourthlayer,theC Cachingtier.Inthiscase,w whenusers firstacquire esomeitemofdata,suchasinformatio onfromtheA ASP.Netappli icationor valuesread dfromadatabase,theyca anuseanApp pFabricCachin ngServicestie erto explicitlyst torethisinfor rmationinthe ecachecluste erunderaun niquename.L Later,the
4

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

applicationcandirectlyreaddatafro omthecachecluster,witho outneedingt togoagain tothedatabase.

Figure1:AppFabricCa acheArchitecture

Keyfeat turesofAppFab bricCach hing

apabilities Figure2:AppFabricCa
5

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Cachingfea aturesofWin ndowsServer rAppFabric Dat taisstoredonmultipleno odes,improvingavailability y. The ereiscaching gofanyserial lizableCLRob bject. The ereisintegrat tionwithASP P.Net,making gitpossibleto ocacheASP.N Net ses ssiondataint thecacheviathecustoms sessionstateprovider.This increasesthepe erformanceandscalability yofASP.Neta applications. Aut tomaticloadbalancingacr rosscacheclu uster,thereby yimproving sca alability. The ereareregion ns,wheredat taissegregat tedintologica alsegments. The ereisanExpirationfeature e,whichallow wstimespanbasedexpira ation ofc cacheddata. The eEvictionsfeatureallowsmemorycons servation. AppFabriccache esupportsen nterprisescale e:thatis,tens,tohundred dsof com mputers.

How wAppFabricCac chingwo orks


Thissection ndescribesth hecachingco onceptsthata areusefulinp programming gwith AppFabric. LogicalHierarchy LogicalHier rarchyofApp pFabriccachin ngconsistsof fMachine>C CacheHost> > NamedCac ches>Region ns>CacheIt tems>Objec cts The emachinesareserverswh hichrunCacheHosts. Cac cheHostsare ethephysicalprocessesth hathosttheA AppFabricCac ching instance.Auser rcanrunmult tipleprocesse esthathosta acacheinstan nce, calledCacheHo osts. NamedCachesa arethelogica alentitieswhichcanspanacrossmachines. The enamedcach heconsistsof fregions,whichstorecach heitems. Reg gionsarephy ysicallycolocatedContainersofCacheItemsandma aybe imp plicitlyorexp plicitlycreated d. The eCacheItemisthekey,Pa ayload(Objec ct)andhasas ssociatedTags s, Tim mestamps,andVersions.

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Figure3:HierarchyofAppFabricCa ache NamedCac che Anamedca acheisaconf figurableunit tofinmemor rystoragetha atallapplicat tionsuseto storedatai inthedistribu utedcache.U Userscanconfigureoneor rmorenamed dcachesfor eachofthe eirapplication ns.Eachcache ecanbeconf figuredindep pendentofthe eothers, whichletsu usersoptimiz zethepolicies sofeachcach hefortheirapplications.A Allphysical configurationsandcachepoliciessuc chasfailover, ,expiration,e eviction,etc.,are specifiedat tthislevel.Alltheapplicat tionsthatnee edtocommunicatetothesame namedcachemustinsta antiatethesa amenamedca acheusingth heDataCache eFactory. Allcachesa aredefinedin ntheclusterc configuration n.TheWindow wsPowerShell administrat tiontoolcanbeusedtocr reateorrecon nfigurecache es.Somesetti ingscan onlybecon nfiguredwhen nthecacheis sfirstcreated d.Othersettin ngscanbech hanged later,butm mayrequireth heentirecach heclustertoberestarted.Thereisalim mitof128 namedcaches. Region Regionsare eanadditiona aldatacontainerthatcanbeplacedinthecache.Re egionsarea cacheconstruct:theyar renotdefined dinthecluste erconfigurati ionsettings.R Regionsare optional;ifrequired,the eymustbeex xplicitlycreatedatruntim mewiththeap pplication codebyusi ingtheCreate eRegionmet thod.

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Anapplicat tionisnotreq quiredtouseRegionsandcanusethep put/get/remo oveAPIs withjustth hekeytotheobject.Infac ct,theapplica ationwillscale ebetterwhennotusing Regionsbecausethekey yscanbedist tributedacros ssthenamed dcache.IfnoRegionis specified,thesystemau utomaticallyp partitionsthekeysintomu ultipleimplicit tlycreated Regions. CacheItem m TheCacheItemactually ycontainsthe eobject.TheC CacheItemst torestheobje ectwiththe key,theob bjectpayload, ,tags,andthe etimetolive(TTL),thecre eatedtimesta amp,the version,andotherinternalbookkeepinginformat tion.ARegion ncontainson neormore acheItems. oftheseCa Availability y Thisisoneoftheimport tantfeaturesoftheWindo owsServerAp ppFabricCach he.Ifone node(mach hine)ofthed distributedcachegetsdow wn,userscangetdatafrom mthe secondarynode.Whenusingapartit tionedcache,itispossibletospecifyan numberof nodesasse econdarycach he.Bydoingt this,userscanstorethesa amedataonmultiple computers.Therefore,if fonenodefa ailsthenoneo ofthesecond darynodesbe ecomesa lesapplicationstocontinu ueaccessingthedatathatwasstored primarynodeandenabl onthecom mputer.

Figure4:PrimaryCach heandSecond daryCachero outing

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

LocalCache e TheLocalC CacheinAppF Fabricissimila artoinmemorycache.Lo ocalCacheob bjectsare storedwith hinthesameprocessspace einwhichthe eapplicationisrunning.Theserver storesobje ectsinaserial lizedmannerinthecache. .Whenacach heclientrequ uestsan objectfrom mthecache,t theserversen ndsittothec clientoverthe enetwork.Th hecache clientthendesterilizest theobjectfor rusebytheclientapplication.Tospeed dupthe processofretrievinganobject,users scanenablet theLocalCach he.

Ap ppFabric cCacheAPI
bricCachingS ServicesAPIisfairlysimple e.Usersmust tfirstcreatea an TheAppFab instanceof ftheCacheFa actoryobject, ,whichunder rthehoodre eadsthe configurationsettingsfr romWeb.config/app. .configoft theirASP.Net tor WForWCF Fservice.TheneedthisCachefFacto ory Objectto oretrievea nameddatacacheobjec ct.Thesewillbetheleastr requiredstep psforusers achedobjects s(data)fromtheAppFabri icCaching wantingtoaccesstheca Services.Th hefollowingc codeexcerptshowcasesth histechnique e: //Create instance of Cach e heFactory DataCach heFactory_factory= new Data = aCacheFactory(); //Get a named cache from the facto ory he_cache= _factory y.GetCache e("default"); DataCach Fromhere,userscande eploysimpleG GetandPutc commandstoreadorwrite e datafrom,ortotheApp pFabriccachin ngstorage.Th hissnippetus sesthesetwo o commandstowriteandthenreadcu ustomdatafromtheAppFabricCache: //Put da ata into a cache _cache.P Put("id01", new It tem("Test" "25.00", "...")); ", ... he same or a different client //Get th data from the s Item MyI Item = (Item) _cac che.Get("i id01"); // If no present in the cache ot if (MyIt tem== null) { //Read f from the b backend l layer MyItem= ReadFromDatabase( (); //Popula ate the Cache _cache.P Put("id01", new It tem("Test" "25.00", "...")); ", returnMy yItem; }

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Bes stPracti ices


Exp pirationtimeonVelocityshouldnotbesettoverysmallvalues,w which can nleadtoincre easingmemo oryconsumption.Thisoccu ursbecauseo of del laysrelatedto ogarbagecol llectioncalls olddataexp pires,butrem mains inm memory,andanewcopyo ofthedataisaddedtome emory. Loc calCache:For rbestperform mance,usersareadvisedt toenableonlythe Loc calCachesforobjectsthatchangeinfreq quently.Usin ngtheLocalCache for rfrequentlychangingdatamayincrease ethechanceofaclient wo orkingwithsta aleobjects.In ninstancesof ffrequentlyc changingdata a,itis bes sttodisablet theLocalCacheandpulldatadirectlyfr romtheclust ter. The edefaultsett tingforReque estTimeoutis s10seconds,andtherefor re use ersareadvise ednottoseti itat0.Ifthey ydo,theapplicationwillse eea tim meoutonever rycachecall. Eve enthoughhav vingjustoneCacheServer rintheclient tconfigurationcan suf ffice,itisreco ommendedto omaintainasmanycacheserverhost nam mesintheco onfigfile.

Constrai C ints
Thereisno odirectsuppo ortofcachedependencyin nWindowSer rverAppFabric caching.Ifd datagetscha angedinthed database,the esamedoesn notchangeinthe CacheClust ter.

10 0

BuildingHig ghPerformanc ceandScalable eApplicationsusingAppFabr ricCache

Summ mary
Theprimar ryadvantageofusingWind dowsServerA AppFabriccac cheisthecre eation ofscalable, ,availableandhighperfor rmanceapplic cations.Applicationsthatuse AppFabricc cacherespon ndfaster,beca ausetheyfetchdatafrom stead thecacheins ofretrievin ngitagainand dagainfromt thedatabase eorothersou urces.Ascache storesthes samedataon nmultiplecom mputers,itpr rovidesapplic cationavailab bility atalltimes.WindowsServerAppFab briccachealsoprovidesintegrationwit th atenablesAS SP.Netsession nobjectstob bestoredinth hedistributed d ASP.Nettha cache,with houthavingto owritetodat tabases.Thisincreasesthe escalabilityand performanc ceofASP.Net tapplications s.

Referen nces
1. 2. 3. tp://msdn.mic crosoft.com/enus/library y/ee677312.aspx htt htt tp://msdn.mic crosoft.com/library/cc645 5013.aspx Ste ephenKaufma an,DannyGar rber:ProWin ndowsServerAppFabric,A Apress

AboutImpet tus

ImpetusTech hnologiesoffersProductEng gineeringandT TechnologyR& &Dservicesforsoftwareprod ductdevelopment. Withongoing ginvestmentsinresearchan ndapplicationo ofemergingte echnologyarea as,innovativeb businessmode els,and anagileappr roach,wepartnerwithourclientbasecom mprisinglarges scaleISVsandt technologyinn novatorstodeliver cuttingedge esoftwareprod ducts.Ourexpertisespansth hedomainsofBigData,SaaS,CloudCompu uting,Mobility Solutions,Te estEngineering g,Performance eEngineering,andSocialMediaamongoth hers. ImpetusTechnologies,Inc. vard,Suite450 0,SanJose,CA95129,USA 5300StevensCreekBoulev @impetus.com Tel:408.213.3310|Email:inquiry@ velopmentCentersINDIA:NewDelhiBangaloreIn ndoreHydera abad RegionalDev Toknowmo orevisit:http:/ //www.impetus.com

Di isclaimers
Theinformationcon ntainedinthisdocumentistheprop prietaryandexclus sivepropertyofIm mpetusTechnologi iesInc.exceptaso otherwiseindicate ed.Nopartof isdocument,inwh holeorinpart,ma aybereproduced, ,stored,transmitted,orusedforde esignpurposeswithoutthepriorwri ittenpermissiono ofImpetus thi 11 1 TechnologiesInc.

Vous aimerez peut-être aussi