外文翻译---改进ADO.NET性能.doc
附录1.英文资料ImprovingADO.NETPerformanceImproving.NETApplicationperformanceandscalabilitySummary:Thischapterprovidesprovenstrategiestohelpyoudesignanddevelopscalabledataaccesssolutions.Topicscoveredincludedifferenttechniquestopassdataacrossapplicationlayers,managingthedatabaseconnectionpool,optimizingstoredprocedurecalls,reducingdatasetserializationcost,techniquesforpagingthroughlargeresultsets,managingtransactions,handlingBLOBS,andmuchmore.ObjectivesOptimizeyourdataaccessdesign.ChoosebetweenDataSetsandDataReaders.Runefficientdatabasecommands.Passdatabetweenlayersefficiently.Performefficienttransactions.Optimizeconnectionmanagement.Evaluatethecostofpagingthroughrecords.Evaluatecriteriaforanalyzingdataaccessperformance.Applyperformanceconsiderationstobinarylargeobject(BLOB)manipulation.OverviewWell-designeddataaccesscodeanddataprocessingcommandsareessentialelementsforapplicationperformanceandscalability.Typically,thedatabaseisafocalpointforapplicationloadbecausethemajorityofapplicationrequestsrequiredatathatcomesfromadatabase.Thischapterprovidesprovenstrategiesfordesigningandimplementingdataaccesscodeforperformanceandscalability.HowtoUseThisChapterUsethischaptertoimprovetheimplementationofyourdataaccesscodeforperformanceandscalability.Togetthemostoutofthischapter,considerthefollowing:Jumptotopicsorreadbeginningtoend.Themainheadingsinthischapterhelpyoutoquicklyidentifyandthenlocatethetopicthatinterestsyou.Alternatively,youcanreadthechapterbeginningtoendtogainathoroughappreciationoftheissuesthataffectADO.NETperformance.Usethechecklist.Use"Checklist:ADO.NETPerformance"inthe"Checklists"sectionofthisguidetoquicklyviewandevaluatetheguidelinespresentedinthischapter.Usethe"Architecture"sectionofthischaptertounderstandhowADO.NETworks.Byunderstandingthearchitecture,youcanmakebetterdesignandimplementationchoices.UnderstandcoreADO.NETcomponents,suchasdataproviderobjectsandtheDataSetobject.Usethe"DesignConsiderations"sectionofthischaptertounderstandthehigh-leveldecisionsthatwillaffectimplementationchoicesforADO.NETcode.Measureyourapplicationperformance.learnaboutthekeymetricsthatyoucanusetomeasureapplicationperformance.Youhavetomeasureapplicationperformancesothatyoucanidentifyandresolveperformanceissues.Testyourapplicationperformance."Testing.NETApplicationPerformance"tolearnhowtoapplyperformancetestingtoyourapplication.Youhavetoapplyacoherenttestingprocessandanalyzetheresults.Tuneyourapplicationperformance."Tuning.NETApplicationPerformance"tolearnhowtoresolveperformanceissuesthatyouidentifythroughtheuseoftuningmetrics.TuneSQLServer.ReadChapter14,"ImprovingSQLServerPerformance"toensurethatyourMicrosoft®SQLServerdatabaseisappropriatelyconfigured.ArchitectureADO.NETreliesondataproviderstoprovideaccesstotheunderlyingdatasource.Eachdataproviderexposesasetofobjectsthatyouusetomanageconnections,retrievedata,andupdatedata.Thecoreobjectsarethefollowing:ConnectionCommandDataReaderDataAdapterInaddition,ADO.NETprovidestheDataSetobject,whichprovidesadisconnectedcacheofdata.TheDataSetobjectdoesnotrequireaspecifictypeofdatasourceandisnottiedtotheunderlyingdatasourcethatthedatawasobtainedfrom.ThebasicADO.NETarchitectureisshowninFigure12.1.Figure12.1:ADO.NETarchitectureThefollowinglistoutlinesthepurposeofeachofthemainADO.NETobjects:Connection.Thisobjectrepresentsaconnectiontoadatabase.Command.ThisobjectrepresentsanSQLstatementthatisrunwhileconnectedtoadatasource.ThisobjectcanbeastoredprocedureoradirectSQLstatement.DataReader.Thisobjectretrievesaread-only,forward-onlystreamofdatafromadatabase.TheDataReaderobjectisdesignedforconnectedscenariosandoffersbetterperformancethanreadingdataintoaDataSetobjectattheexpenseoffunctionality.FormoreinformationabouthowtouseDataReaderobjectsandDataSetobjects,see"DataSetvs.DataReader"laterinthischapter.DataAdapter.ThisobjectchannelsdatatoandfromaDataSetobjectandtheunderlyingdatasource.TheDataAdapterobjectalsoprovidesenhancedbatchupdatefeaturesthatwerepreviouslyassociatedwiththeADORecordsetobject.DataSet.TheDataSetobjectrepresentsadisconnected,cachedsetofdata.TheDataSetisindependentoftheproviderandisnottiedtotheunderlyingdatasourcethatmighthavebeenusedtopopulateit.DataSetcaneasilybepassedfromcomponenttocomponentthroughthevariouslayersofanapplication,anditcanbeserializedasXML.YoushouldbeawareofthewayaDataSetisinternallyconstructedbecausetheDataSetcontainsapotentiallylargenumberofinternalobjects.ThismeansthatalargenumberofmemoryallocationsarerequiredtoconstructatypicalDataSet.ADataSetconsistsofoneormoreDataTableobjectstogetherwithDataRelationobjectsthatmaintaintablerelationshipinformation.EachDataTablecontainsDataRowobjectsandDataColumnobjects.ConstraintobjectsareusedtorepresentaconstraintthatcanbeenforcedononeormoreDataColumnobjects.NoteYoucanalsousetypeddatasetsthatderivefromthebasicDataSetclass.Typeddatasetsprovidebenefitsatbuildtimeandatruntime.Formoreinformation,see"TypedDataSets"laterinthischapter.DataView.AlthoughtheDataViewobjectisnotshowninFigure12.1,youcanuseaDataViewtosortandfilterdatainaDataTable.Thiscapabilityisoftenusedfordatabinding.AbstractingDataAccessADO.NETisdesignedaroundasetofgenericinterfacesthatabstracttheunderlyingdataprocessingfunctionality.Youcanusetheseinterfacesdirectlytoabstractyourdataaccesslayersothatyoucanminimizetheimpactofchangingthetypeofdatasourcethatyouuse.Abstractingdataaccessisextremelyhelpfulwhenyouaredesigningsystemswhereyourcustomerchoosesthedatabaseserver.ThecoreinterfacesprovidedbyADO.NETarefoundintheSystem.Datanamespace:IDbConnection.Thisisaninterfaceformanagingdatabaseconnections.IDbCommand.ThisisaninterfaceforrunningSQLcommands.IDbTransaction.Thisisaninterfaceformanagingtransactions.IDataReader.Thisisaninterfaceforreadingdatareturnedbyacommand.IDataAdapter.Thisisaninterfaceforchannelingdatatoandfromdatasets.Thevariousproviderobjects,suchasSqlConnectionandOleDbConnection,implementthesegenericADO.NETdataaccessinterfaces.Ifyoudecidetoprogramagainstthegenericinterfaces,beawareofthefollowingissues:Thereissomesmallcostassociatedwithavirtualcallthroughaninterface.Certainexpandedfunctionalityislostwhenyouusethegenericinterfaces.Forexample,theExecuteXmlReadermethodisimplementedbytheSqlCommandobjectbutnotbytheIDbCommandinterface.Thereisnogenericbaseexceptiontype,soyoumustcatchprovider-specificexceptiontypes,suchasSqlException,OleDbException,orOdbcException.Whenyouusethegenericinterfaces,youcannottakeadvantageofdatabase-specifictypesthataredefinedforthemanagedproviders;forexample,youcannottakeadvantageofSqlDbTypeinSqlClientandOracle-specifictypesintheOracleprovider.Usingspecificdatabasetypesishelpfulfortypecheckingandparameterbinding.PerformanceandScalabilityIssues