java JDBC 外文翻译 外文文献 英文文献.docx

上传人:b****7 文档编号:26042150 上传时间:2023-06-17 格式:DOCX 页数:25 大小:53.89KB
下载 相关 举报
java JDBC 外文翻译 外文文献 英文文献.docx_第1页
第1页 / 共25页
java JDBC 外文翻译 外文文献 英文文献.docx_第2页
第2页 / 共25页
java JDBC 外文翻译 外文文献 英文文献.docx_第3页
第3页 / 共25页
java JDBC 外文翻译 外文文献 英文文献.docx_第4页
第4页 / 共25页
java JDBC 外文翻译 外文文献 英文文献.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

java JDBC 外文翻译 外文文献 英文文献.docx

《java JDBC 外文翻译 外文文献 英文文献.docx》由会员分享,可在线阅读,更多相关《java JDBC 外文翻译 外文文献 英文文献.docx(25页珍藏版)》请在冰豆网上搜索。

java JDBC 外文翻译 外文文献 英文文献.docx

javaJDBC外文翻译外文文献英文文献

javaJDBC外文翻译外文文献英文文献

原文一:

JavaProgrammingwithOracleJDBC:

Performance

Performanceisusuallyconsideredanissueattheendofadevelopmentcyclewhenitshouldreallybeconsideredfromthestart.Often,ataskcalled"performancetuning"isdoneafterthecodingiscomplete,andtheenduserofaprogramcomplainsabouthowlongittakestheprogramtocompleteaparticulartask.Thenetresultofwaitinguntiltheendofthedevelopmentcycletoconsiderperformanceincludestheexpenseoftheadditionaltimerequiredtorecodeaprogramtoimproveitsperformance.It'smyopinionthatperformanceissomethingthatisbestconsideredatthestartofaproject.

WhenitcomestoperformanceissuesconcerningJDBCprogrammingtherearetwomajorfactorstoconsider.ThefirstistheperformanceofthedatabasestructureandtheSQLstatementsusedagainstit.ThesecondistherelativeefficiencyofthedifferentwaysyoucanusetheJDBCinterfacestomanipulateadatabase.

Intermsofthedatabase'sefficiency,youcanusetheEXPLAINPLANfacilitytoexplainhowthedatabase'soptimizerplanstoexecuteyourSQLstatements.Armedwiththisknowledge,youmaydeterminethatadditionalindexesareneeded,orthatyourequireanalternativemeansofselectingthedatayoudesire.

Ontheotherhand,whenitcomestousingJDBC,youneedtoknowaheadoftimetherelativestrengthsandweaknessesofusingauto-commit,SQL92syntax,andaStatementversusaPreparedStatementversusaCallableStatementobject.Inthischapter,we'llexaminetherelativeperformanceofvariousJDBCobjectsusingexampleprogramsthatreporttheamountoftimeittakestoaccomplishagiventask.We'llfirstlookatauto-commit.Next,we'lllookattheimpactoftheSQL92syntaxparser.Thenwe'llstartaseriesofcomparisonsoftheStatementobjectversusthePreparedStatementobjectversustheCallableStatementobject.Atthesametimewe'llalsoexaminetheperformanceoftheOCIversustheThindriverineachsituationtoseeif,asOracle'sclaims,thereisasignificantenoughperformancegainwiththeOCIdriverthatyoushoulduseitinsteadoftheThindriver.Forthemostpart,ourdiscussionswillbebasedontimingdatafor1,000insertsintothetestperformancetableTESTXXXPERF.Thereareseparateprogramsforperformingthese1,000insertsusingtheOCIdriverandtheThindriver.

Theperformancetestprogramsthemselvesareverysimpleandareavailableonlinewiththerestoftheexamplesinthisbook.However,forbrevity,I'llnotshowthecodefortheexamplesinthischapter.I'llonlytalkaboutthem.Althoughtheactualtimingvalues

changefromsystemtosystem,theirrelativevalues,orratiosfromonesystemtoanother,remainconsistent.ThetimingsusedinthischapterweregatheredusingWindows2000.Usingobjectivedatafromtheseprogramsallowsustocometofactualconclusionsonwhichfactorsimproveperformance,ratherthanrelyingonhearsay.

I'msureyou'llbesurprisedattherealityofperformancefortheseobjects,andIhopeyou'llusethisknowledgetoyouradvantage.Let'sgetstartedwithalookatthetestingframeworkusedinthischapter.

ATestingFramework

Forthemostpart,thetestprogramsinthischapterreportthetimingsforinsertingdataintoatable.IpickedanINSERTstatementbecauseiteliminatestheperformancegainofthedatabaseblockbuffersthatmayskewtimingsforanUPDATE,DELETE,orSELECT.

Thetesttableusedintheexampleprogramsinthischapterisasimplerelationaltable.IwantedittohaveaNUMBER,asmallVARCHAR2,alargeVARCHAR2,andaDATEcolumn.TableTESTXXXPERFisdefinedas:

createtableTestXXXPerf(

idnumber,

codevarchar2(30),

descrvarchar2(80),

insert_uservarchar2(30),

insert_datedate)

tablespaceuserspctfree20

storage(initial1Mnext1Mpctincrease0);

altertableTestXXXPerf

addconstraintTestXXXPerf_Pk

primarykey(id)

usingindex

tablespaceuserspctfree20

storage(initial1Mnext1Mpctincrease0);

Theinitialextentsizeusedforthetablemakesitunlikelythatthedatabasewillneedtotakethetimetoallocateanotherextentduringtheexecutionofoneofthetestprograms.Therefore,extentallocationwillnotimpactthetimings.Giventhisbackground,youshouldhaveacontexttounderstandwhatisdoneineachsectionbyeachtestprogram.Auto-Commit

