Microsoft SQL Server Analysis Services Multidimensional Performance and Operations Guide
Microsoft SQL Server Analysis Services Multidimensional Performance and Operations Guide
Summary: Download this book to learn about Analysis Services Multidimensional performance tuning from an operational and development perspective. This book consolidates the previously published SQL Server 2008 R2 Analysis Services Operations Guide and SQL Server 2008 R2 Analysis Services Performance Guide into a single publication that you can view on portable devices. Category: Guide Applies to: SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 Source: White paper (link to source content, link to source content) E-book publication date: May 2012 200 pages
Copyright 2012 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the authors views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Contents
1 2 Introduction..........................................................................................................................................5 Part1:BuildingaHighPerformanceCube...........................................................................................6 2.1 2.2 2.3 2.4 2.5 3 DesignPatternsforScalableCubes...........................................................................................6 TestingAnalysisServicesCubes..............................................................................................32 TuningQueryPerformance.....................................................................................................39 TuningProcessingPerformance..............................................................................................76 SpecialConsiderations............................................................................................................93
Part2:RunningaCubeinProduction...............................................................................................105 3.1 3.2 3.3 3.4 3.5 3.6 3.7 ConfiguringtheServer ..........................................................................................................106 . MonitoringandTuningtheServer........................................................................................133 SecurityandAuditing............................................................................................................143 HighAvailabilityandDisasterRecovery................................................................................147 DiagnosingandOptimizing....................................................................................................150 ServerMaintenance..............................................................................................................189 SpecialConsiderations..........................................................................................................192
Conclusion.........................................................................................................................................200
Sendfeedback...........................................................................................................................................200
1 Introduction
ThisbookconsolidatestwopreviouslypublishedguidesintooneessentialresourceforAnalysisServices developersandoperationspersonnel.AlthoughthetitlesoftheoriginalpublicationsindicateSQLServer 2008R2,mostoftheknowledgethatyougainfromthisbookiseasilytransferredtootherversionsof AnalysisServices,includingmultidimensionalmodelsbuiltusingSQLServer2012. Part1isfromtheSQLServer2008R2AnalysisServicesPerformanceGuide.PublishedinOctober 2011,thisguidewascreatedfordevelopersandcubedesignerswhowanttobuildhighperformance cubesusingbestpracticesandinsightslearnedfromrealworlddevelopmentprojects.InPart1,youll learnproventechniquesforbuildingsolutionsthatarefastertoprocessandquery,minimizingtheneed forfurthertuningdowntheroad. Part2isfromtheSQLServer2008R2AnalysisServicesOperationsGuide.Thisguide,publishedinJune 2011,isintendedfordevelopersandoperationsspecialistswhomanagesolutionsthatarealreadyin production.Part2showsyouhowtoextractperformancegainsfromaproductioncube,including changingserverandsystemproperties,andperformingsystemmaintenancethathelpyouavoid problemsbeforetheystart. Whileeachguidetargetsadifferentpartofasolutionlifecycle,havingbothinasingleportableformat givesyouanintellectualtoolkitthatyoucanaccessonmobiledeviceswhereveryoumaybe.Wehope youfindthisbookhelpfulandeasytouse,butitisonlyoneofseveralformatsavailableforthiscontent. YoucanalsogetprintableversionsofbothguidesbydownloadingthemfromtheMicrosoftwebsite.
dayinadatedimension,itsometimesmakessensetoexplicitlyassignadefaultmember.Forexample, youmaysetadefaultdateintheAdventureWorkscubelikethis.
ALTERCUBE [Adventure Works]UPDATE DIMENSION [Date], DEFAULT_MEMBER='[Date].[Date].&[2000]'
Youcano optimizeperfo ormancebyd defininghierarchicalrelatio onshipssupportedbythedata.Inthisc case, amodeln nameidentifie estheproduc ctlineandsubcategory,an ndthesubcat tegoryidentif fiesacategor ry.In otherwor rds,asingles subcategoryis snotfoundin nmorethano onecategory.Ifyouredefi inethe relationsh hipsintheatt tributerelatio onshipeditor, ,therelationshipsareclea arer.
Attributerelationships shelpperform manceinthre eesignificantways: sbetweenlev velsinthehie erarchydono otneedtogothroughthekeyattribute.This Crossproducts avesCPUtime eduringquer ries. sa Aggregationsb builtonattrib butescanber reusedforqu ueriesonrelat tedattributes s.Thissaves esourcesduringprocessing gandforque eries. re AutoExistcanmoreefficientlyeliminate eattributeco ombinationst thatdonotex xistinthedat ta.
Considert thecrosspro oductbetweenSubcategor ryandCatego oryinthetwo ofigures.Inthefirst,wher reno attributerelationshipshavebeenexplicitlydefin ned,theengin nemustfirstf findwhichpr roductsarein n 10
eachsubcategoryandthendeterminewhichcategorieseachoftheseproductsbelongsto.Forlarge dimensions,thiscantakealongtime.Iftheattributerelationshipisdefined,theAnalysisServices engineknowsbeforehandwhichcategoryeachsubcategorybelongstoviaindexesbuiltatprocesstime. 2.1.1.6.1 Flexible vs. Rigid Relationships Whenanattributerelationshipisdefined,therelationcaneitherbeflexibleorrigid.Aflexibleattribute relationshipisonewherememberscanmovearoundduringdimensionupdates,andarigidattribute relationshipisonewherethememberrelationshipsareguaranteedtobefixed.Forexample,the relationshipbetweenmonthandyearisfixedbecauseaparticularmonthisntgoingtochangeitsyear whenthedimensionisreprocessed.However,therelationshipbetweencustomerandcitymaybe flexibleascustomersmove. Whenachangeisdetectedduringprocessinaflexiblerelationship,allindexesforpartitionsreferencing theaffecteddimension(includingtheindexesforattributethatarenotaffected)mustbeinvalidated. ThisisanexpensiveoperationandmaycauseProcessUpdateoperationstotakeaverylongtime. IndexesinvalidatedbychangesinflexiblerelationshipsmustberebuiltafteraProcessUpdateoperation withaProcessIndexontheaffectedpartitions;thisaddsevenmoretimetocubeprocessing. Flexiblerelationshipsarethedefaultsetting.Carefullyconsidertheadvantagesofrigidrelationshipsand changethedefaultwherethedesignallowsit.
11
Fromaperformanceperspective,naturalhierarchiesbehaveverydifferentlythanunnaturalhierarchies do.Innaturalhierarchies,thehierarchytreeismaterializedondiskinhierarchystores.Inaddition,all attributesparticipatinginnaturalhierarchiesareautomaticallyconsideredtobeaggregationcandidates. Unnaturalhierarchiesarenotmaterializedondisk,andtheattributesparticipatinginunnatural hierarchiesarenotautomaticallyconsideredasaggregationcandidates.Rather,theysimplyprovide userswitheasytousedrilldownpathsforcommonlyviewedattributesthatdonothavenatural relationships.Byassemblingtheseattributesintohierarchies,youcanalsouseavarietyofMDX navigationfunctionstoeasilyperformcalculationslikepercentofparent. Totakeadvantageofnaturalhierarchies,definecascadingattributerelationshipsforallattributesthat participateinthehierarchy.
2.1.1.10
Fast-Changing Attributes
Somedatamodelscontainattributesthatchangeveryfast.Dependingonwhichtypeofhistorytracking youneed,youmayfacedifferentchallenges. Type2FastChangingAttributesIfyoutrackeverychangetoafastchangingattribute,thismaycause thedimensioncontainingtheattributetogrowverylarge.Type2attributesaretypicallyaddedtoa dimensionwithaProcessAddcommand.Atsomepoint,runningProcessAddonalargedimensionand runningalltheconsistencycheckswilltakealongtime.Also,havingahugedimensionisunwieldy becauseuserswillhavetroublequeryingitandtheserverwillhavetroublekeepingitinmemory.A goodexampleofsuchamodelingchallengeistheageofacustomerthiswillchangeeveryyearand causethecustomerdimensiontogrowdramatically. Type1FastChangingAttributesEvenifyoudonottrackeverychangetotheattribute,youmaystill runintoissueswithfastchangingattributes.Toreflectachangeinthedatasourcetothecube,you havetorunProcessUpdateonthechangeddimension.Asthecubeanddimensiongrowslarger, runningProcessUpdatebecomesexpensive.Anexampleofsuchamodelingchallengeistotrackthe statusattributeofaserverinahostingenvironment(Running,Shutdown,Overloadedandsoon). Astatusattributelikethismaychangeseveraltimesperdayorevenperhour.Runningfrequent ProcessUpdatesonsuchadimensiontoreflectchangescanbeanexpensiveoperation,anditmaynot befeasiblewiththelockingimplementationofAnalysisServicesinaproductionenvironment. 13
NoticethateverytimeThomashasabirthday,anewrowisaddedinthedimensiontable.The alternativedesignapproachsplitsthecustomerdimensionintotwodimensionslikethis.
14
Figure 55: Age in its own dimension
Notethattherearesomerestrictionsonthesituationwherethisdesigncanbeapplied.Itworksbest whenthechangingattributetakesonasmall,distinctsetofvalues.Italsoaddscomplexitytothe design;byaddingmoredimensionstothemodel,itcreatesmoreworkfortheETLdeveloperswhenthe facttableisloaded.Also,considerthestorageimpactonthefacttable:Withthealternativedesign,the facttablebecomeswider,andmorebyteshavetobestoredperrow. 2.1.1.10.2 Type 1 Fast-Changing Attributes Yourbusinessrequirementmaybeupdatinganattributeofadimensionathighfrequency,daily,or evenhourly.Forasmallcube,runningProcessUpdatewillhelpyouaddressthisissue.Butasthecube growslarger,theruntimeofProcessUpdatecanbecometoolongforthebatchwindoworthereal timerequirementsofthecube(youcanreadmoreabouttuningprocessupdateintheprocessing section). Consideragaintheserverhostingexample:Youmaywanttotrackthestatus,whichchangesfrequently, ofallservers.Fortheexample,letussaythattheserverdimensionisusedbyafacttabletracking performancecounters.Assumeyouhavemodeledlikethis.
15
Figure 66: Status column in server dimension
TheproblemwiththismodelistheStatuscolumn.IftheFactCounterislargeandstatuschangesalot, ProcessUpdatewilltakeaverylongtimetorun.Tooptimize,considerthisdesigninstead.
16
2.1.1.11
Large Dimensions
InSQLServer2005,SQLServer2008,andSQLServer2008R2,AnalysisServiceshassomebuiltin limitationsthatlimitthesizeofthedimensionsyoucancreate.Firstofall,ittakestimetoupdatea dimensionthisisexpensivebecauseallindexesonfacttableshavetobeconsideredforinvalidation whenanattributechanges.Second,stringvaluesindimensionattributesarestoredonadiskstructure calledthestringstore.Thisstructurehasasizelimitationof4GB.Ifadimensioncontainsattributes wherethetotalsizeofthestringvalues(thisincludestranslations)exceeds4GB,youwillgetanerror duringprocessing.ThenextversionofSQLServerAnalysisServices,codenamedDenali,isexpectedto removethislimitation. Considerforamomentadimensionwithtensorevenhundredsofmillionsofmembers.Sucha dimensioncanbebuiltandaddedtoacube,evenonSQLServer2005,SQLServer2008,andSQLServer 2008R2.Butwhatdoessuchadimensionmeantoanadhocuser?Howwilltheusernavigateit?Which hierarchieswillgroupthemembersofthisdimensionintoreasonablesizesthatcanberenderedona screen?Whileitmaymakesenseforsomereportingpurposestosearchforindividualmembersinsuch adimension,itmaynotbetherightproblemtosolvewithacube. Whenyoubuildcubes,askyourself:isthisacubeproblem?Forexample,thinkofthistypicaltelco modelofcalldetailrecords.
17
Figure 99: Cube built on aggregate
18
19
TheMinandMaxDataIDscanspecifyaeitherasinglememberorarangeofmembers.Forexample, partitioningbyyearresultsinthesameMinandMaxDataIDslicefortheyearattribute,andqueriestoa specificmomentintimeonlyresultinpartitionqueriestothatyearspartition. ItisimportanttorememberthatthepartitionsliceismaintainedasarangeofDataIDsthatyouhaveno explicitcontrolover.DataIDsareassignedduringdimensionprocessingasnewmembersare encountered.BecauseAnalysisServicesjustlooksattheminimumandmaximumvalueoftheDataID, youcanendupreadingpartitionsthatdontcontainrelevantdata. Forexample:ifyouhaveapartition,P2003_4,thatcontainsboth2003and2004data,youarenot guaranteedthattheminimumandmaximumDataIDintheslidecontainvaluesnexttoeachother(even thoughtheyearsareadjacent).Inourexample,letussaytheDataIDfor2003is42andtheDataIDfor 2004is45.BecauseyoucannotcontrolwhichDataIDgetsassignedtowhichmembers,youcouldbeina situationwheretheDataIDfor2005is44.Whenauserrequestsdatafor2005,AnalysisServiceslooksat thesliceforP2003_4,seesthatitcontainsdataintheinterval42to45andthereforeconcludesthatthis partitionhastobescannedtomakesureitdoesnotcontainthevaluesforDataID44(because44is between42and45). Becauseofthisbehavior,autoslicetypicallyworksbestifthedatacontainedinthepartitionmapstoa singleattributevalue.Whenthatisthecase,themaximumandminimumDataIDcontainedintheslice willbeequalandtheslicewillworkefficiently. Notethattheautosliceisnotdefinedandindexesarenotbuiltforpartitionswithfewerrowsthan IndexBuildThreshold(whichhasadefaultvalueof4096). 2.1.2.1.2 Manually Setting Slices NometadataisavailabletoAnalysisServicesaboutthecontentofROLAPandproactivecaching partitions.Becauseofthis,youmustmanuallyidentifythesliceinthepropertiesofthepartition.Itisa bestpracticetomanuallysetslicesinROLAPandproactivecachingpartitions. However,asshownintheprevioussection,therearecaseswhereautoslicewillnotgiveyouthe desiredpartitioneliminationbehavior.Inthesecasesyoucanbenefitfromdefiningthesliceyourselffor MOLAPpartitions.Forexample,ifyoupartitionbyyearwithsomepartitionscontainingarangeofyears, definingthesliceexplicitlyavoidstheproblemofoverlappingDataIDs.Thiscanonlybedonewith knowledgeofthedatawhichiswhereyoucanaddsomeoptimizationasaBIdeveloper. Itisgenerallynotabestpracticetocreatepartitionsbeforeyouarereadytofillthemwithdata.Butfor realtimecubes,itissometimesagoodideatocreatepartitionsinadvancetoavoidlockingissues. Whenyoutakethisapproach,itisalsoagoodideatosetamanualsliceonMOLAPpartitionstomake surethestorageenginedoesnotspendtimescanningemptypartitions.
20
21
Notethatinordertomovethepartitiontocheaperstorage,youwillhavetochangethedatalocation andreprocessesthepartition.Thisdesignworksverywellforsmalltomediumsizedcubes.Itis reasonablysimpletoimplementandthenumberofpartitionsiskeptlow.However,itdoessufferfroma fewdrawbacks: 1. Ifthegranularityofthepartitioningissmallenough(forexample,hourly),thenumberof partitionscanquicklybecomeunmanageable. 2. Assumingdataisaddedonlytothelatestpartition,partitionprocessingislimitedtooneTCP/IP connectionreadingfromthedatasource.Ifyouhavealotofdata,thiscanbeascalabilitylimit. Ad1)Ifyouhavealotofdatebasedpartitions,itisoftenagoodideatomergetheolderonesintolarge partitions.YoucandothiseitherbyusingtheAnalysisServicesmergefunctionalityorbydroppingthe oldpartitions,creatinganew,largerpartition,andthenreprocessingit.Reprocessingwilltypicallytake
22
longerthanmerging,butwehavefoundthatcompressionofthepartitioncanoftenincreaseifyou reprocess.Amodified,datepartitioningschememaylooklikethis.
Thisdesignaddressesthemetadataoverheadofhavingtoomanypartitions.Butitisstillbottlenecked bythemaximumspeedoftheProcessAddorProcessFullforthelatestpartition.Ifyourdatasourceis SQLServer,thespeedofasingledatabaseconnectioncanbehundredsofthousandsofrowsevery secondwhichworkswellformostscenarios.Butifthecuberequiresevenfasterprocessingspeeds, considermatrixpartitioning. 2.1.2.3.2 Matrix Partitioning Forlargecubes,itisoftenagoodideatoimplementamatrixpartitioningscheme:partitiononboth dateandsomeotherkey.Thedatepartitioningisusedtoselectivelydeleteormergeoldpartitionsas describedearlier.Theotherkeycanbeusedtoachieveparallelismduringpartitionprocessingandto restrictcertainuserstoasubsetofthepartitions.Forexample,consideraretailerthatoperatesinUS, Europe,andAsia.Youmightdecidetopartitionlikethis.
23
Figure 1414: Example of matrix partitioning
Iftheretailergrows,theymaychoosetosplittheregionpartitionsintosmallerpartitionstoincrease parallelismofloadfurtherandtolimittheworstcasescansthatausercanperform.Forcubesthatare expectedtogrowdramatically,itisagoodideatochooseapartitionkeythatgrowswiththebusiness andgivesyouoptionsforextendingthematrixpartitioningstrategyappropriately.Thefollowingtable containsexamplesofsuchpartitioningkeys. Industry Webretail Storeretail Datahosting 24 Examplepartitionkey Customerkey Storekey HostIDorracklocation Sourceofdataproliferation Addingcustomersandtransactions Addingnewstores Addinganewserver
SwitchID,countrycode,orarea Expandingintonewgeographical code regionsoraddingnewservices ProductionlineIDormachineID Addingproductionlinesor(for machines)sensors Stockexchangeorfinancial Addingnewfinancialinstruments, instrument products,ormarkets Creditcardnumberorcustomer Increasingcustomertransactions key Gamekeyorplayerkey Addingnewgamesorplayers
Ifyouimplementamatrixpartitioningscheme,youshouldpayspecialattentiontouserqueries.Queries touchingseveralpartitionsforeverysubcuberequest,suchasaquerythatasksforahighlevel aggregateofthepartitionbusinesskey,resultinahighthreadusageinthestorageengine.Becauseof this,werecommendthatyoupartitionthebusinesskeysothatsinglequeriestouchnomorethanthe numberofcoresavailableonthetargetserver.Forexample,ifyoupartitionbyStoreKeyandyouhave 1,000stores,queriestouchingtheaggregationofallstoreswillhavetotouch1,000partitions.Insucha design,itisagoodideatogroupthestoresintoanumberofbuckets(thatis,groupthestoresoneach partition,ratherthanhavingindividualpartitionsforeachstore).Forexample,ifyourunona16core server,youcangroupthestoreintobucketsofaround62storesforeachpartition(1,000storesdivided into16buckets). 2.1.2.3.3 Hash Partitioning Sometimesitisnotpossibletocomeupwithagooddistributionofbusinesskeysforpartitioningthe cube.Perhapsyoujustdonthaveagoodkeycandidatethatfitsthedescriptionintheprevioussection, orperhapsthedistributionofthekeyisunknownatdesigntime.Insuchcases,abruteforceapproach canbeused:Partitiononthehashvalueofakeythathasahighenoughcardinalityandwherethereis littleskew.Ifyouexpecteveryquerytotouchmanypartitions,itisimportantthatyoupayspecial attentiontotheCoordinatorQueryBalancingFactorandtheCoordinatorQueryMaxThreadsettings, whicharedescribedinPart2.
25
27
Viewsprovideencapsulation,anditisgoodpracticetousethem.Iftherelationaldatamodelersinsist onnormalization,givethemachancetochangetheirmindsanddenormalizewithoutbreakingthecube model. Viewsalsoprovideeasyofdebugging.YoucanissueSQLqueriesdirectlyonviewstocomparethe relationaldatawiththecube.Hence,viewsaregoodwaytoimplementbusinesslogicthatcouldyou couldmimicwithquerybindingintheUDM.WhiletheUDMsyntaxissimilartotheSQLviewsyntax,you cannotissueSQLstatementsagainsttheUDM. 2.1.3.3.1 Query Binding Dimensions QuerybindingfordimensionsdoesnotexistinSQLServer2008AnalysisServices,butyoucan implementitbyusingaview(insteadoftables)foryourunderlyingdimensiondatasource.Thatway, youcanusehints,indexedviews,orotherrelationaldatabasetuningtechniquestooptimizetheSQL statementthataccessesthedimensiontablesthroughyourview.Thisalsoallowsyoutoturna snowflakedesignintherelationalsourceintoaUDMthatisapurestarschema. 2.1.3.3.2 Processing Through Views Dependingontherelationalsource,viewscanoftenprovidemeanstooptimizethebehaviorofthe relationaldatabase.Forexample,inSQLServeryoucanusetheNOLOCKhintintheviewdefinitionto removetheoverheadoflockingrowsastheviewisscanned,balancingthiswiththepossibilityofgetting dirtyreads.ViewscanalsobeusedtopreaggregatelargefacttablesusingaGROUPBYstatement;the relationaldatabasemodelercanevenchoosetomaterializeviewsthatusealotofhardwareresources. 28
29
CREATESET[CurrentDay]ASTAIL([Date].[Calendar].members,1) CREATESET[PreviousDay]ASHEAD(TAIL(Date].[Calendar].members),2),1)
Dothis(assumingtodayis20110616): CalendarKeyAttribute 20110613 20110614 20110615 20110616 DayTypeAttribute (Flexiblerelationshiptokey) OldDates OldDates PreviousDay CurrentDay
ProcessUpdatethedimensionwhenthedaychanges.Userscannowrefertothecurrentdayby addressingtheDayTypeattributeinsteadoftheset.
Instead,usetheAnalysisServicesSCOPEfunctionforthis.
CREATEMEMBERCurrentCube.[Measures].[SixMonthRollingAverage] ASNULL,FORMAT_STRING="Currency",VISIBLE=1; SCOPE([Measures].[SixMonthRollingAverage],[Date].[Calendar].[Month].Members); THIS=Sum([Date].[Calendar].CurrentMember.Lag(5) :[Date].[Calendar].CurrentMember ,[Measures].[InternetSalesAmount])/6;
30
ENDSCOPE;
YoucanreproduceeachthesefeaturesinMDXscript(infact,sometimesyoumust,becausesomeare onlysupportedintheEnterpriseSKU),butdoingsooftenhurtsperformance. Forexample,usingdistributiveunaryoperators(thatis,thosewhosememberorderdoesnotmatter, suchas+,,and~)isgenerallytwiceasfastastryingtomimictheircapabilitieswithassignments. Therearerareexceptions.Forexample,youmightbeabletoimproveperformanceofnondistributive unaryoperators(thoseinvolving*,/,ornumericvalues)withMDX.Furthermore,youmayknowsome specialcharacteristicofyourdatathatallowsyoutotakeashortcutthatimprovesperformance.Such optimizationsrequireexpertleveltuningandingeneral,youcanrelyontheAnalysisServicesengine featurestodothebestjob. Measureexpressionsalsoprovideauniquechallenge,becausetheydisabletheuseofaggregates(data hastoberolledupfromtheleaflevel).Onewaytoworkaroundthisistouseahiddenmeasurethat containspreaggregatedvaluesintherelationalsource.Youcanthentargetthehiddenmeasuretothe aggregatevalueswithaSCOPEstatementinthecalculationscript.
Furthermore,dontperformextrastepswhendeducingwhetherCurrentMemberisaparticular memberbyinvolvingIntersectandCounting.
31
intersect({[Customer].[CustomerGeography].[Country].&[Australia]}, [Customer].[CustomerGeography].currentmember).count>0
UseISinstead.
[Customer].[CustomerGeography].[Country].&[Australia]is[Customer].[Customer Geography].currentmember
ThisstatementusesIntersecttodeterminewhetherthespecifiedinformationisintheset.
intersect({[Customer].[CustomerGeography].[Country].&[Australia]},<set>).count>0
significantamountofdata.Youshouldconsiderwhatyouwanttodowithsuchqueries.Thereare multipleoptions:Forexample,youmaychoosetoscaleyourhardwaretohandletheminadecent responsetime,oryoumaysimplychoosetocancelthem.Ineithercase,asyoupreparefortesting, makesuresuchqueriesarepartthetestsuiteandthatyouobservewhathappenstotheAnalysis Servicesinstancewhentheyrun.Youshouldalsounderstandwhatareasonableresponsetimeisfor yourenduserandmakethatpartofthetestsuite. AsaBIdeveloper,youcanlookatthecubeasyourdescriptionofthemultidimensionalspaceinwhich queriescanbeexpressed.Apartofthisspacewillbeinstantiatedwithdatastructuresondisk supportingit:dimensions,measuregroups,andtheirpartitions.However,someofthis multidimensionalspacewillbeservedbycalculationsoradhocmemorystructures,forexample:MDX calculations,manytomanydimensions,andcustomrollups.Wheneverqueriesarenotserveddirectly byinstantiateddata,thereisapotential,querytimecalculationpricetobepaid,thismayshowupas badresponsetime.Asthecubedeveloper,youshouldmakesurethatthetestingcoversthesecases. Hence,astheBIdeveloper,youshouldmakesurethetestqueriesalsostressnoninstantiateddata.This isavaluableexercise,becauseyoucanuseittomeasuretheimpactonusersofcomplexcalculations andthenadjustthedatamodelaccordingly. Yourapproachtotestingwilldependonwhichsituationyoufindyourselfin.Ifyouaredevelopinganew system,youcanworkdirectlytowardsthetestgoalsdrivenbybusinessrequirements.However,ifyou aretryingtoimproveanexistingsystem,itisanadvantagetoacquireatestbaselinefirst.
toasizethatwillfitinmemory,eliminatingtheneedforthemajorityofI/Ooperationsandproviding fastscantimesevenforpoorlyfilteredqueries. Hereisatableofpotentialtestgoalsyoushouldconsider.Iftheyarerelevantforyourorganizations requirements,youshouldtailorthemtoreflectthoserequirements. TestGoal Scalability Examplegoal Mustsupport10,000 concurrentlyconnectedusers,of which1,000runqueries simultaneously. Simplequeriesreturninga Howfastshouldqueriesreturntotheclient? singleproductgroupforagiven Thismayrequireyoutoclassifyqueriesinto yearshouldreturninlessthan1 differentcomplexities. secondevenatfulluser Notallqueriescanbeansweredquicklyandit concurrency. willoftenbewisetoconsultanexpertcube designertoliaisewithuserstounderstandwhat Queriesthattouchnomore querypatternscanbeexpectedandwhatthe than20%ofthefactrowsshould runinlessthan30seconds. complexityofansweringthesequerieswillbe. Mostotherqueriestouchinga smallpartofthecubeshould Anotherwaytolookatthistestgoalisto returninaround10seconds. measurethethroughputinqueriesanswered Withourworkload,weexpect persecondinamixedworkload. throughputtobearound50 queriesreturnedpersecond. Userqueriesrequestingthe endofmonthcurrencyrate conversionshouldreturninno morethan20seconds.Queries thatdonotrequirecurrency conversionshouldreturninless than5seconds. Whatisthegranularityofeachdimension Thelargestcustomerdimension attribute?Howmuchdatawilleachmeasure willcontain30millionrowsand groupcontain? have10attributesandtwouser hierarchies.Thelargestnonkey Notethatthecubedesignerswilloftenhave attributewillhave1million beenconsideringthisandmayalreadyknowthe members. answer. Thelargestmeasuregroupis sales,with1billionrows.The secondlargestispurchases,with 100millionrows.Allother measuregroupsaretrivialin size. Description Howmanyconcurrentusersshouldbe supportedbythesystem?
Performance/ throughput
DataSizes
34
TargetServer Platforms
TargetI/O system
WhichI/Osystemdoyouwanttouse?What characteristicswillthatsystemhave?
Targetnetwork infrastructure
Processing Speeds
Howfastshouldrowsbebroughtintothecube andhowoften?
Mustrunon2socket6core Nehalemmachinewith32GBof RAM. Mustbeabletoscaleto4 socketNehalem8coremachine with256GBofRAM. MustrunoncorporateSANand usenomorethan1,000random IOPSat32,000blocksizesat6ms latency. WillrunondedicatedNAND devicesthatsupport80,000IOPS at100slatency. Intheworstcasescenario, userswillconnectovera100ms latencyWANlinkwitha maximumbandwidthof 10Mbit/sec. Therewillbea10Gbit dedicatednetworkavailable betweenthedatasourceandthe cube. Dimensionsshouldbefully processedeverynightwithin30 minutes. Twotimesduringtheday, 100,000,000rowsshouldbe addedtothesalesmeasure group.Thisshouldtakeno longerthan15minutes.
35
Queriesthattouchseveraldimensionsatthesametime EnoughqueriestotesteveryMDXexpressioninthecalculationscript Queriesthatexercisemanytomanydimensions Queriesthatexercisecustomrollups Queriesthatexerciseparent/childdimensions Queriesthatexercisedistinctcountmeasuregroups Queriesthatcrossjoinattributesfromdimensionsthatcontainmorethan100,000members Queriesthattoucheverysinglepartitioninthedatabase Queriesthattouchalargesubsetofpartitionsinthedatabase(forexample,currentyear) Queriesthatreturnalotofdatatotheclient(forexample,morethan100,000rows) Queriesthatusecubesecurityversusqueriesthatdonotuseit Queriesexecutingconcurrentlywithprocessingoperationsifthisispartofyourdesign
Youshouldtestonthefulldatasetfortheproductioncube.Ifyoudont,theresultswillnotbe representativeofreallifeoperations.Thisisespeciallytrueforcubesthatarelargerthanthememory onthemachinetheywilleventuallyrunon. Ofcourse,youshouldstillmakesurethatyouhaveplentyofqueriesinthetestscenariosthatrepresent typicaluserbehaviorsrunningonaworkloadthatonlyshowcasestheslowestperformingpartsofthe cubewillnotrepresentarealproductionenvironment(unlessofcourse,theentirecubeispoorly designed). Asyourunthetests,youwilldiscoverthatcertainqueriesaremoredisruptivethanothers.Onegoalof testingistodiscoverwhatsuchquerieslooklike,sothatyoucaneitherscalethesystemtodealwith themorprovideguidanceforuserssothattheycanavoidexercisingthecubeinthiswayifpossible. Partofyourtestscenariosshouldalsoaimtoobservethecubesbehaviorasuserconcurrencygrows. YoushouldworkwithBIdevelopersandbusinessuserstounderstandwhattheworstcasescenariofor userconcurrencyis.Testingatthatconcurrencywillshakeoutpoorlyscalabledesignsandhelpyou configurethecubeandhardwareforbestperformanceandstability.
36
ThirdpartytoolsYoucanusetoolssuchasHPLoadRunnertogeneratehighconcurrencyload.Note thatAnalysisServicesalsosupportsanHTTPbasedinterface,whichmeansitmaybepossibletouse webstresstoolstogenerateload. Rollyourown:Wehaveseencustomerswritetheirowntestharnessesusing.NETandtheADOMD.NET interfacetoAnalysisServices.Usingthe.NETthreadinglibraries,itispossibletogeneratealotofuser loadfromasingleloadclient. Nomatterwhichloadtoolyouuse,youshouldmakesureyoucollecttheruntimeofallqueriesandthe PerformanceMonitorcountersforallruns.Thisdataenablesyoutomeasuretheeffectofanychanges youmakeduringyourtestruns.Whenyougenerateuserworkloadtherearealsosomeotherfactorsto consider. Firstofall,youshouldtestbothasequentialrunandaparallelrunofqueries.Thesequentialrungives youthebestpossibleruntimeofthequerywhilenootherusersareonthesystem.Theparallelrun enablesyoutoshakeoutissueswiththecubethataretheresultofmanyusersrunningconcurrently. Second,youshouldmakesurethetestscenarioscontainasufficientnumberofqueriessothatyouwill beabletorunthetestscenarioforsometime.Tostresstheserverproperly,andtoavoidqueryingthe samehotspotvaluesoverandoveragain,queriesshouldtouchavarietyofdatainthecube.Ifallyour queriestouchasmallsetofdimensionvalues,itwillhardlyrepresentarealproductionrun.Onewayto spreadqueriesoverawidersetofcellsinthecubeistousequerytemplates.Eachtemplatecanbeused togenerateasetofqueriesthatareallvariantsofthesamegeneraluserbehavior. Third,yourtestharnessshouldbeabletocreatereproducibletests.Ifyouareusingcodethatgenerates manyqueriesfromasmallsetoftemplates,makesurethatitgeneratesthesamequeriesonevery testrun.Ifnot,youintroduceanelementofrandomnessinthetestthatmakesithardtocompare differentruns. References: Ascmd.exeonMSDNhttp://msdn.microsoft.com/en us/library/ms365187%28v=sql.100%29.aspx AnalysisServicesCommunitysampleshttp://sqlsrvanalysissrvcs.codeplex.com/ o Describeshowtouseascmdforloadgeneration o ContainsVisualStudiosamplecodethatachievesasimilareffect HPLoadRunner https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&cp=111 12617^8_4000_100
37
Clearingformulaengineandstorageenginecaches:ThefirsttwocachescanbeclearedwiththeXMLA ClearCachecommand.Thiscommandcanbeexecutedusingtheascmdcommandlineutility:
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID><database name></DatabaseID> </Object> </ClearCache>
Clearingfilesystemcaches:Thefilesystemcacheisabithardertogetridofbecauseitresidesinside Windowsitself. IfyouhavecreatedaseparateWindowsvolumeforthecubedatabase,youcandismountthevolume itselfusingthefollowingcommand: fsutil.exevolumedismount<DriveLetter|MountPoint> Thisclearsthefilesystemcacheforthisdriveletterormountpoint.Ifthecubedatabaseresidesonlyon thislocation,runningthiscommandresultsinacleanfilesystemcache. Alternatively,youcanusetheutilityRAMMapfromsysinternals.Thisutilitynotonlyallowsyoutoread thefilesystemcachecontent,italsoallowsyoutopurgeit.Ontheemptymenu,clickEmptySystem WorkingSet,andthenclickEmptyStandbyList.Thisclearsthefilesystemcachefortheentiresystem. NotethatwhenRAMMapstartsup,ittemporarilyfreezesthesystemwhileitreadsthememorycontent thiscantakesometimeonalargemachine.Hence,RAMMapshouldbeusedwithcare. ThereiscurrentlyaCodePlexprojectcalledASStoredProceduresfoundat: http://asstoredprocedures.codeplex.com/wikipage?title=FileSystemCache.Thisprojectcontainscode forautilitythatenablesyoutoclearthefilesystemcacheusingastoredprocedurethatyoucanrun directlyonAnalysisServices. NotethatneitherFSUTILnorRAMMapshouldbeusedinproductioncubesbothcausedisruptionto usersconnectedtothecube.AlsonotethatneitherRAMMaporASStoredProceduresissupportedby Microsoft.
38
Testyourdatacollectionsetup:Testrunsgiveyouauniquechancetotryoutyourdatacollection proceduresbeforeyougointoproduction.Thedatacollectionyouperformcanalsobeusedtodrive earlyfeedbacktothedevelopmentteam. Understandserverutilization:Whileyoutest,youcangetanearlyinsightintoserverutilization.You willbeabletomeasurethememoryusageofthecubeandthewaythenumberofusersmapstoI/O loadandCPUutilization.Ifthecubeislargerthanmemory,youcanalsomeasuretheeffectof concurrencyandleaflevelscanontheI/Osubsystem.Remembertomeasuretheworstcaseexamples describedearliertounderstandwhattheimpactonthesystemis. Earlythreadtuning:Duringtesting,youcandiscoverthreadingbottlenecks,asdescribedinPart1.This enablesyoutogointoproductionwithpretunedsettingsthatimproveuserexperience,scalability,and hardwareutilizationofthesolution.
39
ClientApp(MDX)
SessionManagement
QueryProcessing
QueryProcessor
QueryProcCache
DataRetrieval
Storage Engine
SECache
41
Duringexecution,everyMDXquerymustreferenceallthreecontextstoidentifyallofthepotential calculationsandsecurityconditionsthatcanimpacttheevaluationofthequery.Forexample,toresolve aquerythatcontainsaquerycalculatedmember,thequeryprocessorcreatesaquerycontextto resolvethequerycalculatedmember,createsasessioncontexttoevaluatesessioncalculations,and createsaglobalcontexttoevaluatetheMDXscriptandretrievethesecuritypermissionsoftheuser whosubmittedthequery.Notethatthesecontextsarecreatedonlyiftheyarentalreadybuilt.After theyarebuilt,theyarereusedwherepossible. Eventhoughaqueryreferencesallthreecontexts,itwilltypicallyusethecacheofasinglecontext.This meansthatonaperquerybasis,thequeryprocessormustselectwhichcachetouse.Thequery processoralwaysattemptstousethebroadlyapplicablecachedependingonwhetherornotitdetects thepresenceofcalculationsatanarrowercontext. Ifthequeryprocessorencounterscalculationscreatedatquerytime,italwaysusesthequerycontext, evenifaqueryalsoreferencescalculationsfromtheglobalcontext(thereisanexceptiontothis 42
querieswithquerycalculatedmembersoftheformAggregate(<set>)dosharethesessioncache).If therearenoquerycalculations,buttherearesessioncalculations,thequeryprocessorusesthesession cache.Thequeryprocessorselectsthecachebasedonthepresenceofanycalculationinthescope.This behaviorisespeciallyrelevanttouserswithMDXgeneratingfrontendtools.Ifthefrontendtool createsanysessioncalculationsorquerycalculations,theglobalcacheisnotused,evenifyoudonot specificallyusethesessionorquerycalculations. Thereareothercalculationscenariosthatimpacthowthequeryprocessorcachescalculations.When youcallastoredprocedurefromanMDXcalculation,theenginealwaysusesthequerycache.Thisis becausestoredproceduresarenondeterministic(meaningthatthereisnoguaranteewhatthestored procedurewillreturn).Asaresult,afteranondeterministiccalculationisencounteredduringthequery, nothingiscachedgloballyorinthesessioncache.Instead,theremainingcalculationsarestoredinthe querycache.Inaddition,thefollowingscenariosdeterminehowthequeryprocessorcachescalculation results: TheuseofMDXfunctionsthatarelocaledependent(suchasCaptionor.Properties)prevents theuseoftheglobalcache,becausedifferentsessionsmaybeconnectedwithdifferentlocales andcachedresultsforonelocalemaynotbecorrectforanotherlocale. Theuseofcellsecurity;functionssuchasUserName,StrToSet,StrToMember,andStrToTuple; orLookupCubefunctionsintheMDXscriptorinthedimensionorcellsecuritydefinitiondisable theglobalcache.Thatis,justoneexpressionthatusesanyofthesefunctionsorfeatures disablesglobalcachingfortheentirecube. IfvisualtotalsareenabledforthesessionbysettingthedefaultMDXVisualModepropertyin theAnalysisServicesconnectionstringto1,thequeryprocessorusesthequerycacheforall queriesissuedinthatsession. IfyouenablevisualtotalsforaquerybyusingtheMDXVisualTotalsfunction,thequery processorusesthequerycache. Queriesthatusethesubselectsyntax(SELECTFROMSELECT)orarebasedonasessionsubcube (CREATESUBCUBE)resultinthequeryor,respectively,sessioncachetobeused. Arbitraryshapescanonlyusethequerycacheiftheyareusedinasubselect,intheWHERE clause,orinacalculatedmember.Anarbitraryshapeisanysetthatcannotbeexpressedasa crossjoinofmembersfromthesamelevelofanattributehierarchy.Forexample,{(Food,USA), (Drink,Canada)}isanarbitraryset,asis{customer.geography.USA,customer.geography.[British Columbia]}.Notethatanarbitraryshapeonthequeryaxisdoesnotlimittheuseofanycache.
AnalysisServicesformulaenginetothestorageengine,itsendsarequestintheformofasubcube describingthestructureofthedatarequestandadatacachestructurethatwillcontaintheresultsof therequest.Usingthedatacacheregistryindexes,itattemptstofindacorrespondingsubcube: Ifthereisamatchingsubcube,thecorrespondingdatacacheisreturned. Ifasubcubesupersetisfound,anewdatacacheisgeneratedandtheresultsarefilteredtofit thesubcuberequest. Iflowergraindataexists,thedatacacheregistrycanaggregatethisdataandmakeitavailable aswellandthenewsubcubeanddatacachearealsoregisteredinthecacheregistry. Ifdatadoesnotexist,therequestgoestothestorageengineandtheresultsarecachedinthe cacheregistryforfuturequeries.
AnalysisServicesallocatesmemoryviamemoryholdersthatcontainstatisticalinformationaboutthe amountofmemorybeingused.Memoryholdersareintheformofnonshrinkableandshrinkable memory;eachcombinationofasubcubeanddatacacheformsasingleshrinkablememoryholder. WhenAnalysisServicesisunderheavymemorypressure,cleanerthreadsremoveshrinkablememory. Therefore,ensureyoursystemhasenoughmemory;ifitdoesnot,yourdatacacheregistrywillbe clearedout(resultinginslowerqueryperformance)whenitisplacedundermemorypressure. 2.3.1.3.2 Aggressive Data Scanning Sometimes,intheevaluationofanexpression,moredataisrequestedthanrequiredtodeterminethe result. Ifyoususpectmoredataisbeingretrievedthanisrequired,youcanuseSQLServerProfilertodiagnose howaqueryintosubcubequeryeventsandpartitionscans.Forsubcubescans,checktheverbose subcubeeventandwhethermoremembersthanrequiredareretrievedfromthestorageengine.For smallcubes,thislikelyisntaproblem.Forlargercubeswithmultiplepartitions,itcangreatlyreduce queryperformance.Thefollowingfiguredemonstrateshowasinglequerysubcubeeventresultsin partitionscans.
45
Acellbycellevaluationofthiscalculationproceedsasrepresentedinthefollowingfigure.
46
Figure 2222: Cell-by-cell evaluation
The10cellsfor[2005,AllProducts]areeachevaluatedinturn.Foreach,thepreviousyearislocated, andthenthesalesvalueisobtainedandthenaddedtothesalesforthecurrentyear.Therearetwo significantperformanceissueswiththisapproach. Firstly,ifthedataissparse(thatis,thinlypopulated),cellsarecalculatedeventhoughtheyareboundto returnanullvalue.Inthepreviousexample,calculatingthecellsforanythingbutProduct3andProduct 6isawasteofeffort.Theimpactofthiscanbeextremeinasparselypopulatedcube,thedifference canbeseveralordersofmagnitudeinthenumbersofcellsevaluated. Secondly,evenifthedataistotallydense,meaningthateverycellhasavalueandthereisno wastedeffortvisitingemptycells,thereismuchrepeatedeffort.Thesamework(forexample,getting thepreviousYearmember,settingupthenewcontextforthepreviousYearcell,checkingforrecursion) isredoneforeachProduct.Itwouldbemuchmoreefficienttomovethisworkoutoftheinnerloopof evaluatingeachcell. Nowconsiderthesameexampleperformedusingsubspacecomputation.Insubspacecomputation,the engineworksitswaydownanexecutiontreedeterminingwhatspacesneedtobefilled.Giventhe query,thefollowingspaceneedstobecomputed,where*meanseverymemberoftheattribute hierarchy. [Product.*,2005,RollingSum]
Giventhecalculation,thismeansthatthefollowingspaceneedstobecomputedfirst. 47 [Product.*,2004,Sales]
Next,thefollowingspacemustbecomputed. [Product.*,2005,Sales]
49
True
False
50
where[Customer].[CustomerGeography].[Customer].&[25818]
BoththeAnalysisServicesandtheoperatingsystemcachesneedtobeclearedbeforeyoustarttaking measurements. 2.3.3.1.1 Clearing the Analysis Services Caches TheAnalysisServicesformulaengineandstorageenginecachescanbeclearedwiththeXMLA ClearCachecommand.YoucanuseSQLServerManagementStudiotorunClearCache.
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID><database name></DatabaseID> </Object> </ClearCache>
2.3.3.1.2 Clearing the Operating System Caches ThefilesystemcacheisabithardertogetridofbecauseitresidesinsideWindowsitself.Youcanuse anyofthefollowingtoolstoperformthistask: Fsutil.exe:WindowsFileSystemUtility IfyouhavecreatedaseparateWindowsvolumeforthecubedatabase,youcandismountthe volumeitselfusingthefollowingcommand: fsutil.exevolumedismount<DriveLetter|MountPoint> Thisclearsthefilesystemcacheforthisdriveletterormountpoint.Ifthecubedatabaseresides onlyonthislocation,runningthiscommandresultsinacleanfilesystemcache.
51
RAMMap:Sysinternalstool Alternatively,youcanuseRAMMapfromSysinternals(asofthiswriting,RAMMapv1.11is availableat:http://technet.microsoft.com/enus/sysinternals/ff700229.aspx).RAMMapcan helpyouunderstandhowWindowsmanagesmemory.Thistoolnotonlyallowsyoutoreadthe filesystemcachecontent,italsoallowsyoutopurgeit.Ontheemptymenu,clickEmpty SystemWorkingSet,andthenclickEmptyStandbyList.Thisclearsthefilesystemcacheforthe entiresystem.NotethatwhenRAMMapstartsup,ittemporarilyfreezesthesystemwhileit readsthememorycontentthiscantakesometimeonalargemachine.Hence,RAMMap shouldbeusedwithcare. AnalysisServicesStoredProcedureProject(CodePlex):FileSystemCacheclass ThereiscurrentlyaCodePlexprojectcalledtheAnalysisServicesStoredProcedureProjectfound at:http://asstoredprocedures.codeplex.com/wikipage?title=FileSystemCache.Thisproject containscodeforautilitythatenablesyoutoclearthefilesystemcacheusingastored procedurethatyoucanrundirectlyonAnalysisServices.
Savetheprofilertrace,becauseitcontainsimportantinformationthatyoucanusetodiagnoseslow querytimes.
52
Figure 2424: Sample trace
query,itcanbetimeconsumingtolocatetheproblem.Trytoreducethequerytothesimplest expressionpossiblethatcontinuestoreproducetheperformanceissue.Ifpossible,removeexpressions suchasMDXscripts,unaryoperators,measureexpressions,custommemberformulas,semiadditive measures,andcustomrollupproperties.Withsomeclientapplications,thequerygeneratedbythe clientitself,notthecube,canbetheproblem.Forexample,problemscanarisewhenclientapplications generatequeriesthatdemandlargedatavolumes,pushdowntounnecessarilylowgranularities, unnecessarilybypassaggregations,orcontainquerycalculationsthatbypasstheglobalandsession queryprocessorcaches.Ifyoucanconfirmthattheissueisinthecubeitself,commentoutcalculated membersinthecubeorqueryuntilyouhavenarroweddowntheoffendingcalculation.Usingabinary chopmethodisusefultoquicklyreducethequerytothesimplestformthatreproducestheissue. Experiencedtunerswillbeabletoquicklynarrowinontypicalcalculationissues. Whenyouhaveremovedcalculationsuntiltheperformanceissuereproduces,thefirststepisto determinewhethertheproblemliesinthequeryprocessor(theformulaengine)orthestorageengine. Todeterminetheamountoftimetheenginespendsscanningdata,usetheSQLServerProfilertrace createdearlier.Limittheeventstononcachedstorageengineretrievalsbyselectingonlythequery subcubeverboseeventandfilteringonevent subclass = 22.Theresultwillbesimilartothe following.
Ifthemajorityoftimeisspentinthestorageenginewithlongrunningquerysubcubeevents,the problemislikelywiththestorageengine.Inthiscase,consideroptimizingdimensiondesign,designing aggregations,orusingpartitionstoimprovequeryperformance.Inaddition,youmaywanttoconsider optimizingthedisksubsystem. Ifthemajorityoftimeisnotspentinthestorageenginebutinthequeryprocessor,focusonoptimizing theMDXscriptorthequeryitself.Note,theproblemcaninvolveboththeformulaandstorageengines. AfragmentedqueryspacecanbediagnosedwithSQLServerProfilerifyouseemanyquerysubcube eventsgeneratedbyasinglequery.Eachrequestmaynottakelong,butthesumofthemmay.Ifthisis thecase,considerwarmingthecachetomakesuresubcubesandcalculationsarealreadycached.Also, considerrewritingthequerytoremovearbitraryshapes,becausearbitrarysubcubescannotbecached. Formoreinformation,seeCacheWarminginalatersection.
54
IfthecubeandMDXqueryarealreadyfullyoptimized,youmayconsiderdoingthread,memory,and configurationtuningofthecube.Youmayevenwanttolookatlargerhardware.Serverleveltuning techniquesaredescribedinPart2. References: TheSQLServer2008R2AnalysisServicesOperations Guide(http://sqlcat.com/sqlcat/b/whitepapers/archive/2011/06/01/sqlserver2008r2analysis servicesoperationsguide.aspx) PredeploymentI/OBestPractices (http://sqlcat.com/sqlcat/b/whitepapers/archive/2007/11/21/predeploymentiobest practices.aspx):TheconceptsinthisdocumentprovideanoverviewofdiskI/Oanditsimpact queryperformance;focusontherandomI/Ocontext. ScalableSharedDatabasesPart5 (http://sqlcat.com/sqlcat/b/whitepapers/archive/2011/06/01/sqlserver2008r2analysis servicesoperationsguide.aspx):Reviewtobetterunderstandonqueryperformanceincontext ofrandomI/Ovs.sequentialI/O.
However,almostthesamequery,wherethesetisreplacedwithanalias, operatesincellbycellmode: 55
with set y as [Product].[Category].[Category].members member measures.Naive as sum( y, [Measures].[Internet Sales Amount] ) select {measures.Naive,[Measures].[Internet Sales Amount]} on 0 , [Customer].[Customer Geography].[Country].memberson 1 from [Adventure Works]
cellpropertiesvalue Note:ThisfunctionalityhasbeenfixedwiththelatestservicepackofSQL Server2008R2AnalysisServices. Latebindinginfunctions: Latebindingfunctionsarefunctionsthatdependonquerycontextand cannotbestaticallyevaluated.Forexample,thefollowingcodeisstatically bound. LinkMember,StrToSet, StrToMember, withmember measures.x as StrToValue
(strtomember("[Customer].[Customer Geography].[Country].&[Australia]"),[Measures].[Internet Sales Amount]) select measures.x on 0, [Customer].[Customer Geography].[Country].memberson 1 from [Adventure Works] cell properties value
Aqueryislateboundifanargumentcanbeevaluatedonlyincontext.
withmember measures.x as (strtomember([Customer].[Customer Geography].currentmember.uniquename),[Measures].[Internet Sales Amount]) select measures.x on 0, [Customer].[Customer Geography].[Country].memberson 1 from [Adventure Works] cell properties value
Userdefinedstored procedures
56
Thereasonthiscanonlybeusedinrarecasesisthatthequeryisnotequivalentthesecondquery eliminatescompletelyemptyrows.Moreimportantly,neitherExcelnorSQLServerReportingServices supportsthefourthargumentintheformat_string. References: Formoreinformationaboutusingtheformat_stringcalculationproperty,seeFORMAT_STRING Contents(MDX)(http://msdn.microsoft.com/enus/library/ms146084.aspx)inSQLServerBooks Online. FormoreinformationabouthowExcelusestheformat_stringproperty,seeCreateordeletea customnumberformat(http://office.microsoft.com/enus/excelhelp/createordeletea customnumberformatHP010342372.aspx).
57
DenseFirst
withcellCALCULATIONxfor'({[Measures].[InternetSalesAmount]},leaves([Date]))' as ([Measures].[AverageRate],[DestinationCurrency].[DestinationCurrency].&[EURO])* [Measures].[InternetSalesAmount] select nonempty[Date].[Calendar].memberson0, nonempty[Product].[ProductCategories].memberson1 from[AdventureWorks] where([Measures].[InternetSalesAmount],[Customer].[CustomerGeography].[State Province].&[BC]&[CA])
58
Wheretheconditionevaluatestotrue,thevaluefromthethenbranchisused;otherwisetheelse branchexpressionisused.Notethetermusedoneorbothbranchesmaybeevaluatedevenifthe valueisnotused.Itmaybecheaperfortheenginetoevaluatetheexpressionovertheentirespaceand useitwhenneededtermedaneagerplanthanitwouldbetochopupthespaceintoapotentially enormousnumberoffragmentsandevaluateonlywhereneededastrictplan. Note:OneofthemostcommonerrorsinMDXscriptingisusingIIfwhentheconditiondepends oncellcoordinatesinsteadofvalues.Iftheconditiondependsoncellcoordinates,usescopes andassignmentsasdescribedinsection2.Whenthisisdone,theconditionisnotevaluated overthespaceandtheenginedoesnotevaluateoneorbothbranchesovertheentirespace. Admittedly,insomecases,usingassignmentsforcessomeunwieldyscopingandrepetitionof assignments,butitisalwaysworthwhilecomparingthetwoapproaches. IIfconsiderations: 1) Thefirstconsiderationiswhetherthequeryplanisexpensiveorinexpensive. MostIIfconditionqueryplansareinexpensive,butcomplexnestedconditionswithmoreIIf functionscangotocellbycell. 2) Thenextconsiderationtheenginemakesiswhatvaluetheconditiontakesmost.Thisisdriven bytheconditionsdefaultvalue.Iftheconditionsdefaultvalueistrue,thethenbranchisthe defaultbranchthebranchthatisevaluatedovermostofthesubspace. Knowingafewsimplerulesonhowtheconditionisevaluatedhelpstodeterminethedefaultbranch: Insparseexpressions,mostcellsareempty.ThedefaultvalueoftheIsEmptyfunctionona sparseexpressionistrue. Comparisontozeroofasparseexpressionistrue. ThedefaultvalueoftheISoperatorisfalse. Iftheconditioncannotbeevaluatedinsubspacemode,thereisnodefaultbranch.
Forexample,oneofthemostcommonusesoftheIIffunctionistocheckwhetherthedenominatoris nonzero: 59
ThereisnocalculationonInternetSalesAmount;thereforeitisaregularmeasureexpressionanditis sparse.Thereforethedefaultvalueoftheconditionistrue.Thusthedefaultbranchisthethenbranch withthenullexpression. ThefollowingtableshowshoweachbranchofanIIffunctionisevaluated. Branchqueryplan Expensive Inexpensive Inexpensive Inexpensive Branchisdefault branch Notapplicable True False False Branchexpression sparsity Notapplicable Notapplicable Dense Sparse Evaluation Strict Eager Strict Eager
InSQLServer2008AnalysisServices,youcanoverrulethedefaultbehaviorwithqueryhints.
iif( [<condition> , <then branch> [hint [Eager | Strict]] , <else branch> [hint [Eager | Strict]] )
60
61
Nowthesameattributesaremarkedwitha*indicator,meaningthattheexpressionisevaluatedover theentirespaceinsteadofapartitionedspace.
Therepeatedpartialexpressionscanbeextractedandreplacedwithahiddencalculatedmemberas follows. 62
Thefollowingismoreefficientbecauseitcreatesacalculatedmeasuretohandlethecoloreffect.
createmembercurrentcube.measures.MyCellPropertyas<complexexpression>, visible=0; createmembercurrentcube.measures.[Value]as<exp>, backgroundColor=<MyCellProperty>;
63
Withthemodification,thisquerytakeslessthantwosecondstocomplete.Thefollowingisapartial viewaggregatingtheSQLServerProfilertracesofthetwoqueriesintheexamplebyEventClassand EventSubClass. EventClass>EventSubClass AvgSalesWithOverwrite AvgSales Events Duration Events Duration QueryCubeEnd 1 515 1 161526 SerialResultsEnd 1 499 1 161526 QueryDimension 586 GetDataFromCache>GetData 586 fromFlatCache QuerySubcube>NonCacheData 5 64 5 218 TheQuerySubcube>NonCacheDatadurationsarerelativelysmall,denotingthatmostofthequery calculationisdonebytheAnalysisServicesformulaengine.ThisisapparentwiththeAvgSales calculationbecausemostofthequerydurationscorrespondtotheSerialResultsevent,whichreports thestatusofserializingaxesandcells.Theuseof[All Customers]ensuresthattheexpressionis evaluatedonlyonceforeachCustomer,improvingperformance.
64
select[Measures].[InternetAverageSalesAmount]on0from[AdventureWorks]cell propertiesvalue
Iftheresultisnoticeablefasterwithouttheformatting,applytheformattingdirectlyinthescriptas follows.
scope([Measures].[InternetAverageSalesAmount]); FORMAT_STRING(this)="currency"; endscope;
Executethequery(withformattingapplied)todeterminetheextentofanyperformancebenefit.
2.3.3.10
NON_EMPTY_BEHAVIOR
Insomesituations,itisexpensivetocomputetheresultofanexpression,evenifyouknowitwillbenull beforehandbasedonthevalueofsomeindicatortuple.InearlierversionsofSQLServerAnalysis Services,theNON_EMPTY_BEHAVIORpropertyissometimeshelpfulforthesekindsofcalculations. Whenthispropertyevaluatestonull,theexpressionisguaranteedtobenulland(mostofthetime)vice versa. Thispropertyoftentimesresultedinsubstantialperformanceimprovementsinpastreleases.However, startingwithSQLServer2008,thepropertyisoftentimesignored(becausetheengineautomatically dealswithnonemptycellsinmanycases)andcansometimesresultindegradedperformance.Eliminate itfromtheMDXscriptandadditbackafterperformancetestingdemonstratesimprovement. Forassignments,thepropertyisusedasfollows. this = <e1>; Non_Empty_Behavior(this) = <e2>; ForcalculatedmembersintheMDXscript,thepropertyisusedthisway.
createmembercurrentcube.measures.xas<e1>,non_empty_behavior=<e2>
Ifthepropertyisdefinedandisappliedbytheengine,itissemanticallyequivalent(notperformance equivalent,however)tothefollowingexpression. this = <e1> * iif(isempty(<e2>), null, 1) TheNON_EMPTY_BEHAVIORpropertyisusedif<e2>issparseand<e1>isdenseor<e1>isevaluatedin thenavecellbycellmode.Iftheseconditionsarenotmetandboth<e1>and<e2>aresparse(thatis,if <e2>ismuchsparserthan<e1>),youmaybeabletoachieveimprovedperformancebyforcingthe behaviorasfollows. this = iif(isempty(<e2>), null, <e1>); TheNON_EMPTY_BEHAVIORpropertycanbeexpressedasasimpletupleexpressionincludingsimple membernavigationfunctionssuchas.prevmemberor.parentoranenumeratedset.Anenumeratedset isequivalenttoNON_EMPTY_BEHAVIORoftheresultantsum. References BelowarelinkstosomehandyMDXoptimizationarticles,books,andblogposts: Querycalculatedmembersinvalidateformulaenginecache (http://cwebbbi.wordpress.com/2009/01/30/formulacachingandqueryscope/)byChrisWebb Subselectpreventingcaching(http://cwebbbi.wordpress.com/2008/10/28/reportingservices generatedmdxsubselectsandformulacaching/)byChrisWebb Measuredatatypes (http://bidshelper.codeplex.com/wikipage?title=Measure%20Group%20Health%20Check&Proje ctName=bidshelper) Currencydatatype(http://sqlcat.com/sqlcat/b/technicalnotes/archive/2008/09/25/themany benefitsofmoneydatatype.aspx)
2.3.4 Aggregations
AnaggregationisadatastructurethatstoresprecalculateddatathatAnalysisServicesusestoenhance queryperformance.Youcandefinetheaggregationdesignforeachpartitionindependently.Each partitioncanbethoughtofasbeinganaggregationatthelowestgranularityofthemeasuregroup. Aggregationsthataredefinedforapartitionareprocessedoutoftheleaflevelpartitiondataby aggregatingittoahighergranularity.
66
Whenaqueryrequestsdataathigherlevels,theaggregationstructurecandeliverthedatamorequickly becausethedataisalreadyaggregatedinfewerrows.Asyoudesignaggregations,youmustconsider thequeryingbenefitsthataggregationsprovidecomparedwiththetimeittakestocreateandrefresh theaggregations.Infact,addingunnecessaryaggregationscanworsenqueryperformancebecausethe rarehitsmovetheaggregationintothefilecacheatthecostofmovingsomethingelseout. Whileaggregationsarephysicallydesignedpermeasuregrouppartition,theoptimizationtechniquesfor maximizingaggregationdesignapplywhetheryouhaveoneormanypartitions.Inthissection,unless otherwisestated,aggregationsarediscussedinthefundamentalcontextofacubewithasingle measuregroupandsinglepartition.Formoreinformationabouthowyoucanimprovequery performanceusingmultiplepartitions,seePartitionStrategy.
Figure 2828: Scenario 1: SQL Server Profiler trace for cube with an aggregation hit
ThisfiguredisplaysaSQLServerProfilertraceofthequerysresolutionagainstacubewithaggregations. IntheSQLServerProfilertrace,theoperationsthatthestorageengineperformstoproducetheresult setarerevealed. ThestorageenginegetsdatafromAggregationC0000,0001,0000asindicatedbytheGetDataFrom Aggregationevent.Inadditiontotheaggregationname,AggregationC,Figure29displaysavector,000, 0001,0000,thatdescribesthecontentoftheaggregation.Moreinformationonwhatthisvector actuallymeansisdescribedinthenextsection,HowtoInterpretAggregations.Theaggregationdatais loadedintothestorageenginemeasuregroupcachefromwherethequeryprocessorretrievesitand returnstheresultsettotheclient. Whennoaggregationscansatisfythequeryrequest,noticethemissingGetDataFromAggregation eventfromthesamecubewithnoaggregationsasnotedinthefollowingfigure.
67
Figure 2929: Scenario 2: SQL Server Profiler trace for cube with no aggregation hit
Toidentifyeachaggregation,AnalysisServicescombinesthedimensionvectorsintoonelongvector path,alsocalledasubcube,witheachdimensionvectorseparatedbycommas. Theorderofthedimensionsinthevectorisdeterminedbytheorderofthedimensionsinthemeasure group.Tofindtheorderofdimensionsinthemeasuregroup,useoneofthefollowingtwotechniques: 1. WiththecubeopenedinSQLServerBusinessIntelligenceDevelopmentStudio,reviewtheorder ofdimensionsinameasuregroupontheCubeStructuretab.Theorderofdimensionsinthe cubeisdisplayedintheDimensionspane. 2. Asanalternative,reviewtheorderofdimensionslistedinthecubesXMLAdefinition. Theorderofattributesinthevectorforeachdimensionisdeterminedbytheorderofattributesinthe dimension.YoucanidentifytheorderofattributesineachdimensionbyreviewingthedimensionXML file. Forexample,thesubcubedefinition(0000,0001,0001)describesanaggregationforthefollowing:
68
Product All, All, All, All Customer All, All, All, State/Province Order Date All, All, All, Year
2.3.4.4 BuildingAggregations
IndividualaggregationsareorganizedintocollectionsofaggregationscalledAggregationDesigns.You canapplyanAggregationDesigntomanypartitions.Aswell,onemeasuregroupcanhavemultiple AggregationDesignssothatyoucanchoosedifferentsetsofaggregationsfordifferentpartitions.To helpAnalysisServicessuccessfullyapplytheAggregationDesignalgorithm,youcanperformthe followingoptimizationtechniquestoinfluenceandenhancetheAggregationDesign.Inthissectionwe willdiscussthefollowing: Theimportanceofattributehierarchies Aggregationdesignandpartitions Specifyingstatisticsaboutcubedata Suggestingaggregationcandidates Usagebasedoptimization Largecubeaggregations Distinctcountpartitionaggregationconsiderations
2.3.4.4.1 Importance of Attribute Hierarchies Aggregationsworkbetterwhenthecubeisbasedonamultidimensionaldatamodelthatincludes naturalhierarchies.Whileitiscommoninrelationaldatabasestohaveattributesindependentofeach other,multidimensionalstarschemashaveattributesrelatedtoeachothertocreatenatural hierarchies.Thisisimportantbecauseitallowsaggregationsbuiltatalowerlevelofanaturalhierarchy tobeusedwhenqueryingatahigherlevel. Notethatattributesthatareexposedonlyinattributehierarchiesarenotautomaticallyconsideredfor aggregationbytheAggregationDesignWizard.Therefore,queriesinvolvingtheseattributesare satisfiedbysummarizingdatafromtheprimarykey.Withoutthebenefitofaggregations,query 69
performanceagainsttheseattributeshierarchiescanbeslow.Toenhanceperformance,itispossibleto flaganattributeasanaggregationcandidatebyusingtheAggregationUsageproperty.Formore informationaboutthistechnique,seeSuggestingAggregationCandidates.However,beforeyoumodify theAggregationUsageproperty,youshouldconsiderwhetheryoucantakeadvantageofuser hierarchies. 2.3.4.4.2 Aggregation Design and Partitions Whenyoudefineyourpartitions,theydonotnecessarilyhavetocontainuniformdatasetsor aggregationdesigns.Forexample,foragivenmeasuregroup,youmayhave3yearlypartitions, 11monthlypartitions,3weeklypartitions,and17dailypartitions.Heterogeneouspartitionswith differentlevelsofdetailallowsyoutomoreeasilymanagetheloadingofnewdatawithoutdisturbing existing,larger,andstalepartitions(moreonthisintheprocessingsection)andyoucandesign aggregationsforgroupsofpartitionsthatsharethesameaccesspattern.Foreachpartition,youcanuse adifferentaggregationdesign.Bytakingadvantageofthisflexibility,youcanidentifythosedatasets thatrequirehigheraggregationdesign. Considerthefollowingexample.Inacubewithmultiplemonthlypartitions,newdatamayflowintothe singlepartitioncorrespondingtothelatestmonth.Generallythatisalsothepartitionmostfrequently queried.Acommonaggregationstrategyinthiscaseistoperformusagebasedoptimizationtothemost recentpartition,leavingolder,lessfrequentlyqueriedpartitionsastheyare. Ifyouautomatepartitioncreation,itiseasytosimplysettheAggregationDesignIDforthenewpartition atcreationtimeandspecifythesliceforthepartition;nowitisreadytobeprocessed.Atalaterstage, youmaychoosetoupdatetheaggregationdesignforapartitionwhenitsusagepatternchanges again,youcanjustupdatetheAggregationDesignID,butyouwillalsoneedtoinvokeProcessIndexesso thatthenewaggregationdesigntakeseffectfortheprocessedpartition. 2.3.4.4.3 Specifying Statistics About Cube Data Tomakeintelligentassessmentsofaggregationcosts,thedesignalgorithmanalyzesstatisticsaboutthe cubeforeachaggregationcandidate.Examplesofthismetadataincludemembercountsandfacttable counts.Ensuringthatyourmetadataisuptodatecanimprovetheeffectivenessofyouraggregation design. Wheneveryouusemultiplepartitionsforagivenmeasuregroup,ensurethatyouupdatethedata statisticsforeachpartition.Morespecifically,itisimportanttoensurethatthepartitiondataand membercounts(suchasEstimatedRowsandEstimatedCountproperties)accuratelyreflectthespecific datainthepartitionandnotthedataacrosstheentiremeasuregroup. 2.3.4.4.4 Suggesting Aggregation Candidates WhenAnalysisServicesdesignsaggregations,theaggregationdesignalgorithmdoesnotautomatically considereveryattributeforaggregation.Consequently,inyourcubedesign,verifytheattributesthat areconsideredforaggregationanddeterminewhetheryouneedtosuggestadditionalaggregation candidates.Tostreamlinethisprocess,AnalysisServicesusestheAggregationUsagepropertyto determinewhichattributesitshouldconsider.Foreverymeasuregroup,verifytheattributesthatare 70
automaticallyconsideredforaggregationandthendeterminewhetheryouneedtosuggestadditional aggregationcandidates. AggregationUsageRules AnaggregationcandidateisanattributethatAnalysisServicesconsidersforpotentialaggregation.To determinewhetherornotaspecificattributeisanaggregationcandidate,thestorageenginerelieson thevalueoftheAggregationUsageproperty.TheAggregationUsagepropertyisassignedapercube attribute,soitgloballyappliesacrossallmeasuregroupsandpartitionsinthecube.Foreachattributein acube,theAggregationUsagepropertycanhaveoneoffourpotentialvalues:Full,None,Unrestricted, andDefault. FullEveryaggregationforthecubemustincludethisattributeorarelatedattributethatis lowerintheattributechain.Forexample,youhaveaproductdimensionwiththefollowing chainofrelatedattributes:Product,ProductSubcategory,andProductCategory.Ifyouspecify theAggregationUsageforProductCategorytobeFull,AnalysisServicesmaycreatean aggregationthatincludesProductSubcategoryasopposedtoProductCategory,giventhat ProductSubcategoryisrelatedtoCategoryandcanbeusedtoderiveCategorytotals. NoneNoaggregationforthecubecanincludethisattribute. UnrestrictedNorestrictionsareplacedontheaggregationdesigner;however,theattribute muststillbeevaluatedtodeterminewhetheritisavaluableaggregationcandidate. DefaultThedesignerappliesadefaultrulebasedonthetypeofattributeanddimension.This isthedefaultvalueoftheAggregationUsageproperty.
Thedefaultruleishighlyconservativeaboutwhichattributesareconsideredforaggregation.The defaultruleisbrokendownintofourconstraints. DefaultConstraint1UnrestrictedForadimensionsmeasuregroupgranularityattribute, defaultmeansUnrestricted.Thegranularityattributeisthesameasthedimensionskey attributeaslongasthemeasuregroupjoinstoadimensionusingtheprimarykeyattribute. DefaultConstraint2NoneforSpecialDimensionTypesForallattributes(exceptAll)in manytomany,nonmaterializedreferencedimensions,anddataminingdimensions,default meansNone.Thismeansyoucansometimesbenefitfromcreatingleaflevelprojectionsfor manytomanydimensions.Note,thesedefaultsdonotapplyforparentchilddimensions;for moreinformation,seetheSpecialConsiderations>ParentChilddimensionssection. DefaultConstraint3UnrestrictedforNaturalHierarchiesAnaturalhierarchyisauser hierarchywhereallattributesparticipatinginthehierarchycontainattributerelationshipstothe attributesourcingthenextlevel.Forsuchattributes,defaultmeansUnrestricted,exceptfor nonaggregatableattributes,whicharesettoFull(eveniftheyarenotinauserhierarchy). DefaultConstraint4NoneForEverythingElse.Forallotherdimensionattributes,default meansNone.
71
AggregationUsageGuidelines InlightofthebehavioroftheAggregationUsageproperty,usethefollowingguidelines: AttributesexposedsolelyasattributehierarchiesIfagivenattributeisonlyexposedasan attributehierarchysuchasColor,youmaywanttochangeitsAggregationUsagepropertyas follows. o First,changethevalueoftheAggregationUsagepropertyfromDefaulttoUnrestricted iftheattributeisacommonlyusedattributeoriftherearespecialconsiderationsfor improvingtheperformanceinaparticularpivotordrilldown.Forexample,ifyouhave highlysummarizedscorecardstylereports,youwanttoensurethattheusers experiencegoodinitialqueryresponsetimebeforedrillingaroundintomoredetail. o WhilesettingtheAggregationUsagepropertyofaparticularattributehierarchyto Unrestrictedisappropriateissomescenarios,donotsetallattributehierarchiesto Unrestricted.Increasingthenumberofattributestobeconsideredincreasesthe problemspacetheaggregationalgorithmmustconsider.Thewizardcantakeatleastan hourtocompletethedesignandconsiderablymuchmoretimetoprocess.Setthe propertytoUnrestrictedonlyforthecommonlyqueriedattributehierarchies.The generalruleisfivetotenUnrestrictedattributesperdimension. o Next,changethevalueoftheAggregationUsagepropertyfromDefaulttoFullinthe unusualcasethatitisusedinvirtuallyeveryqueryyouwanttooptimize.Thisisarare case,andthischangeshouldbemadeonlyforattributesthathavearelativelysmall numberofmembers. InfrequentlyusedattributesForattributesparticipatinginnaturalhierarchies,youmaywant tochangetheAggregationUsagepropertyfromDefaulttoNoneifuserswouldonly infrequentlyuseit.Usingthisapproachcanhelpyoureducetheaggregationspaceandgetto thefivetotenUnrestrictedattributesperdimension.Forexample,youmayhavecertain attributesthatareonlyusedbyafewadvanceduserswhoarewillingtoacceptslightlyslower performance.Inthisscenario,youareessentiallyforcingtheaggregationdesignalgorithmto spendtimebuildingonlytheaggregationsthatprovidethemostbenefittothemajorityofusers.
2.3.4.4.5 Usage-Based Optimization TheUsageBasedOptimizationWizardreviewsthequeriesinthequerylog(whichyoumustsetup beforehand)anddesignsaggregationsthatcoveruptothetop100slowestqueries.UsetheUsage BasedOptimizationWizardwitha100%performancegainthiswilldesignaggregationstoavoidhitting thepartitiondirectly. Aftertheaggregationsaredesigned,youcanaddthemtotheexistingdesignorcompletelyreplacethe design.Becarefuladdingthemtotheexistingdesignthetwodesignsmaycontainaggregationsthat servealmostidenticalpurposesthatwhencombinedareredundantwithoneanother.Aswell, aggregationdesignshaveacostlymetadataimpactdontoverdesignbuttrytokeepthenumberof aggregationdesignspermeasuregrouptoaminimum.Inspectthenewaggregationscomparedtothe
72
oldandensuretherearenonearduplicates.Theaggregationdesigncanbecopiedtootherpartitionsin SQLServerManagementStudioorBusinessIntelligenceDesignStudio. References: ReintroducingUsageBasedOptimizationinSQLServer2008AnalysisServices (http://sqlcat.com/sqlcat/b/technicalnotes/archive/2008/11/18/reintroducingusagebased optimizationinsqlserver2008analysisservices.aspx) AnalysisServices2005AggregationDesignStrategy (http://sqlcat.com/sqlcat/b/technicalnotes/archive/2007/09/11/analysisservices2005 aggregationdesignstrategy.aspx) MicrosoftSQLServerCommunitySamples:AnalysisServices (http://sqlsrvanalysissrvcs.codeplex.com/):ThisCodePlexprojectcontainsmanyusefulAnalysis ServicesCodePlexsamples,includingtheAggregationManager
2.3.4.4.6 Large Cube Aggregation Considerations Itisimportanttonotethatsmallcubesmaynotneedaggregations,becauseaggregationsarenoteven builtforpartitionswithfewerrecordsthantheIndexBuildThreshold(whichhasadefaultvalueof4096). EvenifthecubepartitionsexceedtheIndexBuildThreshold,aggregationsthatarecorrectlydesignedfor smallercubesmaynotbethecorrectonesforlargecubes. However,ascubesbecomelarger,itbecomesmoreimportanttodesignaggregationsandtodoso correctly.Asageneralruleofthumb,MOLAPperformanceisapproximatelybetween10and40million rowspersecondpercore,plustheI/Oforaggregatingdata. Itisimportanttonotethatlargercubeshavemoreconstraintssuchassmallprocessingwindowsand/or notenoughdiskspace.Thereforeitmaybedifficulttocreateallofyourdesiredaggregations.Theresult isatradeoffindesigningaggregationstobeconsideredmorecarefully.
References:
74
2.3.6 Scale-Out
IfyouhavemanyconcurrentusersqueryingyourAnalysisServicescubes,apotentialqueryperformance solutionistoscaleoutyourAnalysisServicesqueryservers.Therearedifferentformsofscaleout, whicharediscussedinPart2,butthebasicprincipleisthatyouhavemultiplequeryserversaimedat thesamedatabase(orthedatabaseisreplicated)sotherearemultipleserverstoaddressuserqueries. Thiscanbebeneficialinthecaseslikethefollowing: Incaseswhereyourserverisundermemorypressureduetoconcurrency,scalingoutallowsyou todistributethequeryloadtomultipleservers,thusalleviatingmemorybottlenecksonasingle server.Memorypressurecanbecausedbymanyissues,including(butnotlimitedto): o Usersexecutingmanydifferentuniquequeriesthusfillingupandthrashingavailable cache. o Complexorlargequeriesrequiringlargesubcubesthusrequiringalargememoryspace. o Toomanyconcurrentusersaccessingthesameserver. YouhavemanylongrunningqueriesagainstyourAnalysisServicescube,whichwill: o Blockotherqueries. o Blockprocessingcommits. Inthiscase,scalingoutthelongrunningqueriestoseparateserverscanhelpalleviate contentionproblems. References: SQLServer2008R2AnalysisServicesOperationsGuide (http://sqlcat.com/sqlcat/b/whitepapers/archive/2011/06/01/sqlserver2008r2analysis servicesoperationsguide.aspx) ScaleOutQueryingforAnalysisServiceswithReadOnlyDatabases (http://sqlcat.com/sqlcat/b/whitepapers/archive/2010/06/08/scaleoutqueryingforanalysis serviceswithreadonlydatabases.aspx) ScaleOutQueryingwithAnalysisServices (http://sqlcat.com/sqlcat/b/whitepapers/archive/2007/12/16/scaleoutqueryingwithanalysis services.aspx) ScaleOutQueryingwithAnalysisServicesUsingSANSnapshots (http://sqlcat.com/sqlcat/b/whitepapers/archive/2007/11/19/scaleoutqueryingwithanalysis servicesusingsansnapshots.aspx)
75
MSOLAP:Processing o Rowsread/sec MSOLAP:ProcAggregations o TempFileBytesWrites/sec o Rowscreated/Sec o CurrentPartitions MSOLAP:Threads o Processingpoolidlethreads o Processingpooljobqueuelength o Processingpoolbusythreads MSSQL:MemoryManager o TotalServerMemory o TargetServerMemory Process o VirtualBytesmsmdsrv.exe o WorkingSetmsmdsrv.exe o PrivateBytesmsmdsrv.exe o %ProcessorTimemsmdsrv.exeandsqlservr.exe MSOLAP:Memory o QuoteBlocked LogicalDisk: o Avg.Disksec/TransferAllInstances Processor: o %ProcessorTimeTotal System: o ContextSwitches/sec
Performance/ShowplanXMLStatisticsProfile TSQL/SQL:BatchCompleted
78
Figure 3030: Full cube processing overview
Toprovideamentalmodeloftheworkload,wewillfirstintroducethedimensionprocessing architecture.
79
BuildAttr ributeStoresForeachat ttributeinad dimension,ajobisinstantiatedtoextractandpersistthe attributemembersintoanattribute estore.Thea attributestore econsistsoft thekeystore e,namestore, ,and hipstore.The edatastructuresbuildduringdimensionprocessingaresavedtodiskwiththe e relationsh followingextensions: Hierarchystores:*.ostore,*.sstoreand*.lstore Ke eystore:*.ks store,*.khsto oreand*.ksst tore NameStore:*.asstore,*.ah hstoreand*. .hstore Relationshipst tore:*.dataa and*.data.hd dr DecodingStore es:*.dstore es:*.mapand d*.map.hdr Bitmapindexe
therelationsh hipstorescon ntaininformationaboutde ependentattr ributes,anor rderingofthe e Becauset processingjobsisrequ uired.Toprov videthecorre ectworkflow,thestoragee engineanalyz zesthe dependen nciesbetween nattributes,a andthenitcr reatesanexe ecutiontreew withthecorre ectordering.T The execution ntreeisthenusedtodeterminethebestparallelexe ecutionofthe edimensionp processing. Figure32displaysane exampleexecutiontreefor raTimedime ension.Theso olidarrowsre epresentthe nsion.Thedas shedarrowsr representthe eimplicitrelationshipofea ach attributerelationshipsinthedimen attributetotheAllattr ribute. Note:The edimensionh hasbeenconf figuredusingcascadingatt tributerelatio onships,whic chisabest practicefo oralldimensiondesigns.
80
Figure 3 3232: Exec cution tree example
Inthisexa ample,theAllattributeproceedsfirst,giventhatith hasnodepen ndenciestoan notherattribu ute, followedbytheFiscalYearandCale endarYearat ttributes,whichcanbeprocessedinpa arallel.Theot ther sproceedacc cordingtothe edependenciesintheexec cutiontree,w withthekeya attributealwa ays attributes beingprocessedlast,b becauseitalw wayshasatleastoneattrib buterelations ship,exceptw whenitistheonly sion. attributeinthedimens Thetimet takentoproc cessanattributeisgenerallydependen nton1)thenu umberofmembersand2) )the numbero ofattributere elationships.W Whileyoucan nnotcontrolt thenumbero ofmembersf foragiven attribute,youcanimproveprocessi ingperformancebyusingcascadingatt tributerelatio onships.Thisis ycriticalforth hekeyattribu ute,becausei ithasthemo ostmembersa andallotherjobs(hierarchy, especially decoding, ,bitmapindexes)arewaitingforittocomplete.Attr ributerelatio onshipslowerthememory y requireme entduringpr rocessing.Wh henanattribu uteisprocess sed,alldepen ndentattribut tesmustbekept inmemor ry.Ifyouhave enoattribute erelationship ps,allattributesmustkept tinmemoryw whilethekey attributeisprocessed.Thismaycau useoutofme emorycondit tions. BuildDec codingStoresDecodingstoresareuse edextensively ybythestora ageengine.Duringqueryin ng, theyareu usedtoretrievedatafromthedimensio on.Duringprocessing,the eyareusedto obuildthe dimension nsbitmapind dexes. BuildHier rarchyStores sAhierarchy ystoreisape ersistentrepresentationof fthetreestru ucture.Forea ach naturalhierarchyinthedimension,ajobisinstantiatedtocre eatethehiera archystores. BuildBitm mapIndexes Toefficientl lylocateattributedataint therelationsh hipstoreatq queryingtime,the storageen nginecreates sbitmapinde exesatproces ssingtime.Fo orattributesw withaverylargenumbero of members,thebitmapindexescant takesometim metoprocess s.Inmostscenarios,thebi itmapindexes s providesi ignificantque eryingbenefit ts;however,w whenyouhav vehighcardinalityattributes,thequerying
81
benefitthatthebitmapindexprovidesmaynotoutweightheprocessingcostofcreatingthebitmap index.
TheProcessFullandProcessDatacommandsdiscardallstoragecontentsofthedimensionandrebuild them.Behindthescenes,ProcessFullexecutesalldimensionprocessingjobsandperformsanimplicit ProcessClearonalldependentpartitions.ThismeansthatwheneveryouperformaProcessFull operationofadimension,youneedtoperformaProcessFulloperationondependentpartitionstobring thecubebackonline.ProcessFullalsobuildsindexesonthedimensiondataitself(notethatindexeson thepartitionsarebuiltseparately).IfyoudoProcessDataonadimension,youshoulddoProcessIndexes subsequentlysothatdimensionqueriesareabletousetheseindexes. UnlikeProcessFull,ProcessUpdatedoesnotdiscardthedimensionstoragecontents.Instead,itapplies updatesintelligentlyinordertopreservedependentpartitions.Morespecifically,ProcessUpdatesends SQLqueriestoreadtheentiredimensiontableandthenapplieschangestothedimensionstores. ProcessAddoptimizesProcessUpdateinscenarioswhereyouonlyneedtoinsertnewmembers. ProcessAdddoesnotdeleteorupdateexistingmembers.TheperformancebenefitofProcessAddisthat youcanuseadifferentsourcetableordatasourceviewnamedquerythatrestricttherowsofthe sourcedimensiontabletoonlyreturnthenewrows.Thiseliminatestheneedtoreadallofthesource data.Inaddition,ProcessAddalsoretainsallindexesandaggregations(flexibleandrigid). ProcessUpdateandProcessAddhavesomespecialbehaviorsthatyoushouldbeawareof.These behaviorsarediscussedinthefollowingsections. 2.4.2.2.1 ProcessUpdate AProcessUpdatecanhandleinserts,updates,anddeletions,dependingonthetypeofattribute relationships(rigidversusflexible)inthedimension.NotethatProcessUpdatedropsinvalid aggregationsandindexes,requiringyoutotakeactiontorebuildtheaggregationsinordertomaintain queryperformance.However,flexibleaggregationsaredroppedonlyifachangeisdetected. WhenProcessUpdateruns,itmustwalkthroughthepartitionsthatdependonthedimension.Foreach partition,allindexesandaggregationmustbecheckedtoseewhethertheyrequireupdating.Onacube 82
withmanypartitions,indexes,andaggregates,thiscantakeaverylongtime.Becausethisdependency walkisexpensive,ProcessUpdateisoftenthemostexpensiveofallprocessingoperationsonawell tunedsystem,dwarfingevenlargepartitionprocessingcommands. 2.4.2.2.2 ProcessAdd NotethatProcessAddisonlyavailableasanXMLAcommandandnotfromSQLServerManagement Studio.ProcessAddisthepreferredwayofmanagingType2changingdimensions.BecauseAnalysis Servicesknowsthatexistingindexesdonotneedtobecheckedforinvalidation,ProcessAddtypically runsmuchfasterthanProcessUpdate. InthedefaultconfigurationofAnalysisServices,ProcessAddtypicallytriggersaprocessingerrorwhen run,reportingduplicatekeyvalues.Thisiscausedbytheadditionofnonkeypropertiesthatalready existinthedimension.Forexample,considertheadditionofanewcustomertoadimension.Ifthe customerlivesinacountrythatisalreadypresentinthedimension,thiscountrycannotbeadded(itis alreadythere)andAnalysisServicesthrowsanerror.Thesolutioninthiscaseistosetthe <KeyDuplicate>toIgnoreErroronthedimensionprocessingcommand. NotethatyoucannotrunaProcessAddonanemptydimension.Thedimensionmustfirstbefully processed. References: FordetailedinformationaboutautomatingProcessAdd,seeGregGallowaysblogentry: http://www.artisconsulting.com/blogs/greggalloway/Lists/Posts/Post.aspx?ID=4 ForinformationabouthowtoavoidsettheKeyDuplicate,seethisforumthread: http://social.msdn.microsoft.com/Forums/enUS/sqlanalysisservices/thread/8e7f130456a1 467e9cc668428bd92aa6?prof=required
2.4.3.1.1 Remove Bitmap Indexes Duringprocessingoftheprimarykeyattribute,bitmapindexesarecreatedforeveryrelatedattribute. Buildingthebitmapindexesfortheprimarykeycantaketimeifithasoneormorerelatedattributes withhighcardinality.Atquerytime,thebitmapindexesfortheseattributesarenotusefulinspeeding upretrieval,becausethestorageenginestillmustsiftthroughalargenumberofdistinctvalues.This mayhaveanegativeimpactonqueryresponsetimes. Forexample,theprimarykeyofthecustomerdimensionuniquelyidentifieseachcustomerbyaccount number;however,usersalsowanttosliceanddicedatabythecustomerssocialsecuritynumber.Each customeraccountnumberhasaonetoonerelationshipwithacustomersocialsecuritynumber.You canconsiderremovingthecreationofbitmapsforthesocialsecuritynumber. Youcanalsoconsiderremovingbitmapindexesfromattributesthatarealwaysqueriedtogetherwith otherattributesthatalreadyhavebitmapindexesthatarehighlyselective.Iftheotherattributeshave sufficientselectivity,addinganotherbitmapindextofilterthesegmentswillnotyieldagreatbenefit. Forexample,youarecreatingasalesfactandusersalwaysquerybothdateandstoredimensions. Sometimesafilterisalsoappliedbythestoreclerkdimension,butbecauseyouhavealreadyfiltered downtostores,addingabitmaponthestoreclerkmayonlyyieldatrivialbenefit.Inthiscase,youcan considerdisablingbitmapindexesonstoreclerkattributes. Youcandisablethecreationofbitmapindexesforanattributebysettingthe AttributeHierarchyOptimizedStatepropertytoNotOptimized. 2.4.3.1.2 Optimize Attribute Processing Across Multiple Data Sources Whenadimensioncomesfrommultipledatasources,usingcascadingattributerelationshipsallowsthe systemtosegmentattributesduringprocessingaccordingtodatasource.Ifanattributeskey,name, andattributerelationshipscomefromthesamedatabase,thesystemcanoptimizetheSQLqueryfor thatattributebyqueryingonlyonedatabase.Withoutcascadingattributerelationships,theSQLServer OPENROWSETfunction,whichprovidesamethodforaccessingdatafrommultiplesources,isusedto mergethedatastreams.Inthissituation,theprocessingfortheattributeisextremelyslow,becauseit mustaccessmultipleOPENROWSETderivedtables. Ifyouhavetheoption,considerperformingETLtobringalldataneededforthedimensionintothesame SQLServerdatabase.ThisallowsyoutoutilizetheRelationalEnginetotunethequery.
84
Toquickly ytunetherelationalqueriesusedfordimensionpro ocessingyouc canusetheD DatabaseEngine TuningAd dvisoronapr rofilertraceo ofthedimensionprocessin ng.Forthesm malldimension ntables,chan nces arethaty youcangetaw waywithaddingeverysug ggestedindex x.Forthelarg gertables,targettheindex xes towardst thelongestru unningquerie es.Fordetaile edtuningadv viceonlarged dimensiontab bles,seePart t2. 2.4.3.2.1 Using ByT Table Proce essing gtheProcessi ingGrouppro opertyofthedimensionto obeByTabley youwillchan ngehowAnaly ysis Bysetting Servicesb behavesdurin ngdimensionprocessing.Insteadofsen ndingmultipleSELECTDIST TINCTqueries,the processingtaskinstead drequeststheentiretable ewithonequ uery.Ifyouha aveenoughm memorytoho oldall thenewd dimensiondat tawhileproc cessingishappening,thiso optioncanprovideafastw waytooptimize processing.However,y youshouldbe ecarefulaboutthissetting gifAnalysis sServicesrun nsoutofmem mory ocessing,this swillhaveala argeimpacto onbothquery yandprocess singperforma ance.Experim ment duringpro withthiss settingcarefu ullybeforepu uttingitintop production. NotealsothatByTable eprocessingw willcausedup plicatekey(K KeyDuplicate)errorsbecau useSELECT tedforeacha attribute,and dthesameme emberswillb beencountere edrepeatedly y DISTINCTisnotexecut duringpro ocessing.The erefore,youw willneedtosp pecifyacusto omerrorconf figurationand ddisablethe KeyDuplic cateerrors.
ProcessFulldiscardsthestoragecontentsofthepartitionandthenrebuildsthem.Behindthescenes, ProcessFullexecutesProcessDataandProcessIndexesjobs. ProcessDatadiscardsthestoragecontentsoftheobjectandrebuildsonlythefactdata. ProcessIndexesrequiresapartitiontohavebuiltitsdataalready.ProcessIndexespreservesthedata createdduringProcessDataandcreatesnewaggregationsandbitmapindexesbasedonit. ProcessAddinternallycreatesatemporarypartition,processesitwiththetargetfactdata,andthen mergesitwiththeexistingpartition.NotethatProcessAddisthenameoftheXMLAcommand,in BusinessIntelligenceDevelopmentStudioandSQLServerManagementStudiothisisexposedas ProcessIncremental. ProcessClearremovesalldatafromthepartition.NotetheProcessClearisthenameoftheXMLA command.InBusinessIntelligenceDevelopmentStudioandSQLServerManagementStudio,itis exposedasUnProcess. ProcessClearIndexesremovesallindexesandaggregatesfromthepartition.Thisbringsthepartitionsin thesamestateasifProcessClearfollowedbyProcessDatahadjustbeenrun.Notethat
86
ProcessClearIndexesisthenameoftheXMLAcommand.ThiscommandisnotavailableinBusiness IntelligenceDevelopmentStudioandSQLServerManagementStudio.
Ifyourmeasuregroupcontainsmultiplepartitions,asdescribedintheprevioussection,amoreeffective approachistocreateanewpartitionthatcontainsthenewdataandthenperformProcessFullonthat partition.Thistechniqueallowsyoutoaddnewdatawithoutimpactingtheexistingpartitions.When thenewpartitionhascompletedprocessing,itisavailableforquerying. 2.4.4.4.2 Updates Whenyouneedtoperformdataupdates,youcanperformaProcessFull.Ofcourseitisusefulifyoucan targettheupdatestoaspecificpartitionsoyouonlyhavetoprocessasinglepartition.Ratherthan directlyupdatingfactdata,abetterpracticeistouseajournalingmechanismtoimplementdata changes.Inthisscenario,youturnanupdateintoaninsertionthatcorrectsthatexistingdata.Withthis 87
approach,youcansimplycontinuetoaddnewdatatothepartitionbyusingaProcessAdd.Byusing journaling,youalsohaveanaudittrailofthechangesthathavebeenmadetothefacttable. 2.4.4.4.3 Deletes Fordeletions,multiplepartitionsprovideagreatmechanismforyoutorolloutexpireddata.Consider thefollowingexample.Youcurrentlyhave13monthsofdatainameasuregroup,1monthperpartition. Youwanttorollouttheoldestmonthfromthecube.Todothis,youcansimplydeletethepartition withoutaffectinganyoftheotherpartitions. Ifthereareanyolddimensionmembersthatonlyappearedintheexpiredmonth,youcanremovethese usingaProcessUpdateoperationonthedimension(butonlyifitcontainsflexiblerelationships).In ordertodeletemembersfromthekey/granularityattributeofadimension,youmustsetthe dimensionsUnknownMemberpropertytoHidden.Thisisbecausetheserverdoesnotknowifthereis afactrecordassignedtothedeletedmember.Withthispropertysetappropriately,thememberwillbe hiddenatquerytime.Anotheroptionistoremovethedatafromtheunderlyingtableandperforma ProcessFulloperation.However,thismaytakelongerthanProcessUpdate. Asyourdimensiongrowslarger,youmaywanttoperformaProcessFulloperationonthedimensionto completelyremovedeletedkeys.However,ifyoudothis,allrelatedpartitionsmustalsobe reprocessed.Thismayrequirealargebatchwindowandisnotviableforallscenarios.
Distinctcountcolumns
2.4.4.6.1 Getting Rid of Joins IfyouareusingadatabasevieworaUDMnamedqueryasthebasisofpartitions,youshouldseekto eliminatejoinsinthequerysendtothedatabase.Youcanachievethisbydenormalizingthejoined columnstothefacttable.Ifyouareusingastarschemadesign,youshouldalreadyhavedonethis. References: Forbackgroundonrelationalstarschemasandhowtodesignanddenormalizeforoptimal performance,referto:RalphKimball,TheDataWarehouseToolkit.
Clickonthetablescan(itmayalsobearangescanorindexseekinyourcase)andbringupthe propertiespane.
89
Figure 3535: Too many partitions accessed
Beingabletoprocessmultiplepartitionsinparallelisusefulinavarietyofscenarios;however,thereare afewguidelinesthatyoumustfollow.Keepinmindthatwheneveryouprocessameasuregroupthat hasnoprocessedpartitions,AnalysisServicesmustinitializethecubestructureforthatmeasuregroup. Todothis,ittakesanexclusivelockthatpreventsparallelprocessingofpartitions.Youshouldeliminate thislockbeforeyoustartthefullparallelprocessonthesystem.Toremovetheinitializationlock,ensure thatyouhaveatleastoneprocessedpartitionpermeasuregroupbeforeyoubegintheparallel operation.Ifyoudonothaveaprocessedpartition,youcanperformaProcessStructureonthecubeto builditsinitialstructureandthenproceedtoprocessmeasuregrouppartitionsinparallel.Youwillnot encounterthislimitationifyouprocesspartitionsinthesameclientsessionandusetheMaxParallel XMLAelementtocontrolthelevelofparallelism.
Setthisnumbertoatleastthenumberofpartitionsyouwanttoprocessinparallel.
2.4.4.10
91
ThekeyfigureyouoptimizeduringProcessIndexistheperformancecounterMSOLAP:Proc AggregationsRowcreated/Sec.Asthecounterincreases,theProcessIndextimedecreases.Youcan usethiscountertocheckifyourtuningeffortsimprovethespeed. Anadditionalimportantcountertolookatisthetemporaryfilescounterwhenanaggregationdoesnt fitinmemory,theaggregationdataisspilledtotemporarydiskfiles.Buildingdiskbasedaggregationsis muchmoreexpensive,andifyounoticethisyoumaybeabletofindawaytoeitherallowmorememory tobeavailablefortheindexbuildingphase,ordropsomeofthelargeraggregationstoavoidthisissue. 2.4.4.10.1 Add Partitions to Increase Parallelism AswasthecasewithProcessData,processingmorepartitionsinparallelcanspeedupProcessIndex. Thesametuningstrategyapplies:Keepincreasingpartitioncountuntilyounolongerseeanincreasein processingspeed.
2.4.4.11
Thebestpartitionstrategytoimplementintherelationalsourcevariesbydatabaseproductcapabilities, butsomegeneralguidanceapplies. Itisoftenagoodideatoreflectthecubepartitionstrategyintherelationdesign.Partitionsinthe relationalsourceserveascoarseindexes,andmatchingrelationalpartitionswiththecubeallowsyou togetthebestpossibletablescanspeedsbytouchingonlytherecordsyouneed.Anotherwayto achievethateffectistouseaSQLServerclusteredindex(ortheequivalentinyourpreferreddatabase engine)tosupportfastscanqueriesduringpartitionprocessing.Ifyouhaveusedamatrixpartition schemaasdescribedearlier,youmayevenwanttocombinethepartitionandclusterindexstrategy, usingpartitioningtosupportoneofthepartitioneddimensionandclusterindexestosupporttheother. Thefollowingfiguresillustratesomeexamplesofpartitionstrategiesyoushouldconsider.
92
Figure 3838: Clustering the relational table
Thekeytoimprovingdistinctcountqueryperformanceistohaveapartitioningstrategythat involvesatimeperiodandyourdistinctcountvalue.Startbypartitioningbytimeandxnumber ofdistinctvaluepartitionsofequalsizewithnonoverlappingranges,wherexisthenumberof cores.Refinexbytestingwithdifferentpartitioningschemes. Todistributeyourdistinctvalueacrossyourpartitionswithnonoverlappingranges,considering buildingahashofthedistinctvalue.Amodulofunctionissimpleandstraightforwardbutit requiresextraprocessing(forexample,convertcharacterkeytointegervalues)andstorage(for example,tomaintainanIDENTITYtable).AhashfunctionsuchastheSQLHashBytesfunction willavoidthelatterissuesbutmayintroducehashkeycollisions(thatis,whenthehashvalueis repeatedbasedondifferentsourcevalues). Thedistinctcountmeasuremustbedirectlycontainedinthequery.Ifyoupartitionyourcube bythehashofthedistinctvalue,itisimportantthatyourqueryisagainstthehashofthedistinct value(versusthedistinctvalueitself).Evenifthedistinctvalueandthehashofthedistinct valuehavethesamedistributionofdata,andevenifyoupartitiondatabythelatter,theheader filescontainonlytherangeofvaluesassociatedwiththehashofthedistinctvalue.This ultimatelymeansthattheAnalysisServicesstorageenginemustqueryallofthepartitionsto performthedistinctonthedistinctvalue. Thedistinctcountvaluesneedtobecontinuous.
94
95
basedoneachsetofcommondimensionmembercombinationssothatrepeatedcombinationsare eliminated.
Figure 4040: Compressing the FactInternetSalesReason intermediate fact table (from Analysis Services Many-to-Many Dimensions: Query Performance Optimization Techniques)
97
Afterthedatahasbeenreorganizedintotheuserhierarchy,youcanusetheHideMemberIfproperty ofeachleveltohidetheredundantormissingmembers.Tohelpconvertyourparentchildhierarchy intoaregularhierarchy,refertotheAnalysisServicesParentChildDimensionNaturalizertoolin CodePlex (http://pcdimnaturalize.codeplex.com/wikipage?title=Home&version=12&ProjectName=pcdimnaturaliz e). References: AnalysisServicesParentChildDimensionNaturalizer (http://pcdimnaturalize.codeplex.com/wikipage?title=Home&version=12&ProjectName=pcdimn aturalize) IncludingChildMembersMultiplePlacesinaParentChildHierarchy (http://sqlcat.com/sqlcat/b/technicalnotes/archive/2008/03/17/includingchildmembers multipleplacesinaparentchildhierarchy.aspx)
ItisimportanttonotethatduetothelockinglogicinvokedbyAnalysisServices,longrunningqueriesin AnalysisServicescanbothpreventprocessingfromcommittingandblockotherqueries. ToprovidenearrealtimeresultsandavoidtheAnalysisServicesquerylocking,startwithusingROLAP sothatthequeriesgodirectlytotherelationaldatabase.Yetevenrelationaldatabaseshavelocking and/orconcurrencyissuesthatneedtobedealtwith.Tominimizetheimpactofblockingquerieswithin yourrelationaldatabase,placetherealtimeportionofthedataintoitsownseparatetablebutkeep historicaldatawithinyourpartitionedtable.Afteryouhavedonethis,youcanapplyothertechniques.In thissectionwediscussthefollowing: MOLAPswitching ROLAP+MOLAP ROLAPpartitioning
99
100
2.5.4.4 ROLAP
Ingeneral,MOLAPisthepreferredstoragechoiceforAnalysisServices;becauseMOLAPtypically providesfasteraccesstothedata(especiallyifyourdisksubsystemisoptimizedforrandomI/O),itcan handleattributesmoreefficientlyanditiseasiertomanage.However,ROLAPagainstSQLServercanbe asolidchoiceforverylargecubeswithexcellentperformanceandthebenefitofreducingoreven removingtheprocessingtimeoflargecubes.Asnotedearlier,itisoftenarequirementifyouneedto havenearrealtimecubes.Ascanbeseeninthefollowingfigure,thequeryperformanceofaROLAP cubeafterusagebasedoptimizationisappliedcanbecomparabletoMOLAPifthesystemisexpertly tuned. 101
Figure 4343: Showcasing ROLAP vs. MOLAP performance before and after the application of usage-based optimization
2.5.4.4.1 ROLAP Design Recommendations TherecommendationsforhighperformancequeryingofROLAPcubesarelistedhere: SimplifythedatastructureofyourunderlyingSQLdatasourcetominimizepagereads(for example,removeunusedcolumns,trytouseINTcolumns,andsoon). Useastarschemawithoutsnowflaking,becausejoinscanbeexpensive. Avoidscenariossuchasmanytomanydimensions,parentchilddimensions,distinctcount,and ROLAPdimensions.
BothapproachesrelyonthecreationofindexedviewswithinSQLServerbutofferdifferentadvantages anddisadvantages.Oftenthemosteffectivestrategyisacombinationofthesetwoapproachesasnoted inthefollowingtable. Aggregation Type Cubebased Advantages Efficientqueryprocessing:Analysis Servicescanusecubebased aggregationsevenifthequeryand Disadvantages Processingoverhead:AnalysisServices dropsandrecreatesindexedviews associatedwithcubebasedaggregations
102
Transparent
aggregationgranularitiesdonotexactly match.Forexample,aqueryon[Month] canuseanaggregationon[Day],which requiresonlythesummarizationofup to31numbers. Aggregationdesignefficiency:Analysis ServicesincludestheAggregationDesign WizardandtheUsageBased OptimizationWizardtocreate aggregationdesignsbasedonstorage andpercentageconstraintsorqueries submittedbyclientapplications. Reuseofexistingindexesacrosscubes: Whileaggregateviewscanalsobe createdbyqueriesthatdonotknowof theirexistence,theissueisthatAnalysis Servicesmayunexpectedlydropthe indexedviews Lessoverheadduringcubeprocessing: AnalysisServicesisunawareofthe aggregationsanddoesnotdropthe indexedviewsduringpartition processing.Thereisnoneedtodrop indexedviewsbecausetherelational enginemaintainstheindexes continuously,suchasduringINSERT, UPDATE,andDELETEoperationsagainst thebasetables.
Nosophisticatedaggregation algorithms:Indexedviewsmustmatch querygranularity.Thequeryoptimizer doesntconsiderdimensionhierarchies oraggregationgranularitiesinthequery executionplan.Forexample,anSQL querywithGROUPBYon[Month]cant useanindexon[Day]. Maintenanceoverhead:Database administratorsmustmaintain aggregationsbyusingSQLServer ManagementStudioorothertools.Itis difficulttokeeptrackofthe relationshipsbetweenindexedviews andROLAPcubes. Designcomplexity:DatabaseEngine TuningAdvisorcanhelptofacilitate aggregationdesigntasksbyanalyzing SQLServerProfilertraces,butitcant identifyallpossiblecandidates. Moreover,datawarehouse(DW) architectsmustmanuallystudySQL ServerProfilertracestodetermine effectiveaggregations.
103
2.5.4.4.3 Limitations of ROLAP Aggregations WhileROLAPisverypowerful,therearesomestrictlimitationsthatmustbefirstconsideredbefore usingthisapproach: Youmayhavetodesignusingtablebinding(andnotquerybinding)toanactualtableinsteadof apartition.Thegoalofthisguidanceistoensurepartitionelimination. o ThisadviceisspecifictoSQLServerasadatasource.Forotherdatasources,carefully evaluatethebehaviorofROLAPquerieswhenaccessingapartitionedtable. o Itisnotpossibletocreateanindexedviewonaviewcontainingasubselectstatement. ThiswillpreventAnalysisServicesfromcreatingindexviewaggregations. Relationalpartitioneliminationwillgenerallynotwork: o Normally,DWbestpracticeistousepartitionedfacttables. o IfyouneedtouseROLAPaggregations,youmustuseseparatetablesintherelational databaseforeachcubepartition o Partitionsrequirenamedqueries,andthosegeneratebadSQLplans.Thismayvary dependingontherelationalengineyouuse. Youcannotuse: o AnamedqueryoraviewintheDSV. o AnyfeaturethatwillcauseAnalysisServicestogenerateasubquery.Forexample,you cannotuseaCountofRowsmeasure,becauseasubqueryisalwaysgeneratedwhen thistypeofmeasureisused. Themeasuregroupcannothave: o AnymeasuresthatuseMaxorMinaggregation. o Anymeasuresthatarebasedonnullablefieldsintherelationaldatasource.
104
105
106
3.1.2 msmdsrv.ini
YoucancontrolthebehavioroftheAnalysisServicesenginetoagreatdegreefromthemsmdsrv.inifile. ThisXMLfileisfoundinthe<instancedir>/OLAP/Configfolder.Manyofthesettingsinmsmdsrv.ini shouldnotbechangedwithouttheassistanceofMicrosoftProductSupport,buttherearestillalarge numberofconfigurationoptionsthatyoucancontrolyourself.Itistheaimofthissectiontoprovideyou withtheguidanceyouneedtoproperlyconfigurethesesettings.Thefollowingtableprovidesan overviewofthesettingsavailabletoyouandcanserveasstartingpointforexploringreconfiguration options. Setting <MemoryHeapType> <HeapTypeForObjects> <HardMemoryLimit> Usedfor Increasingthroughputofhigh concurrencysystem PreventingAnalysisServices fromconsumingtoomuch memory <LowMemoryLimt> Reservingmemoryforthe AnalysisServicesprocess <PreAllocate> LockingAnalysisServices memoryallocation,and improvingperformanceon WindowsServer2003and potentiallyWindowsServer 2008 <TotalMemoryLimit> ControllingwhenAnalysis Servicesstartstrimmingworking set <CoordinatorExecutionMode> Settingconcurrencyofqueries <CoordinatorQueryMaxThreads> inthreadpoolduringquery execution <CoordinatorBuildMaxThreads> Increasingprocessingspeeds <AggregationMemoryMin> Increasingparallelismof <AggregationMemoryMax> partitionprocessing <CoordinatorQueryBalancingFactor> Preventingsingleusersfrom <CoordinatorQueryBoostPriorityLevel> monopolizingthesystem <LimitSystemFileCacheSizeMB> Controllingthesizeofthefile systemcache <ThreadPool> Increasingthreadpoolsforhigh (andsubsections) concurrencysystems <BufferMemoryLimit> Increasingcompressionduring <BufferRecordLimit> processing,butconsumingmore memory <DataStorePageSize> Increasingconcurrencyona <DataStoreHashPageSize> largemachine <MinIdleSessionTimeout> Cleaningupidlesessionsfaster <MaxIdleSessionTimeout> onsystemsthathavemany Describedin Section2.3.2.4 Section2.3.2
Section2.3.2 Section2.3.2.1
Section2.3.2
Section2.4.2
Section2.3.2.4 Section2.3.2.5
107
connect/disconnects ChangingtheportthatAnalysis Servicesislisteningon Controllingwhichfoldersare viewablebytheserver administrator Controllingwherediskspillsgo Controllingsegregationof dutiesscenarios Controllingsegregationof dutiesscenarios Killingqueriesthatareblocking aprocessingoperationorkilling theprocessingoperation Section5.1 Section2.5andSection5.5
108
Takethefollowingexamplefromacustomerconfiguration.Thecustomerwasexperiencingextremely poorquery/processingperformance.Whenwelookedatthememorycounters,wesawthis.
109
Figure 45 - Memory measurements with scaled counters
110
Figure 46 - Properly scaled counters
Nowthefactthatthereisaseriousmemoryproblemisclear.TakealookattheactualMemoryLimit HighKBvalue.InaPerformanceMonitorlogthisandMemoryLimitLowKBwillalwaysbeconstant valuesthatreflectthevalueofTotalMemoryLimitandLowMemoryLimitrespectivelyinthe msmdsrv.inifile.SoitappearsthatsomeonehasmodifiedtheTotalMemoryLimitfromthedefault80 percenttoanabsolutevalueof12,288bytes,probablythinkingthesettingwasinmegabyteswhenin reality,thesettingisinbytes.Asyoucansee,theresultsofanincorrectlyconfigured.inifilesettingcan bedisastrous. Themoralofthisstoryisthis:Alwaysbeextremelycarefulwhenyoumodifyyourmsmdsrv.inifile settings.OneofthefirstthingstheMicrosoftCustomerServiceandSupportteamdoeswhenworking onanAnalysisServicesissueisgrabthemsmdsrv.inifileandcompareitwiththedefault.inifileforthe customersversionofAnalysisServices.Therearenumerousfilecomparisontoolsyoucanuse,themost obviousbeingWindiff.exe,whichcomeswithWindowsServer. References: 111
Nonshrin nkablememor ryincludesallthestructur resthatarere equiredtokeeptheserver rrunning:act tive usersessions,workingmemoryofr runningqueries,metadata aabouttheob bjectsontheserver,andt the 112
processitself.AnalysisServicesdoesnotreleasememoryinthenonshrinkablememoryspacesthough thismemorycanseestillbepagedoutbytheoperatingsystem(butseethesectiononPreAllocate). Shrinkablememoryincludesallthecachesthatgraduallybuilduptoincreaseperformance:Theformula enginehasacalculationcachethattriestokeepfrequentlyaccessedandcalculatedcellsinmemory. Dimensionsthatareaccessedbyusersarealsokeptincache,tospeedupaccesstodimensions, attributes,andhierarchies.Thestorageenginealsocachescertainaccessedsubcubes.(Notallsubcubes arecached.Forexample,theonesusedbyarbitraryshapesarenotkept.)AnalysisServicesgradually trimsitsworkingsetiftheshrinkablememorycachesarenotusedfrequently.Thismeansthatthetotal memoryusageofAnalysisServicesmayfluctuateupanddown,dependingontheserverstatethisis expectedbehavior. OutsideoftheAnalysisServicesprocessspace,youhavetoconsiderthememoryusedbytheoperation systemitself,otherservices,andthememoryconsumedbythefilesystemcache.Ideally,youwantto avoidpagingimportantmemoryandaswewillsee,thismayrequiresomeconfigurationtweaks. References: Russinovich,MarkandDavidSolomon:WindowsInternals,5thedition. http://technet.microsoft.com/enus/sysinternals/bb963901 Webb,Chris,MarcoRusso,andAlbertoFerrari:ExpertCubeDevelopmentwithMicrosoftSQL Server2008AnalysisServicesChapter11 ArbitraryShapesinAS2005https://kejserbi.wordpress.com/2006/11/16/arbitraryshapesin as2005/
113
PreAllocateThisoptionalparameter(withadefaultof0)enablesyoutopreallocatememoryatservice startup.Itisdescribedinmoredetaillaterinthissection.PreAllocateshouldbesettoavaluelessthan orequaltoLowMemoryLimit. TotalMemoryLimitWhenAnalysisServicesexceedsthismemoryvalue,itstartsdeallocatingmemory aggressivelyfromshrinkablememoryandtrimmingitsworkingset.Notethatthissettingisnotanupper memorylimitfortheservice;ifalargequeryconsumesalotofresources,theservicecanstillconsume memoryabovethisvalue.ThisvaluecanalsobereadfromthePerformanceMonitorcounter: MSOLAP:Memory\TotalMemoryLimit. HardMemoryLimitThissettingisonlyavailableinSQLServer2008AnalysisServicesandSQLServer 2008R2AnalysisServicesnotSQLServer2005AnalysisServices.Itisamoreaggressiveversionof TotalMemoryLimit.IfAnalysisServicesgoesaboveHardMemoryLimit,usersessionsareselectively killedtoforcememoryconsumptiondown. LimitSystemFileCacheMBTheWindowsfilesystemcache(describedlater)isactivelyusedbyAnalysis Servicestostorefrequentlyusedblocksondisk.Forsomescanintensiveworkloads,thefilesystem cachecangrowsolargethatAnalysisServicesisforcedtotrimitsworkingset.Toavoidthis,Analysis ServicesexposestheWindowsAPItolimitthesizeofthefilesystemcachewithaconfigurationsetting inMsmdsrv.ini.Ifyouchoosetousethissetting,notethatitlimitsthefilesystemcachefortheentire server,notjustfortheAnalysisServicesfiles.Thisalsomeansthatifyourunmorethanoneinstanceof AnalysisServicesontheserver,youshouldusethesamevalueforLimitSystemFileCacheMBforeach instance. 3.1.3.2.1 PreAllocate and Locked Pages ThePreAllocatesettingfoundinmsmdsrv.inicanbeusedtoreservevirtualand/orphysicalmemoryfor AnalysisServices.ForinstallationswhereAnalysisServicescoexistswithotherservicesonthesame machine,settingPreAllocatecanprovideamorestablememoryconfigurationandsystemthroughput. NotethatiftheserviceaccountusedtorunAnalysisServicesalsohastheLockpagesinMemory privilege,PreAllocatecausesAnalysisServicestouselargememorypages.Largememorypagesare moreefficientonabigmemorysystem,buttheytakelongertoallocate.LockpagesinMemoryisset usingGpedit.msc.Bearinmindthatlargememorypagescannotbeswappedouttothepagefile.While thiscanbeanadvantagefromaperformanceperspective,ahighnumberofallocatedlargepagescan causethesystemtobecomeunresponsive. Important:PreAllocatehasthelargestimpactontheWindowsServer2003operatingsystem.Withthe introductionofWindowsServer2008,memorymanagementhasbeenmuchimproved.Wehavebeen testingthissettingonWindowsServer2008,buthavenotmeasuredanysignificantperformance benefitsofusingPreAllocateonthisplatform.However,youmaywantstillwanttomakeuseofthe lockedpagesfunctionalityinWindowServer2008. TolearnmoreabouttheeffectsofPreAllocate,seethefollowingtechnicalnote:
114
Thesetwosettingsdeterminehowmuchmemoryisallocatedforthecreationofaggregationsand indexesineachpartition.WhenAnalysisServicesstartspartitionprocessing,parallelismisthrottled basedontheAggregationMemoryMin/Maxsetting.Thesettingisperpartition.Forexample,ifyou startfiveconcurrentpartitionprocessingjobswithAggregationMemoryMin=10,anestimated50 percent(5x10%)ofreservedmemoryisallocatedforprocessing.Ifmemoryrunsout,newpartition processingjobsareblockedwhiletheywaitformemorytobecomeavailable.Onalargememory system,allocating10percentofavailablememoryperpartitionmaybetoomuch.Inaddition,Analysis Servicesmaysometimesmisestimatethemaximummemoryrequiredforthecreationofaggregatesand indexes.Ifyouprocessmanypartitionsinparallelonalargememorysystem,loweringthevalueof AggregationMemoryLimitMinandAggregationMemoryMaxmayincreaseprocessingspeed.Thisworks becauseyoucandriveahigherdegreeofparallelismduringtheprocessindexphase. LiketheotherAnalysisServicesmemorysettings,ifthissettinghasavaluegreaterthan100itis interpretedasafixedamountofkilobytes,andifislowerthan100,itisinterpretedasapercentageof thememoryavailabletoAnalysisServices.Formachineswithlargeamountsofmemoryandmany partitions,usinganabsolutekilobytevalueforthesesettingsmayprovideabettercontrolofmemory thanusingapercentagevalue. 3.1.3.2.3 BufferMemoryLimit and BufferRecordLimit OLAP\Process\BufferMemoryLimitdeterminesthesizeofthefactdatabuffersusedduringpartition dataprocessing.WhilethedefaultvalueoftheOLAP\Process\BufferMemoryLimitissufficientformost deployments,youmayfinditusefultoalterthepropertyinthefollowingscenario. Ifthegranularityofyourmeasuregroupismoresummarizedthantherelationalsourcefacttable,you maywanttoconsiderincreasingthesizeofthebufferstofacilitatedatagrouping.Forexample,ifthe sourcedatahasagranularityofdayandthemeasuregrouphasagranularityofmonth;AnalysisServices 115
mustgroupthedailydatabymonthbeforewritingtodisk.Thisgroupingoccurswithinasinglebuffer anditisflushedtodiskafteritisfull.Byincreasingthesizeofthebuffer,youdecreasethenumberof timesthatthebuffersareswappedtodisk.Becausetheincreasedbuffersizesupportsahigher compressionratio,thesizeofthefactdataondiskisdecreased,whichprovideshigherperformance. However,beawarethathighvaluesfortheBufferMemoryLimitusemorememory.Ifmemoryrunsout, parallelismisdecreased. Youcanuseanotherconfigurationsettingtocontrolthisbehavior:BufferRecordLimit.Thissettingis expressedinreceivedrecordsfromthedatasourceinsteadofaMemory%/Kbsize.Thelowerofthe twotakesprecedence.Forexample,ifBufferMemoryLimitissetto10percentofa32GBmemory spaceandBufferRecordLimitissetto10millionrows,either3.2GBor10,000,000timestherowsizeis allocatedforthemergebuffer,whicheverissmaller. 3.1.3.2.4 Heap Settings, DataStorePageSize, and DataStoreHashPageSize Duringqueryexecution,AnalysisServicesgenerallytouchesalotofdataandperformsmanymemory allocations.AnalysisServiceshashistoricallyreliedonitsownheapimplementationtoachievethebest performance.However,sinceWindowsServer2003,advancesintheWindowsServeroperatingsystem meanthatmemorycannowbemanagedmoreefficientlybytheoperatingsystem.Thisturnsouttobe especiallytrueformultiuserscenarios.Becauseofthis,serversthathavemanyusersshouldgenerally applythefollowingchangestothemsmdsrv.inifile.
Default Multi-user, faster heap Setting 1 2 <MemoryHeapType> 1 0 <HeapTypeForObjects> ItisalsopossibletoincreasethepagesizethatisusedformanagingthehashtablesAnalysisServices usestolookupvalues.Especiallyonmodernhardware,wehaveseenthefollowingchangeyielda significantincreaseinthroughputduringqueryexecution.
KB2004668Youexperiencepoorperformanceduringindexingandaggregationoperations whenusingSQLServer2008AnalysisServiceshttp://support.microsoft.com/kb/2004668
3.1.3.2.5 Clean Up Idle Sessions Clienttoolsmaynotalwayscleanupsessionsopenedontheserver.Thememoryconsumedbyactive sessionsisnonshrinkable,andhenceisnotreturnedtheAnalysisServicesoroperatingsystemprocess forotherpurposes.Afterasessionhasbeenidleforsometime,AnalysisServicesconsidersthesession expiredandmovethememoryusedtotheshrinkablememoryspace.Butthesessionstillconsumes memoryuntilitiscleanedup. 116
Becauseidlesessionsconsumevaluablememory,youmaywanttoconfiguretheservertobemore aggressiveaboutcleaningupidlesessions.Therearesomemsmdsrv.inisettingsthatcontrolhow AnalysisServicesbehaveswithrespecttoidlesessions.Notethatavalueofzeroforanyofthefollowing settingsmeansthatthesessionsorconnectioniskeptaliveindefinitely. Setting <MinIdleSessionTimeOut> Description Thisistheminimumamountoftimeasessionisallowedtobeidle beforeAnalysisServicesconsidersitreadytodestroy.Sessionsare destroyedonlyifthereismemorypressure. Thisisthetimeafterwhichtheserverforciblydestroysthesession, regardlessofmemorypressure. Thisisthetimeoutthatcontrolssessionsthatnolongerhavea connectionassociatedwiththem.Examplesoftheseareusers runningaqueryandthendisconnectingfromtheserver. Thistimeoutcontrolshowlongaconnectioncanbekeptopenand idleuntilAnalysisServicesdestroysit.Notethatiftheconnectionhas noactivesessions,MaxIdleSessionTimeouteventuallymarksthe sessionforcleaningandtheconnectioniscleanedwithit.
<MaxIdleSessionTimeout> <IdleOrphanSessionTimeout>
<IdleConnectionTimeout>
117
118
Figure 48 - Coordinator Queries
CoordinatorQueryBalancingFactor 1 CoordinatorQueryBoostPriorityLevel 3
1 0
Ifyouwanttounderstandexactlywhatthesesettingsdo,youneedtoknowalittleabouttheinternals ofAnalysisServices.First,awordofwarning:TheremainderofthissectionlooksatAnalysisServicesat averydetailedlevel.Itisperfectlyacceptabletotakeaqueryworkloadandtestwiththedefault settingsandthenwiththemultiusersettingstodecideifitisworthmakingthesechanges. Withthedisclaimeroutoftheway,letslookatanexampletoexplainthisbehavior.Ona45core WindowsServer2008serverwithdefault.inifilesettings,youhavealongrunningquerythatappearsto beblockingmanyoftheotherqueriesbeingexecutedbyotherusers.BehindthescenesinAnalysis Services,multiplesegmentjobs(differentfromcoordinatorjobs)arecreatedtoquerytherespective segments.AsegmentofdatainAnalysisServicesiscomposedofroughly64,000records,whichare subdividedintopages.Thereare256pagesinasegmentand256recordsinapage.Theserecordsare broughtintomemoryinchunksuponrequestbyqueries.AnalysisServicesdetermineswhichpages needtobescannedtoretrievetherelevantrecordsforthedatarequested.Thesejobsarechained, meaningJob1queuesJob2tothethreadpool,Job1performsitsownjob,Job2queuesJob3tothe threadpool,Job2performsitsownjob,andsoon.Eachjobhasitsownthread,orsegmentjob. Inourexample,usingthedefaultsettingsthefirstqueryfiresoff720jobs,scanningalotofdata.The secondqueryfiresoff1job.Thefirst720jobsfireofftheirown720jobs,usingupallofthethreads.This preventsthesecondqueryfromexecuting,becausenothreadsareavailable.Thisbehaviorcauses blockingofthesecondandsubsequentqueriesthatneedthreadsfromtheprocesspool.Themultiuser settings(CoordinatorQueryBalancingFactor=1,CoordinatorQueryBoostPriorityLevel=0)preventallof thethreadsfrombeingallocatedsothesecondandthirdqueriescanexecutetheirjobs. Again,eachsegmentjobusesonethread.Ifthelongrunningqueryrequiresscanningofmultiple segments,AnalysisServicescreatesthenecessarynumberofthreads.Insingleusermode,thefirst queryfiresoff720jobs,andthesecondqueryfiresoff1job.Eachsegmentjobisimmediatelyqueued upbeforethepriorsegmentjobbeginsscanningdata.Thefirst720jobsfireofftheirown720jobs, preventingsecondqueryfromexecuting.Inmultiusermode,notallthreadsareallocated,allowing secondquery(andthird)toexecutetheirjobs. Becarefulmodifyingthesesettings;althoughthesesettingsreduceorstoptheblockingofshorter runningqueriesbylongerrunningones,itmayslowtheresponsetimesofindividualqueries.(Inthe figure,SSASstandsforSQLServerAnalysisServices.)
120
Figure 49 - Default settings
3.1.4.4 Hyperthreading
Wereceivenumerousquestionsfromcustomersaroundhyperthreading.TheAnalysisServices developmentteamhasnoofficialrecommendationonhyperthreading;itisincludedinthisbookonly 121
Consultthesubsectionsthatfollowforguidanceinthesespecificsetups.However,thefollowinggeneral guidanceapplies. SANMegaLUNs:IfyouareusingaSAN,yourstorageadministratormaybeabletoprovisionyoua single,largeLUNforyourcubes.Unlessyouplantobuildaconsolidationenvironment,havingsucha single,megaLUNisprobablytheeasiestandmostmanageablewaytoprovisionyourstorage.Firstof all,itprovidestheIOPSasageneralresourcetotheserver.Secondly,andadditionaladvantageofa megaLUNisthatyoucaneasilydiskalignthisinWindowsServer2003.ForWindowsServer2008you donotneedtoworryaboutdiskalignmentonnewlycreatedvolumes. WindowsServerdynamicdiskstripes:UsingDiskManageritispossibletocombinemultipleLUNsintoa singleWindowsvolume.Thisisaverysimplewaytocombinemultiple,similarlysized,similarly performingLUNsintoasinglemountpointordriveletter.Wehavetesteddynamicdiskstripesin WindowsServer2008R2allthewayupto100.000IOPSandtheperformanceoverheadtothatlevelis negligible. Note:Youcannotusedynamicdiskstripesinacluster.Thisisdiscussedingreaterdetaillaterin Part2.
122
Drivelett tersversusmountpoints:Bothdrivele ettersandmo ountpointswillworkwithAnalysisServ vices cubes.Ift theserverisd dedicatedtoa asingleAnaly ysisServicesinstance,adr rivelettermaybethesimp plest solution.C Choosingdriv velettersvers susmountpo ointsisoftenamatterofp personalprefe erence,oritc can bedrivenbythestandardsofyouroperationste eam.Fromtheperspective eofperforma ance,oneisnot totheother. superiort AllowedB BrowsingFolders:Rememb berthatinord derforadirectorytobevi isibletoadmi inistratorsof AnalysisS ServicesinSQ QLServerMan nagementStu udio,itmustb belistedinAl llowedBrows singFolders,w which isavailabl leinSQLServ verManagem mentStudioby yclickingServ verPropertie esandthenA Advanced Propertie es.
TheAnaly ysisServicesa accountmustalsohavepe ermissiontob bothreadand dwritetothesefolders.Ju ust addingthemtotheAll lowedBrowsingFolderslist tisnotenoug ghyoumus stalsoassignfilesystem permissio ons. MFTversu usGPTdisk:Ifyouexpectyourcubestobelargerth han2terabytes,youshoul lduseaGPTd disk. Thedefau ult,anMFTdi isk,onlyallow ws2terabytepartitions. TempDirFolder:TheTe empDirfolde er,configured dintheAdvan ncedPropertiesoftheserv ver,shouldbe e movedtothefastestv volumeyouha ave.Thismay ymeanyouw willshareTem mpDirwithcub bedata,whic chis uplancapacit tyaccordingly y.Formorein nformation,seethesectionabouttheT TempDirfolde er. fineifyou NTFSAllo ocationUnitS Size(AUS):W Withcarefulop ptimization,it tissometime espossibletogetslightlyb better performancebysmartlychoosingb between32Ko or64K(afew wpercent).Bu ut,unlessyouarehuntingfor benchmar rkperforman nce,justgowith32K.Ifyou uhavestanda ardizedon64 4KforotherSQLServer services,t thatwillwork ktoo. 123
Dontsuboptimizestorage:Thereareafewcaseswhereitmakessensetosplityourdataintomultiple volumesforexampleifyouhavedifferentstoragetypesattachedtotheserver(suchasNANDfor latestdataandSATAdrivesforhistoricaldata).However,itisgenerallynotagoodideatosuboptimize thestoragelayoutofAnalysisServicesbycreatingcomplicateddatadistributionsthatspandifferent storagetypes.Theruleofthumbforoptimaldisklayoutistoutilizealldiskdrivesforallcubepartitions. Createlargepoolsofdisk,presentedassingle,largevolumes. ExcludeAnalysisServicesfoldersfromvirusscanners:Ifyouarerunningavirusscannerontheserver, makesuretheDatafolder,TempDir,andbackupfoldersarenotbeingscannedortouchedbythefilter driversoftheantivirustool.TherearenoexecutablefilesintheseAnalysisServicesfolders,andenabling virusscannersonthefoldermayslowdownthediskaccessspeedssignificantly. ConsiderDefragmentingtheDataFolder:AnalysisServicescubesgetveryfragmentedovertime.We haveseencaseswheredefragmentingcubedatafolders,usingthestandarddiskdefragmentutility, yieldedasubstantialperformancebenefit.Notethatdefragmentingadrivealsohasimpactonthe performanceofthatdriveasitmovesthefilesaround.IfyouchoosetodefragmentanAnalysisServices drive,dosoinbatchwindowwheretheservicecanbetakenofflinewhilethedefragmentationhappens, orplandiskspeedsaccordinglytomakesuretheperformanceimpactisacceptable. References: Whitepaper:ConfiguringDynamicVolumeshttp://technet.microsoft.com/en us/library/bb727122.aspx
Reference es: SQ QLIOdownload:http://ww ww.microsoft t.com/downlo oads/en/deta ails.aspx?familyid=9a8b005b 84 4e44f248d6 65cb53442d9 9e19&display ylang=en Whitepaper:A W AnalyzingI/Ocharacteristi icsandsizingstorageforS SQLServerDa atabase Applicationshttp://sqlcat t.com/whitep papers/archiv ve/2010/05/10/analyzingiocharacteri istics ndsizingstor ragesystemsforsqlserve erdatabasea applications.a aspx an Blog:TheMem moryShellGame ttp://blogs.m msdn.com/b/n ntdebugging/archive/2007 7/10/10/them memoryshellgame.aspx ht
Ifyouhav vea1GbpsN NIC,butonlya a100Mbpsswitch,TaskM Managerdispl lays100Mbp ps.Depending gon yournetw worktopology ytheremayb bemoretode eterminingyo ourlinkspeed dthanthis,bu utusingTask Managerisasimplewaytogetaro oughideaoft theconfigurat tion. Inadditiontocreatingahighspeed dnetwork,the erearesome eadditionalco onfigurations syoucanchan nge tofurther rspeedupne etworktraffic.
3.1.6.1 Use Shar Memory for Loc SQL Se red cal erver Data Sources a s
IfAnalysis sServicesiso onthesamep physicalmach hineastheda atasource,an ndthedataso ourceisSQL Server,yo oushouldmakesureyoua areexchangin ngdataovert thesharedme emoryprotoc col.Shared memoryismuchfasterthanTCP/IP P,asitavoidstheoverhead dofthetrans slationlayersinthenetwork stack.Sha aredmemoryisonlypossib bleiftheSQL LServerdatab baseisonthe esamephysic calmachineas AnalysisS Services.Ifyoucannotgetahighspeednetworksetupinyouror rganization,y youcansometimes benefitfro omrunningS SQLServeran ndAnalysisSe ervicesonthe esamephysic calmachine.
125
Tomodify yyourdataso ourceconnec ctiontospecif fysharedmem mory: 1. First,m makesuretha attheShared dMemorypro otocolisenab bledinSQLSe erver Config gurationMana ager.
3. Aftery youstartproc cessing,youc canverifyyou urconnection nisusingshar redmemoryb by execut tingthefollow wingSELECTs statement.
SELECT session_i T id, net_tr ransport, n net_packet t_size FROMsy ys.dm_exec_ _connectio ons
Thenet_t transportfortheAnalysisServicesSPID Dshouldshow w:Sharedmemory. Formoreinformationaboutshared dmemorycon nnections,see eCreatingaValidConnec ctionStringU Using msdn.microso oft.com/enus s/library/ms1 187662.aspx). . SharedMemoryProtocol(http://m Tocompa areTCP/IPand dsharedmem mory,weranthefollowing gtwoprocess singcomman nds.
<!--SQL Server Na ative Clien with TC nt CP--> <Batchxm mlns="http p://schemas s.microsof ft.com/anal lysisservi ices/2003/e engine"> <Paralle el> <Process s <Object> > <Databas seID>Adven nture Works DW 2008R s R2</Databas seID> <CubeID> >Adventure Works</Cu e ubeID> </Object t> <Type>Pr rocessFull l</Type> <DataSou urcexsi:ty ype="Relati ionalDataS Source"> <ID>Adve enture Wor rks DW</ID> > <Name>Ad dventure Works DW</N W Name>
126
<ConnectionString> Provider=SQLNCLI10.1;Data Source=tcp:johnsi5\kj; Integrated Security=SSPI;Initial Catalog=AdventureWorksDW2008R2; </ConnectionString> <ImpersonationInfo> <ImpersonationMode>ImpersonateCurrentUser</ImpersonationMode> </ImpersonationInfo> <Timeout>PT0S</Timeout> </DataSource> </Process> </Parallel> </Batch> <!--SQL Native Client with shared memory--> <Batchxmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Parallel> <Process <Object> <DatabaseID>Adventure Works DW 2008R2</DatabaseID> <CubeID>Adventure Works</CubeID> </Object> <Type>ProcessFull</Type> <DataSourcexsi:type="RelationalDataSource"> <ID>Adventure Works DW</ID> <Name>Adventure Works DW</Name> <ConnectionString> Provider=SQLNCLI10.1;Data Source=lpc:johnsi5\kj; Integrated Security=SSPI;Initial Catalog=AdventureWorksDW2008R2; </ConnectionString> <ImpersonationInfo> <ImpersonationMode>ImpersonateCurrentUser</ImpersonationMode> </ImpersonationInfo> <Timeout>PT0S</Timeout> </DataSource> </Process> </Parallel> </Batch>
127
Figure 5 - Compa 53 aring rows/sec throu ughput
TodeterminewhetherTCPChimneyisenabled,runthefollowingfromanelevatedcommandprompt. netshinttcpshowglobal Intheresults,checktheChimneyOffloadStatesetting. TCPGlobalParameters ReceiveSideScalingState ChimneyOffloadState NetDMAState DirectCacheAccess(DCA) ReceiveWindowAutoTuningLevel AddOnCongestionControlProvider ECNCapability RFC1323Timestamps Inthisexample,theresultsshowthatTCPChimneyoffloadingissettoautomatic.Thismeansthatitis enabledaslongastherequirementsmentionedearlieraremet. AfteryouverifythatTCPChimneyisenabledattheoperatingsystemlevel,checktheNICsettingsin devicemanager: 1. Gotostart|runandtypedevmgmt.msc. 2. InDeviceManager,expandNetworkAdapters,andrightclickthenameofthephysicalNIC adapter,andthenclickProperties. 3. OntheAdvancedtab,underProperty,clickTCPChimneyOffloadorTCPConnectionOffload, andthenunderValue,verifythatEnabledisdisplayed.YoumayneedtodothisforbothIPv4 andIPv6.NotethatTCPChecksumOffloadisnotthesameasTCPChimneyOffload. IfthesystemhasIPsecenabled,noTCPconnectionsareoffloaded,andTCPChimneyprovidesno benefit.TherearenumerousdifferentconfigurationoptionsforTCPChimneyoffloadingthatouroutside thescopeofthisbook.Seethereferencessectionforadeepertreatment. 129
3.1.6.2.2 Jumbo Frames JumboframesareEthernetframeswithmorethan1,500andupto9,000bytesofpayload.Jumbo frameshavebeenshowntoyieldasignificantthroughputimprovementduringAnalysisServices processing,specificallyProcessData.NetworkthroughputisincreasedwhileCPUusageisminimized. Jumboframesareonlyavailableongigabitnetworks,andalldevicesinthenetworkpathmustsupport them(switches,routers,NICs,andsoon). MostdefaultEthernetsetupsareconfiguredtohaveMTUsizesofupto1,500bytes.Jumboframes allowyoutogoupto9,000bytesinasingletransfer.Toenablejumboframes: 1. Configureallrouterstosupportjumboframes. 2. ConfiguretheNICsontheAnalysisServicesmachineandthedatasourcemachineto supportjumboframes. a) ClicktheStartbutton,pointtoRun,andthentypencpa.cpl. b) Rightclickyournetworkconnection,andthenclickProperties. c) ClickConfigure,andthenclicktheAdvancedtab.UnderProperty,clickJumbo Frame,andthenunderValue,changethevaluefromDisabledto9kbMTUor 9014,dependingontheNIC. d) ClickOKonallthedialogboxes.Afteryoumakethechange,theNICloses networkconnectivityforafewsecondsandyoushouldreboot. 3. Afteryouconfigurejumboframes,youcaneasilytestthechangebypingingtheserver withalargetransfer: Ping<servername>fl9000 YoushouldonlymeasureonenetworkpacketperpingrequestinNetworkMonitor.
131
First,setupmultipleNICsinthesourceandthetarget,eachwithitsownIPnumber.MatcheachNICon thecubeserverwithacorrespondingNIContherelationaldatabase.Setupthesubnetmasksoonlythe desiredNIConthesourcecanbereachedfromitspartneronthecubeserver.Ifyouarelimitedin bandwidthontheswitchesorwanttocreateaverysimplesetup,youcanusethistechniquewitha crossovercable,whichwehavedonesuccessfully Second,addadatasourceforeachNIConthedatasource,andsetupeachdatasourcetopointtoits ownsourceNIC. Third,configurepartitionsinthecubesothattheyarebalancedacrossalldatasources.Forexample,if youhave16partitionsand4datasourcesperNICpoint4partitionstoeachdatasource. Schematically,thesetuplookslikethis.
loggingandremovetheI/Ooverhead.TheserverpropertythatcontrolswhetherFlightRecorderis enabledistheLog\FlightRecorder\Enabledproperty.Bydefault,thispropertyissettotrue.
MSOLAP:Processing MSOLAP:MDX
Rowsread/sec Rowswritten/sec *
Measuresspeedofrelationreadandefficiency ofmergebuffers. Usedbycubetunerstodeterminewhether calculationscriptsorMDXqueriescanbe improved. Measurebytesreadfromthefilesystem cache. MeasuresIOPSfromfilesystemcache ContainsthecapacityplantofollowifNIC speedslows.Seesection2.6.5. Discoversunstableconnections.
DependingonhowoftenyouquerytheDMV,youcangeneratealotofdata.Itisoftenagoodideato keeptherecentdataatahighgranularityandaggregateolderdata.UsingatoollikeMicrosoft StreamInsightenablesyoutoperformsuchhistoricalaggregationinrealtime. CapturingtheDMVdataenablesyoutomonitortheprogressofqueriesandalertyoutoheavyresource consumersearly.HerearesomeexamplesofissuesyoucanidentifywhenyouuseDMVs: Queriesthatconsumealotofmemory Queriesthathavebeenblockedforalongtime Locksthatareheldforalongtime Sessionsthathaverunforalongtime,orconsumedalotofI/O Connectionsthataretransmittingalargeamountofdataoverthenetwork
135
136
Ifyouhaveanylongrunning,highmemoryconsumingqueries,youshouldalsomeasurehowmuch memorytheyconsumewhiletheyexecute. CopythedataintoanExcelspreadsheetforfurtheranalysis.YoucanalsousetheCodePlexproject ResMoncube(seereferencesection)toperiodicallylogsnapshotsofthisDMVandbrowsememory usagetrendssummarizedinacube. Withthedatacollectedintheprevioussection,youcandefinesomevaluesneededtosetthememory: [PhysicalRAM]=Thetotalphysicalmemoryonthebox [AvailableRAM]=ThevalueofthePerformanceMonitorcounterMemory/AvailableBytesasnoted downearlier. [NonShrinkableMemory]=ThesumoftheMemoryUsedcolumnfrom $SYSTEM.DISCOVER_MEMORYUSAGEwherethecolumnShrinkableisFalse. [ValuableObjects]=Thesumofallobjectsthatyouwanttoreservememoryforfrom $SYSTEM.DISCOVER_MEMORYUSAGEwherecolumnShrinkableisTrue.Forexample,youwillmost likelywanttoreservememoryforalldimensionsandattributes.Ifyouhaveasmallcube,thisvaluemay simplybeeverythingthatismarkedasshrinkable. [WorstQueriesMemory]=Theamountofmemoryusedbytheallthemostdemandingqueriesyou expectwillrunconcurrently.YoucanusetheDMV$system.discover_memoryusagetomeasurethison aknownworkload. WiththeprecedingvaluesyoucancalculatethememoryconfigurationforAnalysisServices: LowMemoryLimit=[NonShrinkableMemory]+[ValuableObjects]/[TotalRAM]Butkeepagapofat least20percentbetweenthisvalueandHighMemoryLimittoallowthememorycleanerstorelease memoryatagoodrate.
137
HighMemoryLimit=([AvailableRAM][WorstQueriesMemory])/[TotalRAM] HardMemoryLimit=[AvailableRAM]/[TotalRAM] LimitSystemFileCacheMB=[AvailableRAM]LowMemoryLimit Notethatitmaynotalwaysbepossibletomeasureallthecomponentsthatmakeuptheseequations. Insuchcase,yourbestbetistoguesstimatethem.TheideabehindthismethodisthatAnalysisServices willalwaysholdontoenoughmemorytokeepthevaluableobjectsinmemory.Whatisvaluable dependsonyourparticularsetupandqueryset.Therestoftheavailablememoryissharedbetweenthe filesystemcacheandtheAnalysisServicescaches;ifyouusetheoperatingsystemsmemoryusage optimizations,theidealbalancebetweenAnalysisServicesandthefilesystemcacheisadjusted dynamically. IfAnalysisServicescoexistswithotherservicesonthemachine,taketheirmaximummemory consumptionintoconsideration.Whenyoucalculate[AvailableRAM],subtractthemaximummemory usebyotherlargememoryconsumers,suchastheSQLServerrelationalengine.Also,makesurethose othermemoryconsumershavetheirmaximummemorysettingsadjustedtoallowspaceforAnalysis Services. Thefollowingdiagramillustratesthedifferentusesofmemory.
138
FromtheperspectiveoftheI/Osystem,thestorageenginerequestsdatafromanoffsetinafile.The buildingblocksofthestorageusedbyAnalysisServicesarethefilesusedtostoredimensionandfact data.Dimensiondataistypicallycachedbythestorageengine.Hence,themostfrequentlyrequested filesfromthestoragesystemaremeasuregroupdata,andtheyhavethefollowingfilenames: *.fact.data,*.aggs.rigid.dataand*.agg.flex.data.BecauseAnalysisServicesusesbufferedI/O, frequentlyrequestedblocksinfilesaretypicallyretainedbytheNTFSfilesystemcache.Notethatthis meansthatthememoryusedforthefilesystemcachingofdatacomesfromoutsidetheAnalysis Servicesworkingset. WhenablockfromafileisrequestedbyAnalysisServices,thepathtakenbytheoperatingsystem dependsonthestateofthecache. 139
Figure 58 - Accessing a file in the NTFS cache
Intheprecedingillustration,AnalysisServicesexecutestheReadFileExcalltotheWindowsAPI. Iftheblockisnotinthecache,anI/Orequestisissued(2),thefileisputinthecache(3),and thedataisreturnedtoAnalysisServices(5). Ifheblockisalreadyinthecache(3),itissimplyreturnedtoAnalysisServices(5). Ifablockisnotfrequentlyaccessedorifthereismemorypressure,theNTFSfilesystemcache maychoosetoplacetheblockintheStandbyCache(4)andeventuallyremovethefilefrom memory.Ifthefileisrequestedbeforeitisremoved,itisbroughtbackintotheSystemCache (3)andthenreturnedtoAnalysisServices(5). o NotethatinWindowsServer2003,thefileissimplyremovedfromthesystemcache, bypassingthestandbycache.
exceedthefilesystemcachesize,youwilleventuallyhavetoassistcubeperformancewithafastdisk system.Measuringthecurrentcachehitratiohelpsshedlightonthis. TomeasuretheI/Oservedbythefilesystemcache,usePerformanceMonitortomeasureSystem:File ReadBytes/secandSystemFileReadOperations/sec.Thesecounterswillgiveyouanestimateofthe numberofI/Ooperationsandfilebytesthatareservedfrommemory.BycomparingthiswithLogical Disk/Diskreads/secyoucanmeasuretheratiobetweenmemorybufferedandphysicalI/O.Asthe amountofdatainthecubegrows,youwilloftenseethattheamountofdiskaccessbeginstogrowin proportiontomemoryaccess.Byextrapolatingfromhistoricaltrends,youcanthendecidewhatthe bestratiobetweenIOPSandRAMsizesshouldbegoingforward. TomeasurethetotalmemoryconsumptionofAnalysisServices,youwillalsohavetotakethefile systemcacheintoaccount.Thetotalmemoryusedbyanalysisservicesisthesumof: Processmsmdsrv.exe/PrivateBytesThememoryusedbyAnalysisServicesitself MemoryCacheBytesThefilescurrentlyliveincache MemoryStandbyCacheNormalPriorityBytesThefilesthatcanbefreedfromthecache
Dimensionprocessing:Tooptimizedimensionprocessing,werecommendthatyouusethetechniques describedlaterinthisdocumenttoavoidspillsandspeedupprocessing.ByTableshouldgenerallyonly beusedifyoucankeepthedimensiondatainmemoryduringprocessing. Aggregationprocessing:Duringcubeprocessing,aggregationbuffersdescribedinconfigurationsection determinetheamountofmemorythatisavailabletobuildaggregationsforagivenpartition.Ifthe aggregationbuffersaretoosmall,AnalysisServicessupplementstheaggregationbufferswith temporaryfiles.Tomonitoranytemporaryfilesusedduringaggregation,reviewMSOLAP:Proc Aggregations\Tempfilebyteswritten/sec.Youshouldtrytodesignyourcubeinsuchawaythat memoryspillstotempfilesdoesnotoccur,thatis,keepthetempbyteswrittenatzero.Thereare severaltechniquesavailabletoavoidmemoryspillsduringaggregationprocessing:
141
ItisgenerallyagoodideatosplitProcessDataandProcessIndexoperationsintotwodifferent processingjobs.ProcessDatatypicallyconsumeslessmemorythanProcessIndexandyourunmany ProcessDataoperationsinparallel.DuringProcessIndex,youcanthendecreaseconcurrencyifyouare shortonmemory,toavoidthediskspill. ROLAPdimensions:Ingeneral,youshouldtrytoavoidROLAPdimensions;MOLAPstoresaremuch fasterfordimensionaccess.However,therequirementforROLAPdimensionsisoftendrivenbyalackof sufficientmemorytoholdtheattributestoresrequiresfordrillthroughactions,whichreturnsdatausing adegenerateROLAPdimension.Ifthisisyourscenario,youmaynotbeabletoavoidspillstothe TempDirfolder. Ifyoucannotdesignthecubetofitalloperationsinmemory,spillingtoTempDirmaybeyouronly option.Ifthatisthecase,werecommendthatyouplacetheTempDirfolderonafastLUN.Youcan eitheruseaLUNbackedbycaches(forexampleinaSAN)oronethatsitsonfaststorageforexample, NANDdevices.
142
Accessthefilesystemasaloggedinuser
143
Figure 59 - Changing the port used for Analysis Services
BearinmindthatyouwillneedtoopentheportassignedhereinyourfirewallforTCP/IPtraffic.Ifyou leavethedefaultvalueof0,AnalysisServiceswilluseport2382. Ifyouareusingnamedinstances,yourclientapplicationmayalsoneedtoaccesstheSQLServer browserservice.Thebrowserserviceallowsclientstoresolveinstancenamestoportnumbers,andit listensonTCPport2382.NotethatitispossibletoconfiguretheconnectionstringforAnalysisServices insuchawaythatyouwillnotneedthebrowserserviceportopen.Toconnectdirectlytotheportthat AnalysisServicesislisteningon,usethisformat[Servername}:[Port].Forexample,toconnecttoan instancelisteningonport2384onserverMyServer,useMyServer:2384. AnalysisServicescanbesetuptouseHTTPtocommunicatewithclients.Ifyouchoosethisoption, followtheguidelinesforconfiguringMicrosoftInternetInformationServices.Inthiscase,youwill typicallyneedtoopeneitherport80orport443.
144
References: Howto:ConfigureWindowsFirewallforAnalysisServicesAccess http://msdn.microsoft.com/enus/library/ms174937.aspx ResolvingCommonConnectivityIssuesinSQLServer2005AnalysisServicesConnectivity Scenarioshttp://msdn.microsoft.com/enus/library/cc917670.aspx o AlsoappliestoSQLServer2008AnalysisServicesandSQLServer2008R2Analysis Services ConfiguringHTTPAccesstoSQLServer2005AnalysisServicesonMicrosoftWindows2003 http://technet.microsoft.com/enus/library/cc917711.aspx o AlsoappliestoSQLServer2008AnalysisServices,SQLServer2008R2AnalysisServices, WindowsServer2008,andWindowsServer2008R2 AnalysisServices2005protocolXMLAoverTCP/IP http://www.mosha.com/msolap/articles/as2005_protocol.htm
145
146
However,keepinmindthatalocaladministratorcouldstillaccessthemsmdsrv.inifileandalterthe changesyouhavemade,soyoushouldauditforthispossibility.
147
3.4.1 Backup/Restore
Cubesaredatastructuresondiskandassuch,theycontaininformationthatyoumaywanttobackup. AnalysisServicesbackupAnalysisServiceshasabuiltinbackupfunctionalitythatgeneratesasingle backupfilefromacubedatabase.AnalysisServicesbackupspeedshavebeensignificantlyimprovedin SQLServer2008andformostsolutions,youcansimplyusethisbuiltinbackupandrestore functionality.Aswithallbackupsolutions,youshouldofcoursetesttherestorespeed. SANbasedbackupIfyouuseaSAN,youcanoftenmakebackupsofaLUNusingthestoragesystem itself.ThisbackupprocessistransparenttoAnalysisServicesandtypicallyoperatesontheLUNlevel. YoushouldcoordinatewithyourSANadministratortomakesurethecorrectLUNsarebackedup, includingallrelevantdatafoldersusedtostorethecube.YoushouldalsomakesurethattheSAN backuputilityusesaVDI/VSScomplianttooltocalltoWindowsbeforethebackupistaken.Ifyoudonot useaVDI/VSStool,youriskgettingchkdskerrorswhentheLUNisrestored. FilebasedbackupcopyInSQLServer2008AnalysisServicesandSQLServer2008R2AnalysisServices, youcanattachdatabaseifyouhaveacopyofthedatafolderthedatabaseresidesin.Thismeansthata detachedcopyoffilesinastalecubecanserveasabackupofthedatabase.Thisoptionisavailableonly withSQLServer2008AnalysisServicesandSQLServer2008R2AnalysisServices.Youcanusethesame toolsthatyouuseforscaleoutcubes(forexample,RobocopyorNiceCopy).Restoringinthiscase meanscopyingthefilesbacktotheserverandattachingthedatabase. DontbackupWhilethismaysoundlikeasillyoption,itdoeshavemeritinsomedisasterrecovery scenarios.Cubesarebuiltonrelationaldatasources.Ifthesesourcesareguaranteedtobeavailableand securelybackedup,itmaybefastertosimplyreprocessthecubethantorestoreitfrombackup.Ifyou usethisoption,makesurethatnodataresidesinthecubesthatcannotberecreatedfromthe relationalsource(forexample,dataloadedviatheSQLServerIntegrationServicesAnalysisServices destination).Ofcourse,youshouldalsomakesurethatthecubestructureitselfisavailable,includingall aggregationandpartitiondesignsthathavebeenchangedontheproductionserverfromthestandard deploymentscript. ThisisparticularlytrueforROLAPcubes.Inthiscase(asinallthepreviousscenarios),youshouldalways maintainanupdatedbackupofyourAnalysisServicesprojectthatallowsforaredeploymentofthe solution(withthesubsequentrequiredprocessing),incaseyourbackupmediasuffersanykindof physicalcorruption.
Herearesomeimportantfactorstoconsiderwhenyouworkwithsynchronization: Attheendofthesynchronizationprocess,aWritelockmustbeappliedtothetargetserver.If thislockisqueuedupbehindalongrunningquery,itcanpreventusersfromqueryingthetarget database. Duringsynchronization,areadcommitlockisappliedtothesourceserver,whichpreventsusers fromprocessingnewdatabutallowsmultiplesynchronizationstooccurfromthesamesource server. Forenterprisesizedatabases,thesynchronizationmethodcanbeexpensiveandlow performing.Becausesomeoperationsaresinglethreaded(suchasthedeleteoperation),having highperformanceserversanddisksubsystemsmaynotresultinfastersynchronizationtimes. Becauseofthis,werecommendedthatforenterprisesizedatabasesyouusealternatemethods, suchasRobocopy(discussedlaterinthisbook)orhardwarebasedsolutions(forexample,SAN clonesandsnapshots). Whenexecutingmultiplesynchronizationoperationsagainstasingleserver,youmaygetthe bestperformance(byminimizinglockcontentions)byqueuingupthesynchronizationrequests andthenrunningthemserially. Forthesamelockingcontentionreasons,planyoursynchronizationsfordowntimes,when queryingandprocessingarenotoccurringontheaffectedservers.Whiletherearelocksinplace topreventoverwrites,processessuchaslongrunningqueriesandprocessingmaypreventthe synchronizationfromcompletinginatimelyfashion.
3.4.1.2 Robocopy
ThebasicprinciplebehindtheRobocopymethodistouseafastcopyutility,suchasRobocopy,tocopy theOLAPdatafolderfromoneservertoanother.Byfollowingthesamplescriptnotedinthetechnical note,SampleRobocopyScripttocustomersynchronizeAnalysisServicesdatabases (http://sqlcat.com/technicalnotes/archive/2008/01/17/samplerobocopyscripttocustomer synchronizeanalysisservicesdatabases.aspx),youcanperformdeltacopies(thatis,copyonlythedata thathaschanged)oftheOLAPdatafolderfromonesourcetoanothertargetsourceinparallel.This methodisoftenemployedinenterpriseenvironmentsbecausethekeyfactorhereisfast,robustdata filetransfer. However,thekeydisadvantagesofusingthisapproachinclude: Youmuststopandthenrestart(inSQLServer2005AnalysisServices)ordetach(inSQLServer 2008AnalysisServicesandSQLServer2008R2AnalysisServices)yourAnalysisServicesservers whenyouuseafastcopyutility. YoucannotusethesynchronizationfeatureandRobocopytogether.
149
YoucanusuallyincreasethroughputofProcessDatabytuningthenetworkstackandprocessingmore partitionsinparallel.However,youmaystillbenefitfromtuningtheprocesspool. TooptimizethesesettingsfortheProcessDataphase,checkyourPerformanceMonitorcounteronthe objectMSOLAP:Threadsandusethefollowingtableforguidance. Situation Processingpooljobqueuelength>0and Processingpoolidlethreads=0 forlongerperiodsduringprocessing. BothProcessingpooljobqueuelength>0and Processingpoolidlethreads>0atsametime duringprocessing. Action IncreaseThreadPool\Process\MaxThreadsand thenretest. DecreaseCoordinatorExecutionMode(for example,changeitfrom4to8)andthenretest.
YoucanusetheProcessor%ProcessorTimeTotalcounterasaroughindicatorofhowmuchyou shouldchangethesesettings.Forexample,ifyourCPUloadis50percent,youcandouble ThreadPool\Process\MaxThreadstoseewhetherthisalsodoublesyourCPUusage.Itispossibletoget to100percentCPUloadinasystemwithoutbottlenecks,thoughyoumaywanttoleavesome headroomforgrowth.Keepinmindthatincreasedparallelismofprocessingalsohasaneffecton queriesrunningatthesystem.Ideally,useaseparateprocessingserveroradedicatedprocessingtime windowwherenooneisqueryingAnalysisServices.Ifthisisnotanoption,asyoudedicatemoreCPU powerandthreadstoprocessing,lessCPUwillbeusedforqueryresponses.Becauseprocessing consumesthreadsfromthesamepoolasquerysubcuberequests,youshouldalsobecarefulthatyou dontruntheprocessthreadpooldryifyouprocessandqueryatthesametime.Ifyouareprocessing thecubesduringasetprocessingwindowwithnousersonthebox,thiswillofcoursenotbeanissue. References: SQLServer2005AnalysisServices(SSAS)ServerProperties(http://technet.microsoft.com/en us/library/cc966526.aspx)
3.5.1.1.1 Relational Indexing for Partition Processing Whileyougenerallywanteachcubepartitiontotouchatmostonerelationalpartition,thereverseis nottrue.Itisperfectlyviabletohavetohavemorethanonecubepartitionaccessingthesame relationalpartition.Asanexample,arelationalsourcethatispartitionedbyyearwithacubethatis partitionedbymonthcanstillprovideoptimalprocessingperformance. Ifyoudonothaveaonetoonerelationshipbetweenrelationalandcubepartitions,yougenerallywant anindextosupportthefactprocessingquery.Thebestchoiceofindexforthispurposeisaclustered index;ifyourloadstrategyallowsyoutomaintainsuchanindex,thisiswhatyoushouldaimfor. Whenapartitionprocessingqueryissupportedbyanindextheplanshouldlooklikethis.
3.5.1.1.2 Relational Indexing for Dimension Processing Ifyoufollowadimensionalstarschemadesign(whichwerecommendforlargecubes),mostdimension processingqueriesshouldrunrelativelyfastandtakeonlyatinyportionofthetotalcubeprocessing time.Butifyouhaveverylargedimensionswithmillionsofrowsordimensionswithlotsofattributes, someperformancecanbestillbegainedbyindexingtherelationaldimensiontable.Tounderstandthe bestindexingstrategy,itisusefultoknowwhichformdimensionsprocessingqueriestake.Thenumber ofqueriesgeneratedbyAnalysisServicesdependsontheattributerelationshipsdefinedinthe dimension.Foreachattributeinthedimension,thefollowingqueryisgeneratedduringprocessing. SELECTDISTINCT<attribute>,[<relatedattribute>[n]] FROM<dimensiontable> Considerthefollowingexampledimension,withCustomerIDasthekeyattribute. 152
Country
Name Customer ID
Zip
Thefollowingqueriesaregeneratedduringdimensionprocessing.
SELECTDISTINCT Country FROM Dim.Customer SELECTDISTINCTState, Country FROM Dim.Customer SELECTDISTINCT City,StateFROM Dim.Customer SELECTDISTINCT Zip, City FROM Dim.Customer SELECTDISTINCT Name FROM Dim.Customer SELECTDISTINCT Gender FROM Dim.Customer SELECTDISTINCT Age FROM Dim.Customer SELECTDISTINCT CustomerID, Name, Gender, Age, Zip FROM Dim.Customer
Thiswillcreatethefollowing,optimalqueryplan.
153
Figure 61 - A good key processing plan
Highcardinalityattributes:Forhighcardinalityattributes,likeName,youneedanonclusteredindex. NoticetheDISTINCTintheSELECTquerygeneratedbyAnalysisServices.
SELECTDISTINCT Name FROM Dim.Customer
DISTINCTgenerallyforcestherelationalenginetoperformasorttoremoveduplicatesinthereturned dataset.Thesortoperationresultsinaplanthatlookslikethis.
Ifthisplantakesalongtimetorun,whichcouldbethecaseforlargedimension,considercreatingan indexthathelpsremovethesort.Inthisexample,youcancreatethisindex.
CREATEINDEX IX_Customer_Name ON Dim.Customer(Name)
Thisindexgeneratesthefollowing,muchbetterplan.
154
3.5.1.1.3 Overoptimizing and Wasting Time Itispossibletotunetherelationalenginetocutdowntimeonprocessingsignificantly,especiallyfor partitionprocessingandlargedimensions.However,bearinmindthateverytimeyouaddanindextoa table,youaddonemoredatastructurethatmustbemaintainedwhenusersmodifyrowsinthattable. Relationalindexing,likeaggregationdesigninacubeandmuchofBIanddatawarehousing,istradeoff betweendatamodificationspeedanduserqueryperformance.Thereistypicallyasweetspotinthis spacethatwilldependonyourworkload.Differentpeoplehavedifferentskills,andtheperceptionof wherethatsweetspotlieswillchangewithexperience.Asyougetclosertotheoptimalsolution, increasedthetuningeffortwilloftenreachapointofdiminishingreturnswherethespeedofthesystem movesasymptoticallytowardstheoptimumbalance.Monitoryourowntuningeffortsandtryto understandwhenyouaregettingclosetothatflatlinebehavior.Astemptingasfulltuningexercisescan betothetechnicallysavvy,noteverysystemneedsbenchmarkperformance. 155
3.5.1.1.4 Using Index FILLFACTOR = 100 and Data Compression Ifpagesplittingoccursinanindex,thepagesoftheindexmayenduplessthan100percentfull.The effectisthatSQLServerwillbereadingmoredatabasepagesthannecessarywhenscanningtheindex. YoucancheckforindexpagesarenotfullbyqueryingtheSQLServerDMV sys.dm_db_index_physical_stats.Ifthecolumnavg_page_space_used_in_percentissignificantlylower than100percent,aFILLFACTOR100rebuildoftheindexmaybeinorder.Itisnotalwayspossibleto rebuildtheindexlikethis,butthistrickhastheabilitytoreduceI/O.Forstaledata,rebuildingthe indexesonthetableisoftenagoodideabeforeyoumarkthedataasreadonly. InSQLServer2008youcanuseeitherroworpagecompressiontofurtherreducetheamountofI/O requiredbytherelationaldatabasetoservethefactprocessquery.CompressionhasaCPUoverhead, butreductioninI/Ooperationsisoftenworthit. References: DataCompression:Strategy,CapacityPlanningandBestPractices http://msdn.microsoft.com/enus/library/dd894051%28v=sql.100%29.aspx
3.5.1.1.5 Eliminating Database Locking Overhead WhenSQLServerscansanindexortable,pagelocksareacquiredwhiletherowsarebeingread.This ensuresthatmanyuserscanaccessthetableconcurrently.However,fordatawarehouseworkloads, thispagelevellockingisnotalwaystheoptimalstrategyespeciallywhenlargedataretrievalqueries likefactprocessingaccessthedata. BymeasuringthePerfmoncounterMSSQL:LocksLockRequests/SecandlookingforLCKeventsin sys.dm_os_wait_stats,youcanseehowmuchlockingoverheadyouareincurringduringprocessing. Toeliminatethislockingoverhead,youhavethreeoptions: Option1:SettherelationaldatabaseinReadOnlymodebeforeprocessing. Option2:BuildthefactindexeswithALLOW_PAGE_LOCKS=OFFandALLOW_ROW_LOCKS=OFF. Option3:Processthroughaview,specifyingtheWITH (NOLOCK)orWITH (TABLOCK)queryhint.
IfyouusetheNOLOCKhint,bewareofthedirtyreadsthatcanoccur.Formoreinformationabout lockingbehaviors,seeSETTRANSACTIONISOLATIONLEVEL(http://technet.microsoft.com/en us/library/ms173763.aspx)inSQLServerBooksOnline. 3.5.1.1.6 Forcing Degree of Parallelism in SQL Server DuringProcessData,apartitionprocessingtaskislimitedbythespeedachievablefromasinglenetwork connectionthedatasource.Thesespeedscanvarybetweenafewthousandrowspersecondforlegacy datasources,toaround100,000rowspersecondfromSQLServer.Perhapsthatisnotfastenoughfor you,andyouhavefollowedtheguidanceinthisbooktoallowmultiplepartitionstoprocessinparallel scalingProcessDatanearlylinearly. Wehaveseencustomerreach6.5millionrowspersecondintoacubebyprocessing64partitions concurrently.Bearinmindwhatittakestotransportmillionsofrowsoutofarelationaldatabaseevery second.Eachprocessingquerywillbeselectingdatafromabigtable,aggressivelyfetchingdataasfast asthenetworkstackandI/Osubsystemcandeliverthem.WhenSQLServerreceivesjustasingle requestforallrowsinalargefacttable,itwillspawnmultiplethreadsinsidethedatabaseengineto servethatitasfastaspossibleutilizingallserverresources.ButwhattheDBAoftherelationalengine maynotknow,isthatinafewmilliseconds,yourcubedesignissetuptoaskforanotheroneofthose largetablesconcurrently.Thispresentstherelationalenginewithaproblem:howmanythreadseach queryshouldbeassignedtooptimizethetotalthroughputofthesystem,withoutsacrificingoverall performanceofindividualprocessingcommands.Itiseasytoseethatraceconditionsmaycreateall sortsoninterestingsituationstofurthercomplicatethis.IfparallelismoverloadstheDatabaseEngine, SQLServermustresorttocontextswitchingbetweentheactivetasks,continuouslyredistributingthe scarceCPUresourcesandwastingCPUtimewithscheduling.Youcanmeasurethishappeningasahigh SOS_SCHEDULER_YIELDwaitinsys.dm_os_wait_stats. 157
Fortunately,youcandefendyourselfagainstexcessiveparallelismbyworkingtogetherwiththecube designertounderstandhowmanypartitionsareexpectedtoprocessatthesametime.Youcanthen assignasmallersubsetoftheCPUcoresintherelationaldatabaseforeachpartition.Carefullydesigning forthisparallelismcanhavealargeimpact.Wehaveseencubeprocessdataspeedsmorethandouble whentheassignedCPUresourcesarecarefullycontrolled. Youhaveoneortwowaystopartitionserverresourcesforoptimalprocessdataspeeds,dependingon whichversionofSQLServeryourun. InstancereconfigurationUsingsp_configure,youcanlimitthenumberofCPUresourcesasingle querycanconsume.Forexample,consideracubethatprocesseseightpartitionsinparallelfroma computerrunningSQLServerwith16cores.Todistributetheprocessingtasksequallyacrosscores,you wouldconfigurelikethis.
EXECsp_configure'show advanced options', 1 RECONFIGURE EXECsp_configure'max degree of parallelism', 2 RECONFIGURE
Unfortunately,thisisabruteforceapproach,whichhasthesideeffectofchangingthebehaviorofthe entireinstanceofSQLServer.Itmaynotbeaproblemiftheinstanceisdedicatedforcubeprocessing, butitisstillacrudetechnique.Unfortunately,thisistheonlyoptionavailabletoyouonSQLServer 2005. ResourceGovernorIfyourunSQLServer2008orSQLServer2008R2,youcanuseResourceGovernor tocontrolprocessingqueries.Thisisthemostelegantsolution,becauseitcanoperateoneachdata sourceviewindividually. ThefirststepistocreatearesourcepoolandaworkloadgrouptocontroltheAnalysisServices connections.Forexample,tothefollowingstatementlimitseachProcessDatataskto2CPUcoresanda maximummemorygrantof10percentperquery.
CREATERESOURCEPOOL [cube_process] WITH( min_cpu_percent=0 , max_cpu_percent=100 , min_memory_percent=0 , max_memory_percent=100) GO CREATEWORKLOADGROUP [process_group] WITH( group_max_requests=0 , importance=Medium , request_max_cpu_time_sec=0 , request_max_memory_grant_percent=10 , request_memory_grant_timeout_sec=0 , max_dop=2) USING [cube_process] GO
158
Makesureyoutesttheclassifierfunctionbeforeapplyingitinproduction.Afteryouarecertainthatthe functionworks,enableit.
ALTERRESOURCEGOVERNORWITH (CLASSIFIER_FUNCTION = [dbo].[fnClassifier]); GO ALTERRESOURCEGOVERNORRECONFIGURE;
3.5.1.1.7 Loading from Oracle AnalysisServicesiscommonlydeployedinheterogeneousenvironments,withOraclebeingoneofthe maindatasources.Becausecubesoftenneedtoreadalotofdatafromthesourcesystemduring processing,itisimportantthatyouusehighspeeddriverstoextractthisdata.Wehavefoundthatthe nativeOracledriversprovideareasonableperformance,especiallyifmanypartitionsareprocessedin parallel. However,wehavealsofoundthatdatacanbeextractedfromaSQLServerdatasourceat510times thespeedofthesameOraclesource.TheSQLServerdriverSQLNLCIisoptimizedforveryhigh extractionspeedssometimesreachingupto80,000100,000rowspersecondfromasingleTCP/IP connection,dependingonthesourceschema).WehavetestedprocessingspeedsontopofSQLServer allthewayto6.1millionrowspersecond. ConsiderthatSQLServerIntegrationServices,partofthesameSKUasAnalysisServices,hasahigh speedOracledriveravailablefordownload.Thisdriverisoptimizedforhighspeedextractionfrom
159
Oracle.Wehavefoundthatthefollowingarchitectureoftenprovidesfasterprocessingperformance thanprocessingdirectlyontopofOracle.
3.5.2.1 CoordinatorBuildMaxThreads
Whenasinglepartitionisscanned,theamountofthreadsusedtoscanextentsislimitedbythe CoordinatorBuildMaxThreadssetting.Thesettingdeterminesthemaximumnumberofthreads allocatedperaggregationprocessingjob.Itistheabsolutenumberofthreadsthatcanberunbyan aggregationprocessingjob.Keepinmindthatyouarestilllimitedbythenumberofthreadsinthe processthreadpoolwhenprocessing,soincreasingthisvaluemayrequireincreasingthethreads availabletotheprocessthreadpooltoo.
160
Figure 24 CoordinatorBuildMaxThreads
161
Workerthreadsfromthequerypoolcheckthedataandcalculationcachestoseewhethertherequest canbeservedfromcache.Iftherequestcontainscalculationsthatneedtobehandledbytheformula engine,workerthreadsinthequerypoolareusetoperformthecalculationandstoretheresults.Ifthe queryneedstogotodisktoretrieveaggregationsorscanapartition,workerthreadsfromthe processingpoolareusedtosatisfytherequestandstoretheresultsincache. Therearesettingsinthemsmdsrv.inifilethatallowuserstotunethebehaviorofthethreadpools involvedinqueryworkloads.Guidanceonusingthemisprovidedinthissection. 3.5.3.1.1 Parsing Thread Pools TheAnalysisServicesprotocolusesSimpleObjectAnalysisProtocol(SOAP)andXMLAforAnalysis (XMLA)withTCP/IPorHTTP/HTTPSastheunderlyingtransportmechanism.Afteraclientconnectsto AnalysisServicesandestablishesaconnection,commandsarethenforwardedfromtheconnections inputbufferstooneofthetwoparsingthreadpoolswheretheXMLAparserbeginsparsingtheXMLA whileanalyzingtheSOAPheaderstomaintainthesessionstateofthecommand. Therearetwoparsingthreadpools:theshortcommandparsingpoolandthelongcommandparsing pool.Theshortcommandparsingpoolisusedforcommandsthatcanbeexecutedimmediatelyandthe longcommandparsingpoolisusedforcommandsthatrequiremoresystemresourcesandgenerally takelongertocomplete.Requestslongerthanonepackagearedispatchedtothelongparsingthread pool,andonepackagerequestsgototheshortparsingpool.Ifarequestisaquickcommand,likea DISCOVER,theparsingthreadisusedtoexecuteit.Iftherequestisalargeroperation,likeanMDX queryoranMDSCHEMA_MEMBERS,itisqueueduptothequerythreadpool. FormostAnalysisServicesconfigurationsyoushouldnotmodifyanyofthesettingsintheshortparsing orlongparsingthreadpools.However,withtheinformationprovidedhere,youcanimagineaworkload whereeithertheshortparsingorlongparsingthreadpoolsrundry.Wehaveonlyseenonesuch workload,atveryhighconcurrency,soitisunlikelythatyouwillneedtotunetheparsingthreadpool.If youdohaveaproblemwithonetheparsingthreadpools,itwillshowupasvaluesconsistentlyhigher thanzeroinMSOLAP/ThreadShortparsingjobqueuelengthorMSOLAP/ThreadLongparsingjob queuelength. 3.5.3.1.2 Query Thread Pool Settings AlthoughmodifyingtheThreadPool\Process\MaxThreadsandThreadPool\Query\MaxThreads propertiescanincreaseparallelismduringquerying,youmustalsotakeintoaccounttheadditional impactofCoordinatorExecutionModeasdescribedintheconfigurationsection. Inpracticalterms,thebalancingofjobsandthreadscanbetricky.Ifyouwanttoincreaseparallelism,it isimportanttofirstnarrowdownparallelismasthebottleneck.Tohelpyoudeterminewhetherthisis thecase,itishelpfultomonitorthefollowingperformancecounters: Threads\QuerypooljobqueuelengthThenumberofjobsinthequeueofthequerythread pool.Anonzerovaluemeansthatthenumberofqueryjobshasexceededthenumberof availablequerythreads.Inthisscenario,youmayconsiderincreasingthenumberofquery
162
3.5.3.2 Aggregations
Aggregationsbehaveverymuchlikeindexesinarelationaldatabase.Theyarephysicaldatastructures thatareusedtoanswerfrequentlyaskedqueriesinthedatabase.Addingaggregationstoacube enablesyoutospeeduptheoverallthroughput,atthecostofmorediskspaceandincreasedprocessing times. Notethatjustaswithrelationalindexing,noteverysingle,potentiallyhelpfulaggregateshouldbe created.Whenthespaceofpotentialaggregatesgrowslarge,oneaggregatebeingreadmaypush anotheroutofmemoryandcasediskthrashing.AnalysisServicesmayalsostruggletofindthebest aggregateamongmanymatchingagivenquery. Agoodruleofthumbisthatnomeasuregroupshouldhavemorethan30percentofitsstoragespace dedicatedtoaggregates.Todiscoverwhichaggregatesaremostuseful,youshouldcollectthequery subcubeverboseeventusingSQLServerProfilerwhilerunningarepresentativeworkload.Bysumming theruntimeofeachuniquesubcubeyoucangetagoodoverviewofthemostvaluableaggregationsto create.Formoreinformationabouthowtocreateaggregates,seePart1. Therearesomeaggregatesthatyougenerallyalwayswanttocreate,namelytheonesthatareused directlybysetsdefinedinthecalculationscript.Youcanidentifythosebytracingqueriesgoingtothe cubeafteraprocessevent.Thefirstusertorunaqueryorconnecttothecubeafteraprocessingevent maytriggerquerysubcubeverboseeventsthathaveSPID=0thisisthecalculationscriptitself requestingdatatoinstantiateanynamedsetsdefinedthere. References:
163
AnalysisServices2005AggregationDesignStrategy http://sqlcat.com/technicalnotes/archive/2007/09/11/analysisservices2005aggregation designstrategy.aspx o AlsoappliestoSQLServer2008AnalysisServicesandSQLServer2008R2Analysis Services AggregationManageronCodePlex http://bidshelper.codeplex.com/wikipage?title=Aggregation%20Manager&referringTitle=Home o Makesthetaskofdesigningaggregationseasier BIDSHelperhttp://bidshelper.codeplex o Assistswithmanycommontasks,includingaggregationdesign
Notethattherearemanyotheroptimizationsthatcanbedoneondimensions.Part1ofthisbook containsmoredetailedinformation.
3.5.3.5 Repartitioning
Partitioningofcubescanbeusedtobothincreaseprocessingandqueryspeeds.Forexample,ifyou strugglewithprocessdataspeeds,splittingupthenightlybatchintomultiplepartitionscanincrease concurrencyoftheprocessingoperation.ThistechniqueisdocumentedinPart1ofthisbook. PartitionscanalsobeusedtoselectivelymovedatatodifferentI/Osubsystems.Anexampleofthisisa customerthatkeepsthelatestdatainthecubeonNANDdevicesandmovesoldandinfrequently accesseddatatoSATAdisks.YoucanmovepartitionaroundusingSQLServerManagementStudiointhe propertiespaneofthepartition.Alternatively,youcanuseXMLorscriptingtomovepartitiondataby executingaquerylikethis.
<AlterObjectExpansion="ExpandFull" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID>Adventure Works DW</DatabaseID> <CubeID>Adventure Works DW</CubeID> <MeasureGroupID>Fact Reseller Sales</MeasureGroupID> <PartitionID>Reseller_Sales_2001</PartitionID> </Object> <ObjectDefinition> <Partition> <ID>Reseller_Sales_2001</ID> <Name>Reseller_Sales_2001</Name> <StorageLocation>D:\MSAS10_50.KILIMANJARO\OLAP\2001\</StorageLocation> </Partition> </ObjectDefinition> </Alter>
165
Process
Process
Asia 200911
US 200901
Europe 200901
Asia 200901
US 2008
Europe 2008
Asia 2008
YearlyPartitiong MonthsMergedat yearend
US 2007
Europe 2007
Asia 2007
RegionPartitioning
Process
andgivesyouoptionsforextendingthematrixpartitioningstrategyappropriately.Thefollowingtable containsexamplesofsuchpartitioningkeys. Industry WebRetail StoreRetail DataHosting Telecommunications Computerized manufacturing InvestmentBanking RetailBanking OnlineGaming Examplepartitionkey Customerkey Storekey HostIDorracklocation SwitchIDorcountrycodeor areacode ProductionLineIDorMachine ID StockExchangeorfinancial instrument CreditCardNumberor CustomerKey GameKeyorPlayerKey Sourceofdataproliferation Addingcustomersandtransactions Addingnewstores Addinganewserver Expandingintonewgeographical regionsoraddingnewservices Addingproductionlinesor(for machines)sensors Addingnewfinancialinstruments, products,ormarkets Increasingcustomertransactions Addingnewgamesorplayers
Sometimesitisnotpossibletocomeupwithagooddistributionofthekeysacrossthepartitions. Perhapsyoujustdonthaveagoodkeycandidatethatfitsthedescriptioninthepreviousparagraph,or perhapsthedistributionofthekeyisunknownatdesigntime.Insuchcases,abruteforceapproachcan beused:Partitiononthehashvalueofakeythathasahighenoughcardinalityandwherethereislittle skew.Userswillhavetotouchallthehashbucketsastheyquerythecube,butatleastyoucanperform parallelloading.Ifyouexpecteveryquerytotouchmanypartitions,itisimportantthatyoupayspecial attentiontotheCoordinatorQueryBalancingFactordescribedearlier. Asyouaddmorepartitions,themetadataoverheadofmanagingthecubegrowsexponentially.Asarule ofthumb,youshouldthereforeseektokeepthenumberofpartitionsinthecubeinthelowthousands. ThisaffectsProcessUpdateandProcessAddoperationsondimensions,whichhavetotraversethe metadatadependenciestoupdatethecubewhendimensionschange.Forlargecubes,preferlarger partitionsovercreatingtoomanypartitions.ThisalsomeansthatyoucansafelyignoretheAnalysis ManagementObjectswarning(AMO)inVisualStudiothatpartitionsizesshouldnotexceed20million rows.Wehavemeasuredtheeffectoflargepartitionsizes,andfoundthattheyshownegligible performancedifferencescomparedtosmallerpartitionsizes.Therefore,thereductioninpartition managementoverheadjustifiesrelaxingtheguidelinesonpartitionsizes,particularlywhenyouhave largenumbersofpartitions. 3.5.3.5.1 Adding and Managing Partitions Managingpartitionsonalargecubequicklybecomesalargeadministrativetaskifdonemanually throughSQLServerManagementStudio.Werecommendthatyoucreatescriptstohelpyoumanage partitioningofthecubeinanautomatedmannerinstead. Thebestwaytomanagealargecubeistousearelationaldatabasetoholdthemetadataaboutthe desiredpartitioningschemeofthecubeanduseXMLAtokeepthecubestructureinsyncwiththe 167
metadataintherelationalsource.Everytimeyourequestmetadatafromacube,youhavetoruna DISCOVERcommandsomeofthesecommandsareexpensiveonalargecubewithmanypartitions. Youshoulddesignpartitionmanagementcodetoextractthemetadatafromthecubeinasinglebulk operationinsteadofmultiplesmallDISCOVERcommands.NotethatwhenyouuseAMO(andtheSQL ServerIntegrationServicestask)toaccessthecube,someamountoferrorhandlingisbuiltintothe.NET library.ThiserrorhandlingcodeexecutesDISCOVERcommandsandbequitechattywiththeserver.A goodexampleofthisisthepartitionaddfunctioninAMO.Thiscodewillfirstchecktoseewhetherthe partitionalreadyexists(itraisesanerrorifitdoes)usingaDISCOVERcommand.Afterthatitwillissue theCREATEcommand,creatingthepartitioninthecube.Thistechniqueturnsouttobeahighly inefficientwaytoaddmanynewpartitionsoncubewiththousandsofexistingpartitions.Instead,itis fastertofirstreadallthepartitionsusingasingleXMLAcommand,discoverwhichpartitionsaremissing ,andthenrunanXMLAcommandtocreateeachmissingpartitiondirectlyavoidingtheerrorchecking thatAMO.NETdoes. Insummary,designpartitionmanagementcodecarefullyandtestitusingSQLServerProfilertotrace thecommandsyougenerateasthecoderuns.Becauseitprovidessomuchfeedbacktotheserver, partitionmanagementcodeisveryexpensive,anditisoftensurprisingtocustomershoweasyitisto createinefficientoperationsonabigcube.ThatisthepriceofthesafetynetthatADOMD.NETgives you.UsingXMLAtocarefullymanagepartitionsisoftenabettersolutionforalargecube.
(suchasLOCK_NONE,LOCK_SESSION_LOCK,LOCK_ABORTABLE,LOCK_INPROGRESS,LOCK_INVALID)are usedperipherallyashelperfunctionsforconcurrencymanagement.Becausetheyareperipheraltothis discussion,thissectionfocusesonthemainlocktypesinstead. Thefollowingtableliststheselocksandbrieflydescribeshowtheyareused. Locktype Read Object All Usage Readlocksareusedforreadingmetadataobjects,ensuringthat theseobjectscannotbemodifiedwhiletheyarebeingused. Readlocksareshared,meaningthatmultipletransactionscantake Readlocksonthesameobject. Writelocksareusedforcreate,alter,andupdateoperations. Writelocksareexclusive.Exclusivelockspreventconcurrent transactionsfromtakingReadorWritelocksontheobjectatthe sametime. Commit_Readlocksareshared,buttheyblockwriteoperations thatarewaitingtocommitchangestodisk. DatabaseObjects:Commit_Readlocksareusedforthefollowing: Queryoperationstoensurethatnocommittransactions overwriteanyofthemetadataobjectsusedinthequery. Thelockisheldforthedurationofaquery. Duringprocessing,whileacquiringReadandWritelockson otherobjects. Atthebeginningofasessiontocalculateuserpermissions foragivendatabase. Duringsomediscoveroperations,suchasthosethatread fromadatabaseobject. ServerObjects:Commit_Readlocksareusedatthebeginningofa sessiontocomputesessionsecurity.Commit_Readisalsousedat thestartofatransactiontoreadthemasterversionmap. ServerProxyObjects:Commit_Readlocksareusedatthe beginningofSQL,DMX,andMDXqueriestopreventchangesto assembliesoradministrativerolewhiletheobjectsareretrieved. Commit_Writelocksareexclusivelocksonanobject,takento preventaccesstothatobjectwhileitisbeingupdated. Commit_Writeistheprimarymechanismforensuringoneversion ofthetruthforqueries.
Write
All
Commit_Read
Commit_Write
169
DatabaseObjects:ACommit_Writeisusedinacommittransaction thatcreates,updates,ordeletesDDLstructuresinthedatabase.In acommittransaction,Commit_Writelockscanbetakenon multipledatabasesatthesametime,assumingthetransaction includesthem(forexample,deletingmultipledatabasesinone transaction). ServerObject:ACommit_Writeisusedtoupdatethemaster versionmap.Moreinformationaboutthemasterversionmapisin thenextsectiononserverlocks. ServerProxyObject:ACommit_Writeistakenwheneverthereare changestoassembliesormembershipoftheserverrole.
TheServerobjecttakesacommitlockforoperationssuchasprocessingorqueryingthattraversethe objecthierarchy.Typically,commitlocksontheserverareverybrief,takenprimarilywheneverthe serverreadsthemasterversionmap(Master.vmp)fileorupdatesitsothatitcontainsnewerversionsof objectschangedbyatransaction. Themasterversionmapisalistofobjectidentifiersandcurrentversionnumberforallofthemajor objectsrecognizedbytheserver(thatis,Database,Cube,MeasureGroups,Partitions,Dimensionsand Assemblies).Minorobjects,suchashierarchylevelsorattributes,donotappearinthelist.Themaster versionmapidentifieswhichobjectversiontouseatthestartofaqueryorprocess.Theversionnumber ofamajorobjectchangeseachtimeyouprocessorupdateit.OnlytheServerobjectreadsandwritesto theMaster.vmpfile. Whenreadingthemasterversionmap,theservertakesaCommit_Readtoprotectagainstchangesto thefilewhileitisbeingread.ACommit_WriteistakenontheServerobjecttoupdatethemaster versionmap,bymergingnewerversioninformationthatwascreatedinatransaction. 170
TheServerProxyobjectisusedforadministrativelocks,forexamplewhenyoumakechangestothe membershipoftheServerroleortoassembliesusedbythedatabase.
171
Figure 68 - Locks during partition processing
Otheroperationssuchaslazyprocessing,sessions,andproactivecachingposeinterestingchallengesin termsofunderstandinglocks.Thereasonisdiscussedattheendofthissection,buttheseother operationsarenotdiscussedindetail.Alsomissingfromthelistiswriteback,Becausewritebackisa hybridofqueryandprocessoperations,whicharecoveredindividually. 3.5.4.4.1 Begin Session Whenasessionstarts,AnalysisServicesdetermineswhichdatabasestheuserhaspermissiontouse. PerformingthistaskrequirestakingaCommit_Readlockonthedatabase.Ifadatabaseisnotspecified, sessionsecurityiscomputedforeachdatabaseontheserveruntiladatabaseisfoundthatthesession hasreadaccessto.Locksarereleasedaftersessionsecurityiscomputed.Occasionally,thecommitlock isacquiredandreleasedsoquicklythatitnevershowsupinatrace. 3.5.4.4.2 Queries Allqueriesrunonadatabaseandinasession.ACommit_Readlockistakensimultaneouslyonthe ServerProxyobjectanddatabasewhenthequerystarts.Thelockisheldforthedurationofthequery. TheCommit_Readlockonadatabaseheldbyqueryissometimesblocksprocessingoperations.
172
Figure 69 - Write locks blocking queries
Intheprecedingexample,thelongrunningquerypreventstheCommit_Writelockrequiredbythe processingoperation(yellowarrow)frombeingtaken.NewreadersrequiringtheCommit_Readlockon thedatabasethenbecomeblockedbehindtheprocessingcommand.Itisthiscombinationofevents thatcanturnathreesecondqueryintoathreeminute(orlonger)query. 3.5.4.4.3 Discovers Therearetwotypesofdiscoveroperationsthatuselocks:thosethatrequestmetadataaboutinstances orobjects(suchasMDSCHEMA_CUBE),andthosethatarepartofadynamicmanagementview(DMV) query. TheDiscovermethodonmetadataobjectsbehavesverysimilarlytoaqueryinthatittakesa Commit_Readlockonthedatabase. DiscoversissuedforDMVoperationsdonttakeReadlocks.Instead,DMVsuseinterlockingmethodsto synchronizeaccesstosystemdatathatiscreatedandmaintainedbytheserver.Thisapproachis sufficientbecauseDMVdiscoversdonotreadfromthedatabasestructure.Assuch,theprotection offeredbylocksisoverkill.ConsiderDISCOVER_OBJECT_MEMORY_USAGE.ItisaDMVquerythat returnsshrinkableandunshrinkablememoryusedbyallobjectsontheserveratgivenpointintime. Becauseitisafastreadofsystemdatadirectlyontheserver,DISCOVER_OBJECT_MEMORY_USAGEuses interlockedaccessovermemoryobjectstoretrievethisinformation. 3.5.4.4.4 Processing Forprocessing,locksareacquiredintwophases,firstduringobjectacquisitionandagainduring scheduleprocessing.Afterthesefirsttwophases,thedatacanbeprocessedandthechanges committed. Phase1:ObjectAcquisition 1. ACommit_Readlockisacquiredonthedatabasewhiletheobjectsareretrieved. 2. Theobjectsusedinprocessingarelookedup. 3. Theobjectsareidentified,andthentheCommit_Readlockonthedatabaseisreleased. Phase2:ScheduleProcessing Thisphasefindstheobjectsonwhichthedimensionorpartitiondepends,aswellasthoseobjectsthat dependonit.Inpractice,buildingthescheduleisaniterativeprocesstoensurethatallofthe dependenciesareidentified.Afterallofthedependenciesareunderstood,theexecutionworkflow 173
2. ScheduleracquiresaCommit_Readonthedatabase,andthenitacquiresReadandWritelocks ontheobjects. 3. Schedulergeneratesthejobsandisnowfreetostartexecutingthejobs. Phase3:Process Afterscheduling,therearenoCommit_Readlocks,justWritelocksontheaffectedobjects,andread locksonobjects.OnlyReadandWritelocksareusedtodothework.ReadandWritelockspreventother transactionsfromupdatinganyobjectsusedinthetransaction.Atthesametime,objectsthatare relatedbutnotincludedinthecurrenttransactioncanbeupdated.Forexample,supposetwodifferent dimensionsarebeingprocessedinparallel.Ifeachdimensionisreferencedbydifferentcubesandif eachdimensionisfullyindependentoftheother,thereisnoconflictwhenthetransactioniscommitted. HadaCommit_Writelockbeenheldonthedatabase,thistypeofparallelprocessingwouldnotbe possible. Phase4:Commit WhenaCommittransactionstarts,aCommit_Writelockistakenonthedatabaseandheldforthe durationofthetransaction.NonewCommit_ReadlocksareacceptedwhileCommit_Writeispending. AnynewBeginSessionsmayencounteraconnectiontimeout.Newqueriesarequeuedorcanceled, dependingontimeoutsettings. TheCommittransactionwaitsforthequeryqueuetodrain(thatis,itwaitsforCommit_Readlockstobe released).Atthispoint,readingfromthepropertysettingsdefinedontheserver,itmightuseoneofthe followingpropertiestocancelaqueryifitistakingtoolong: 174
ForceCommitTimeoutcancelstransactionsthatholdCommit_Readlocks.Bydefault,this propertyissetto30seconds.However,itisimportanttorememberthatcancelationsarenot alwaysinstantaneous.Sometimesittakesseveralminutestoreleasecommitlocks. CommitTimeoutcancelstransactionsrequestingCommit_Writelocks,ineffectprioritizing queriesoverprocessing.Theserveruseswhichevertimeoutoccursfirst.If ForceCommitTimeoutoccurssoonerthanCommitTimeout,cancelationiscalledonlong runningqueriesinsteadofthewriteoperation. Note:Iftheclientapplicationhasitsownretrylogic,itcanreissueacommandinresponsetoa connectiontimeoutandtheconnectionwillsucceedifthereareavailablethreads. AcommittransactionalsotakesaCommit_Writelockontheserver.Thisisveryshortandoccurswhen thetransactionversionmapismergedintothemasterversionmapthatkeepstrackofwhichobject versionsarethemasterversions.BecausethisisaWritelock,itmustwaitforReadlockstoclearthis waittimeiscontrolledbyForceCommitTimeoutandCommitTimeout.Acommittransactioncreates newversionsofthemasterobjects,ensuringconsistentresultsforallqueries. AftertheMaster.vmpfileisupdated,theserverdeletesunusedversiondatafiles.Atthispoint,the Commit_Writelockisreleased. 3.5.4.4.5 DDL Operations Foroperationsthatcreate,alter,ordeletemetadataobjects,locksareacquiredonce.Itissimilartothe processingworkflowbutwithouttheschedulingphase.Itfindstheobjectsthattheobjectdependson andlocksthemusingReadlocks,andWritelocksaretakenontheobjectsthatdependontheobject thatisbeingmodified.Writelocksarealsoacquiredontheobjectsthatarecreated,updated,ordeleted inthetransaction. 3.5.4.4.6 Rollback Forrollback,thereisaserverlatchthatprotectsMaster.vmp,butarollbackbyitselfdoesnottakea Commit_ReadorCommit_Writelockonthedatabase.Inarollback,nothingischanging,sonocommit locksarerequired.However,anyReadandWritelocksthatweretakenbythetransactionarestillheld duringtherollback,buttheyarereleasedaftertherollbackhasbeencompleted.Rollbackdeletesthe unusedversionsofanyobjectscreatedbytheoriginaltransaction. 3.5.4.4.7 Session Transactions, Proactive Caching, and Lazy Processing Intermsoflocking,sessions,proactivecachingandlazyprocessingaretrickybecausetheyhave breakablelocks.Pendingawriteoperationfromanadministrator,LockManagercancelsWritelocksina session,proactivecaching,orlazyprocessing,anditletstheWriteCommitprevail. SessionscanhaveWritelocksthatdontconflict.Snapshotsandcheckpointsareusedtomanagewrite operationsforsessioncubes.TheclassicexampleisthegroupingbehaviorinExcelwherenew dimensionsarecreatedinsession,onthefly,tosupportadhocdatastructures.Thenewdimensions arealwaysrolledbackeventually,buttheycanbeproblematicduringtheirlifetime.Ifanerroroccursin
175
session,theservermightperformapartialrollbacktoachieveastablestate;sometimestheserollback operationshaveunintendedconsequences. 3.5.4.4.8 Synchronization, Backup and Restore, and Attach Thelockingmechanismforsynchronization,restore,andattacharealreadydocumentedintheAnalysis ServicesSynchronizationBestPracticesarticleontheSQLCATwebsite(http://sqlcat.com).Restated fromthatarticle,thebasicworkflowoflockacquisitionandreleaseforsynchronizationisasfollows. Duringsynchronization,aWritelockisappliedbeforethemergeofthefilesonthetargetserver,anda readcommitlockisappliedtothesourcedatabasewhilefilesaretransferred. TheWritelockisappliedonthetargetserver(whenatargetdatabaseexists),preventingusers fromqueryingand/orwritingindatabase.Thelockisreleasedfromthetargetdatabaseafter themetadataisvalidated,themergehasbeenperformedandthetransactioniscommitted. Thereadcommitlockistakenonthesourceservertopreventprocessingfromcommittingnew data,butitallowsqueriestorun,includingothersourcesynchronization.Becauseofthis, multipleserverscanbesynchronizedatthesametimefromthesamesource.Thelockis releasedataboutthesamemomentastheWritelock,asitistakeninthisdistributed transaction.
Forsynchronizationonly,thereisalsoanadditionalCommit_Writelockwhilethedatabasesaremerged. Thislockcanbeheldforalongperiodoftimewhilethedatabaseiscreatedandoverwritten. Forbackup,thereisonlyaCommit_Readonthedatabase. Arestoreoperationusesamorecomplexseriesoflocks.ItacquiresaWritelockonthedatabasethatis beingrestored,ensuringtheintegrityofthedatabaseasitsbeingrestored,butblockingquerieswhile Restoreisbeingprocessed.Bestpracticerecommendationssuggestusingtwodatabaseswithdifferent namessothatyoucanminimizequerydowntime. Thebasicworkflowforalloftheseoperationsisasfollows: 1. Writelocksaretakenonthedatabasethatisbeingsynchronized,restored,orattached. 2. Filesareextractedandchangescommittedwhileprocessing. 3. Thelocksarereleased.
otherendofthespectrum,blockingcanbecomesoseverethatusersarelockedoutofthesystem. Connectionrequestsfail;querieseithertimeoutorfailtostartaltogether. Intheseextremescenarios,itisdifficulttoclearlydiagnosetheproblemifyoudonothaveanavailable threadtoconnectSQLServerProfilerorifyouareunabletorunaDMVquerythattellsyouwhatis goingon.Inthiscase,theonlywaytoconfirmalockingproblemistoworkwithaMicrosoftsupport engineertoanalyzeamemorydump.Theengineercantellyouwhetheryourserverunavailabilityisdue tolocks,indicatedbyPCLockManager::Waitonmultiplethreads. 3.5.4.5.1 Using DMV Queries and XMLA to Cancel a Blocked Transaction Ifyoursituationislessdire,youcanuseaDMVqueryandXMLforAnalysis(XMLA)tounblockyour server.Givenafreethreadforprocessinganewconnectionrequest,youcanconnecttotheserverusing anadministratoraccount,runaDMVquerytogetthelistoflocks,andthentrytokilltheblockingSPID byrunningthisXMLAcommand.
<Cancel xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <SPID>nnnn</SPID> </Cancel>
TogettheSPID,youcanuseSQLServerManagementStudiotoconnecttotheserverandthenissuea DISCOVER_LOCKSstatementasanMDXquery.
Select * from $SYSTEM.DISCOVER_LOCKS
Unfortunately,thereisnomitigationforthis.YoucannotrunDISCOVER_LOCKSinconjunctionwith otherDMVstatementstogetadditionalinsightintothetimingofthelockacquisitionreleaselifecycle
177
relativetothetransactionsrunningonyourserver.YoucanonlyruntheMDXSELECTstatementand thenactontheinformationitprovides. 3.5.4.5.2 Using SQL Server Profiler to Analyze Lock Contention SQLServerProfileroffersnumerousadvantagesoverDMVqueriesintermsofdepthandbreadthof information,butitcomesatacost.ItisoftennotfeasibletorunSQLServerProfilerinaproduction environmentbecauseoftheadditionalresourcedemandsitplacesonserver.Butifyoucanuseit,andif youarerunningSQLServer2008R2SP1,youcanaddthenewLockAcquired,LockReleased,andLock Waitingeventstoatracetounderstandthelockingactivityonyourserver. SQLServer2008R2SP1addsthefollowingeventstotheLockseventcategoryinSQLServerProfiler: LockAcquired,LockReleased,LockWaiting. Likeotherlockevents,theyarenotenabledbydefault.YoumustselecttheShowallcolumnscheckbox beforeyoucanselecteventsintheLockscategory.Togetanideaofhowlocksareacquiredand releasedinthecourseofatransactionbesuretoaddCommandBeginandCommandEndtothetrace.If youwanttoviewtheMDXexecuted,youshouldalsoincludetheQueryBeginandQueryEnd. InAnalysisServices,itisnormaltoseealargenumberofacquiredandreleasedlockevents.Every transactionthatincludesReadorWriteoperationsonamajorobjectrequestsalocktoperformthat action.LockWaitingislesscommon,butbyitselfisnotsymptomaticofaproblem.Itmerelyindicates thataqueuehasformedfortransactionsthatarerequestingthesameobject.Ifthequeueisnotlong andoperationscompletequickly,thequeuedrainsandqueryorprocessingtasksproceedwithonlya smalldelay. ThefollowingillustrationshowsaLockWaitingeventandtheXMLstructuresthatidentifywhich transactioncurrentlyholdsalockontheobject,andwhichtransactionsarewaitingforthatsameobject. Intheillustration: <HoldList>showswhichtransactioniscurrentlyholdingaCommit_Writelockonthedatabase. <WaitList>indicatesthatanothertransactioniswaitingforaCommit_Writelockonthesame database.
178
Figure 31 SQL Server Profiler output of lock events
3.5.4.6 Deadlocks
AdeadlockinAnalysisServicesislockcontentionbetweentwoormoresessions,whereoperationsin eithersessioncantmoveforwardbecauseeachiswaitingtoacquirealockheldbytheothersession. AnalysisServiceshasdeadlockdetectionbutitonlyworksforlocks(Read,Write,Commit_Read, Commit_Write).Itwontdetectdeadlocksforlatches.Whenadeadlockisdetected,AnalysisServices stopsthetransactioninoneofthesessionssothattheothertransactioncancomplete. Deadlocksaretypicallyaboundarycase.Ifyoucanreproduceit,youcanrunaSQLServerProfilertrace andusetheDeadlockeventtodeterminethepointofcontention.InSQLServerProfiler,adeadlock lookslikethefollowing:
179
Figure 71 - Deadlock events in profiler
180
<Lock> <LOCK_OBJECT_ID><Object><DatabaseID>FoodMart 2008</DatabaseID><DimensionID>Promotion</DimensionID></Object></LOCK_OBJECT_ID> <LOCK_ID>7F15875F-4CCB-4717-AE11-5F8DD48229D0</LOCK_ID> <LOCK_TRANSACTION_ID>1D3C42F3-E875-409E-96A0-B4911355675D</LOCK_TRANSACTION_ID> <SPID>29924</SPID> <LOCK_TYPE>4</LOCK_TYPE> ---- Lock_Write <LOCK_STATUS>0</LOCK_STATUS> ---- waiting on Promotion, which is locked by 29945 </Lock> <Lock><LOCK_OBJECT_ID><Object><DatabaseID>FoodMart 2008</DatabaseID><DimensionID>Product</DimensionID></Object></LOCK_OBJECT_ID> <LOCK_ID>96B09D08-F0AE-4FD2-8703-D33CAD6B90F1</LOCK_ID> <LOCK_TRANSACTION_ID>1D3C42F3-E875-409E-96A0-B4911355675D</LOCK_TRANSACTION_ID> <SPID>29924</SPID> <LOCK_TYPE>4</LOCK_TYPE> ---- Lock_Write <LOCK_STATUS>1</LOCK_STATUS> ---- granted </Lock>< /LOCKS> </DeadlockGraph>
Deadlocksshouldberareevents,iftheyoccuratall.Persistentdeadlocksindicateaneedforredesigning yourprocessingstrategy.Youmightneedtospeedupprocessingbymakinggreateruseofpartitions,or youmightneedtotakeacloserlookatotherprocessingoptionsorschedulestoseewhetheryoucan eliminatetheconflict.Formoreinformationabouttheserecommendations,seePart1ofthisbookor theAnalysisServicesPerformanceGuide (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=3be0488de7aa4078a050 ae39912d2e43&displaylang=en). References: AnalysisServicesSynchronizationBestPractices http://sqlcat.com/technicalnotes/archive/2008/03/16/analysisservicessynchronizationbest practices.aspx DeadlockTroubleshootinginSQLServerAnalysisServices(SSAS) http://blogs.msdn.com/b/sql_pfe_blog/archive/2009/08/27/deadlocktroubleshootinginsql serveranalysisservicesssas.aspx SSAS:Processing,ForceCommitTimeoutand"theoperationhasbeencancelled" http://geekswithblogs.net/darrengosbell/archive/2007/04/24/SSASProcessing ForceCommitTimeoutandquottheoperationhasbeencancelledquot.aspx LockingandUnlockingDatabases(XMLA)http://msdn.microsoft.com/en us/library/ms186690.aspx
181
Thethreearchitectureshavedifferenttradeoffsthatyouhavetoconsider,whichthissectiondescribes. Note:Itisalsopossibletocombinethesearchitecturesindifferenthybrids,butthatisoutsidethescope ofthisdocument.Understandingthetradeoffsforeachwillhelpyoumaketherightdesigndecisions. 3.5.5.2.1 Dedicated Processing Architecture Inthededicatedprocessingarchitecture,aninstanceofAnalysisServicesisreservedtoprocessallnew, incomingdata.Afterprocessingisdone,theresultiscopiedtoqueryservers.Theadvantageofthis architectureisthatthequeryserverscanrespondtothequerieswithoutbeingaffectedbythe processingoperation.Alockisrequiredonlywhendataisupdatedoraddedtothecube. 182
NetworkandLoadBalancer
Query InstanceA
Query InstanceB
Query InstanceC
Co py
Inadedicatedprocessingarchitecture,considerhowtogetthedatafromtheprocessinginstancetothe queryservers.Thereareseveralwaystoachievethis. AnalysisServicesCubeSynchronization:ByusingthisbuiltinAnalysisServicesfunctionality,youcan movethedeltadatadirectlytothequeryservers. RobocopyorNiceCopy:Byusingahighspeedcopyingprogram,youcanquicklysynchronizeeachquery instancewithitsowncopyofthechangeddata.Thismethodisgenerallyfasterthancube synchronization,butitrequiresyoutosetupyourowncopyscripts. SANSnapshotsorStorageMirrors:UsingSANtechnology,itispossibletoautomaticallymaintaincopies ofthedataLUNontheprocessingservers.Thesecopiescanthenbemountedonthequeryservers whenthedataisupdated. SANReadOnlyLUN:Usingthistechnique,whichisavailableonlyinSQLServer2008andSQLServer 2008R2,youcanusereadonlyLUNtomovethedatafromtheprocessinginstancetothequeryservers. AreadonlyLUNcanbesharedbetweenmultipleservers,andhenceenablesyoutousemorethan queryserveronthesamephysicaldisk. BothSANsnapshotsandreadonlyLUNstrategiesmayrequirecarefuldesignofthestoragesystem bandwidth.Ifyourcubeissmallenoughtofitinmemory,youwillnotseemuchI/Oactivityandthis 183
py Co
Process
Processing Instance
SourceData
techniquewillworkverywelloutofthebox.However,ifthecubeislargeandcannotfitinmemory, AnalysisServiceswillhavetodoI/Ooperations.Asyouaddmoreandmorequeryserverstothesame SAN,youmayendupcreatingabottleneckinthestorageprocessorsontheSANtoserveallthisI/O. YoushouldmakesurethattheSANiscapableofsupportingtherequiredthroughput.IftheI/O throughputisnotsufficient,youmayendupwithascaleoutsolutionthatperformsworsethanascale up. IfyouareworriedaboutI/Obandwidth,theRobocopy/NiceCopysolutionorthecubesynchronization solutionmayworkbetterforyou.Inthesesolutionsyoucanhavededicatedstorageoneachquery server.However,youhavetomakesurethereisenoughbandwidthonthenetworktorunmultiple copiesoverthenetwork.Youmayhavetousededicatednetworkcardsforsuchasetup. Thededicatedprocessingarchitecturescanalsobeusedtoachievehighavailability.However,youneed awaytoprotecttheprocessingserver,toavoidasinglepointoffailure.Youcanhaveeitherastandby processingserveroranextra(disabled)instanceononeofthequeryserversthatcanbeusedtotake overtheroleofprocessingserviceinthecaseofhardwarefailure.Anotheralternativeistouse clusteringontheprocessingserver,althoughthismaywastehardwareresourcesonthepassivenode. References: ScaleOutQueryingforAnalysisServiceswithReadOnlyDatabases http://sqlcat.com/whitepapers/archive/2010/06/08/scaleoutqueryingforanalysisservices withreadonlydatabases.aspx SampleRobocopyScripttoSynchronizeAnalysisServicesDatabases http://sqlcat.com/technicalnotes/archive/2008/01/17/samplerobocopyscripttocustomer synchronizeanalysisservicesdatabases.aspx ScaleOutQueryingwithAnalysisServices http://sqlcat.com/whitepapers/archive/2007/12/16/scaleoutqueryingwithanalysis services.aspx ScaleOutQueryingwithAnalysisServicesUsingSANSnapshots http://sqlcat.com/whitepapers/archive/2007/11/19/scaleoutqueryingwithanalysisservices usingsansnapshots.aspx AnalysisServicesSynchronizationBestPractices http://sqlcat.com/technicalnotes/archive/2008/03/16/analysisservicessynchronizationbest practices.aspx SQLVelocityScalableSharedDatabase http://sqlvelocity.typepad.com/blog/2010/09/scalableshareddatabasepart1.html
servers.Inthequery/processingflippingarchitecture,eachinstanceofAnalysisServicesperformsits ownprocessing,asillustratedinthefollowingfigure.
Process
Pr oc es s
s es oc Pr
185
Thequery/processingflippingarchitecturealsohasabuildinhighavailabilitysolution.Ifoneofthe serversfails,thesystemcanremainonlinebutwithadditionalloadontherestoftheservers.
186
3.5.5.3.3 Windows Network Load Balancing TheMicrosoftloadbalancingsolutionisNetworkLoadBalancing(NLB),whichisafeatureofthe WindowsServeroperatingsystem.WithNLB,youcancreateanNLBclusterofAnalysisServicesservers runninginmultiplehostmode.WhenanNLBclusterofAnalysisServicesserversisrunninginmultiple hostmode,incomingrequestsareloadbalancedamongtheAnalysisServicesservers. 3.5.5.3.4 Analysis Services Load Balancer AnalysisServicesisusedextensivelyinsideMicrosofttoserveourbusinessuserswithdata.Aspartof theinitiativetoscaleoutourAnalysisServicesfarmsanewloadbalancingsolutionwasbuilt.The advantagesofthissolutionarethatyoucanloadbalanceonthedatabaselevelandthatyouuseaweb APItocontroleachdatabaseandtheusersconnectedtoit.ThiscustomizedAnalysisServicesload balancingsolutionalsoallowsfinecontrolovertheloadbalancingalgorithmused.Beawarethatmoving largedatasetsoverthewebAPIhasabandwidthoverhead,dependingonhowmuchdataisrequested byuserqueries.Measurethisbandwidthoverheadaspartofthecubetestphase. References: AnalysisServicesLoadBalancingSolution http://sqlcat.com/technicalnotes/archive/2010/02/08/aslbsetup.aspx
187
188
189
Figure 75 - Recycling the event log
190
191
192
MDXcalculations ROLAPdimensions
193
YoushouldworkcloselywiththeBIdeveloperswhentroubleshootingROLAPcubes.Itisimperativeto getthedesignrightandfollowtheguidanceinPart1ofthisbook. References: AnalysisServicesParentChildDimensionNaturalizeronCodePlex http://pcdimnaturalize.codeplex.com/ o AlsoavailablefromBIDShelper:http://bidshelper.codeplex.com AnalysisServicesManytoManyDimensions:QueryPerformanceOptimizationTechniques http://www.microsoft.com/downloads/en/details.aspx?FamilyID=3494E712C90B4A4EAD45 01009C15C665&displaylang=en AnalysisServicesROLAPforSQLServerDataWarehouses http://sqlcat.com/whitepapers/archive/2010/08/23/analysisservicesrolapforsqlserverdata warehouses.aspx
194
195
Figure 76 - Setting the Data Source to Snapshot
Second,enableMARSintheconnectionstringofthedatasourceview.
Andfinally,enableeithersnapshotorreadcommittedsnapshotisolationintheSQLServerdatabase.
ALTERDATABASE [Database] SETREAD_COMMITTED_SNAPSHOTON
Youcanstillapplyadatebasedpartitionschemainadditiontothedistinctcountpartitioning.Butifyou do,makesurethatqueriesdonotcrossthegranularitylevelofthisdaterange,oryoulosepartofthe optimization.Forexample,ifyoudonothavequeriesacrossyears,youmaybenefitbypartitioningby bothyearandthedistinctcountmeasure.Conversely,ifyouhavequeriesthataskfordataattheyear level,youshouldnotpartitionbymonthandthedistinctcountmeasure. ThewhitepaperintheReferencessectiondescribesthepartitionstrategyfordistinctcountmeasuresin muchmoredetail. References: AnalysisServicesDistinctCountOptimization http://www.microsoft.com/downloads/en/details.aspx?FamilyID=65df6ebf9d1c405f84b1 08f492af52dd&displaylang=en o DescribesthepartitionstrategythatspeedsupqueriesandprocessingforDistinctCount Measuregroups
198
Ifyourpartitioncontainsalargeamountofrows,orderingthedatacantakealongtime.Without supportingindexes,thequeryplanlookssomethinglikethis.
Ofcourse,thisindexneedstobemaintained.Buthavingitinplacespeedsuptheprocessingqueries.
199
Manytomanyprojecthttp://www.sqlbi.com/manytomany.aspx o Designpatternsformanytomanydimensions
4 Conclusion
This document provides guidance for creating and maintaining Analysis Services cubes that run in a production environment. In Part 1, you learned best practices for developing cubes and dimensions that are fast to process and query. Part 2 explored performance tuning from the standpoint of cubes that are already in production and not easily modified. For more information, see: http://sqlcat.com/:SQLCustomerAdvisoryTeam http://www.microsoft.com/sqlserver/:SQLServerWebsite http://technet.microsoft.com/enus/sqlserver/:SQLServerTechCenter http://msdn.microsoft.com/enus/sqlserver/:SQLServerDevCenter If you have any suggestions or comments, please do not hesitate to contact the authors. You can reach Thomas Kejser at tkejser@microsoft.com and Denny Lee at dennyl@microsoft.com. Did this paper help you? Please give us your feedback. Tell us on a scale of 1 (poor) to 5 (excellent), how would you rate this paper and why have you given it this rating? For example: Are you rating it high due to having good examples, excellent screen shots, clear writing, or another reason? Are you rating it low due to poor examples, fuzzy screen shots, or unclear writing?
This feedback will help us improve the quality of white papers we release. Sendfeedback.
200