Bydefault,JDBC'sauto-commitfeatureison,whichmeansthateachSQLstatementiscommittedasitisexecuted.IfmorethanoneSQLstatementisexecutedbyyour

program,thenasmallperformanceincreasecanbeachievedbyturningoffauto-commit.

Let'stakealookatsomenumbers.Table19-1showstheaveragetime,inmilliseconds,neededtoinsert1,000rowsintotheTESTXXXPERFtableusingaStatementobject.Thetimingsrepresenttheaveragefromthreerunsoftheprogram.Bothdriversexperienceapproximatelyaone-secondlossasoverheadforcommittingbetweeneachSQLstatement.Whenyoudividethatonesecondby1,000inserts,youcanseethatturningoffauto-commitsavesapproximately0.001seconds(1millisecond)perSQLstatement.Whilethat'snotinterestingenoughtowritehomeabout,itdoesdemonstratehowauto-commitcanimpactperformance.

Table19-1:

Auto-committimings(inmilliseconds)

Auto-commitOCIThin

On3,7123,675

Off2,6132,594

Clearly,it'smoreimportanttoturnoffauto-commitformanagingmultisteptransactionsthanforgainingperformance.Butonaheavilyloadedsystemwheremanyusersarecommittingtransactions,theamountoftimeittakestoperformcommitscanbecomequitesignificant.Somyrecommendationistoturnoffauto-commitandmanageyourtransactionsmanually.Therestofthetestsinthischapterareperformedwithauto-committurnedoff.

SQL92TokenParsing

Likeauto-commit,SQL92escapesyntaxtokenparsingisonbydefault.Incaseyoudon'trecall,SQL92tokenparsingallowsyoutoembedSQL92escapesyntaxinyourSQLstatements(see"OracleandSQL92EscapeSyntax"inChapter9).Thesestandards-basedsnippetsofsyntaxareparsedbyaJDBCdrivertransformingtheSQLstatementintoitsnativesyntaxforthetargetdatabase.SQL92escapesyntaxallowsyoutomakeyourcodemoreportable--butdoesthisportabilitycomewithacostintermsofperformance?

Table19-2showsthenumberofmillisecondsneededtoinsert1,000rowsintotheTESTXXXPERFtable.TimingsareshownwiththeSQL92escapesyntaxparseronandoffforboththeOCIandThindrivers.Asbefore,thesetimingsrepresenttheresultofthreeprogramrunsaveragedtogether.

Table19-2:

SQL92tokenparsertimings(inmilliseconds)

SQL92parserOCIThin

On2,5672,514

Off2,7442,550

NoticefromTable19-2thatwiththeOCIdriverwelose177millisecondswhenescapesyntaxparsingisturnedoff,andweloseonly37millisecondswhentheparseristurnedoffwiththeThindriver.Theseresultsaretheoppositeofwhatyoumightintuitivelyexpect.ItappearsthatbothdrivershavebeenoptimizedforSQL92parsing,soyoushouldleaveitonforbestperformance.

NowthatyouknowyouneverhavetoworryaboutturningtheSQL92parseroff,let'smoveontosomethingthathassomepotentialforprovidingasubstantialperformanceimprovement.

StatementVersusPreparedStatement

There'sapopularbeliefthatusingaPreparedStatementobjectisfasterthanusingaStatementobject.Afterall,apreparedstatementhastoverifyitsmetadataagainstthedatabaseonlyonce,whileastatementhastodoiteverytime.Sohowcoulditbeanyotherway?

Well,thetruthofthematteristhatittakesabout65iterationsofapreparedstatementbeforeitstotaltimeforexecutioncatchesupwithastatement.WhenitcomestowhichSQLstatementobjectperformsbetterundertypicaluse,aStatementora

PreparedStatement,thetruthisthattheStatementobjectyieldsthebestperformance.WhenyouconsiderhowSQLstatementsaretypicallyusedinanapplication--1or2here,maybe10-20(rarelymore)pertransaction--yourealizethataStatementobjectwillperformtheminlesstimethanaPreparedStatementobject.Inthenexttwosections,we'lllookatthisperformanceissuewithrespecttoboththeOCIdriverandtheThindriver.TheOCIDriver

Table19-3showsthetimingsinmillisecondsfor1insertand1,000insertsintheTESTXXXPERFtable.TheinsertsaredonefirstusingaStatementobjectandthenaPreparedStatementobject.Ifyoulookattheresultsfor1,000inserts,youmaythinkthatapreparedstatementperformsbetter.Afterall,at1,000inserts,thePreparedStatementobjectisalmosttwiceasfastastheStatementobject,butifyouexamineFigure19-1,you'llseeadifferentstory.

Table19-3:

OCIdrivertimings(inmilliseconds)

InsertsStatementPreparedStatement

110113

1,0002,8041,412

Figure19-1isagraphofthetimingsneededtoinsertvaryingnumbersofrowsusingbothaStatementobjectandaPreparedStatementobject.Thenumberofinsertsbeginsat1andclimbsinintervalsof10uptoamaximumof150inserts.Forthisgraphandforthose

thatfollow,thelinesthemselvesarepolynomialtrendlineswithafactorof2.Ichosepolynomiallinesinsteadofstraighttrendlinessoyoucanbetterseeachangeintheperformanceasthenumberofinsertsincreases.Ichoseafactorof2sothelineshaveonlyonecurveinthem.Theimportantthingtonoticeaboutthegraphisthatit'snotuntilabout65insertsthatthePreparedStatementobjectoutperformstheStatementobject.65inserts!

Clearly,theStatementobjectismoreefficientundertypicalusewhenusingtheOCIdriver.

Figure19-1

TheThinDriver

IfyouexamineTable19-4(whichshowsthesametimingsasforTable19-3,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1