Vous êtes sur la page 1sur 14

Servin' It Up

Improving ASP Application Performance


J.D. Meier Microsoft Corporation March 28, 2000 Contents Introduction ASP Pa e Perfor!ance Co!ponent Perfor!ance Data Access Perfor!ance IIS Settin s Stress "estin Conc#usion

Introduction
Deve#opers often as$ ho% to et !ore perfor!ance out of their ASP app#ications. &ecause I fre'uent#( revie% Active Server Pa es )ASP* app#ications for perfor!ance, I fi ured I'd share the set of 'uestions I as$ to identif( pro+#e!s and reco!!end i!prove!ents. So!e of these tips !a( see! #i$e co!!on sense, %hi#e others !a( +e #ess o+vious, ho%ever, a## of the reco!!endations are +ac$ed +( rea# %or#d e-perience.

ASP Page Performance


Are you storing Visual Basic objects in Session or Application scope? .isua# &asic/ and other Sin #e0"hreaded Apart!ent )S"A* o+1ects shou#d +e used on#( at pa e scope. Storin S"As in a Session varia+#e #oc$s the o+1ect do%n to the thread that created the o+1ect, defeatin the purpose of a thread poo#. Storin an S"A in App#ication scope seria#i2es access for a## users. See the fo##o%in artic#es for !ore infor!ation on this issue3 Don &o-'s 4ASP and C5M Apart!ents4 6http377%%%.deve#op.co!7d+o-7aspapt.asp8 92:;<:; 4I=>53 Do =ot Store S"A 5+1ects in Session or App#ication4 6http377support.!icrosoft.co!7support7$+7artic#es792:;7<7:;.asp8 92:;<:8 4I=>53 Desi n ?uide#ines for .isua# &asic Co!ponents Under ASP4 6http377support.!icrosoft.co!7support7$+7artic#es792:;7<7:8.asp8 92:;8@< 4PA&3 Storin S"A C5M Co!ponent in Session Boc$s to Sin #e "hread4 6http377support.!icrosoft.co!7support7$+7artic#es792:;787@<.asp8

Are you storing the Scripting. ictionary in Session or Application scope? "he Scriptin .Dictionar( is Apart!ent threaded and shou#d +e used on#( at pa e scope, or (our app#ication %i## suffer serious seria#i2ation issues )see 9@C:80; 4PA&3

Scriptin .Dictionar( 5+1ect >ai#s in ASP App#ication Scope4 6http377support.!icrosoft.co!7support7$+7artic#es79@C:7870;.asp8* "his #i!itation usua##( raises the 'uestion of %hat dictionaries can +e used at Session or App#ication scope. 5ptions are so!e%hat #i!ited, +ut inc#ude the Co!!erce Dictionar( and the Boo$up"a+#e 5+1ect. See 4A+rid in the Dictionar( 5+1ect3 "he ASP "ea! Creates a Boo$up0"a+#e 5+1ect.4 6http377!sdn.!icrosoft.co!7%or$shop7!ana e!ent7p#annin 7MSD=chronic#es2.ht!8 Are your ASP scripts hundreds of lines long? Script is interpreted #ine +( #ine, so e#i!inatin redundant script or creatin !ore efficient script can i!prove perfor!ance. If (ou have hundreds of #ines of ASP script in a sin #e pa e, perhaps (ou can +etter partition (our user, +usiness, and data services. ASP script is reat for atherin input or for!attin output, +ut %hen it co!es to +usiness and data services, co!ponents offer so!e additiona# +enefits 00 such as ear#( +indin and protection of inte##ectua# propert(. In his artic#e 4Co!ponent vs. Co!ponent Part II,4 Jason "a(#or discusses si nificant perfor!ance ains he found portin his ASP script to custo! co!ponents, usin Dindo%s Script Co!ponents )DSC* as an inter!ediate step. If (ou aren't usin co!ponents, (ou can sti## partition (our services %ith functions. >or e-a!p#e, if (our script is renderin severa# ta+#es, !a$e a eneric function to enerate (our ta+#es. Eou can then put these functions into inc#udes, or #a( the round%or$ for a future port to co!ponents. "he fo##o%in sa!p#e i##ustrates usin functions and inc#udes for i!proved !aintenance.
<!-- #include file="Header.asp" --> <!-- #include file="Footer.asp" --> <script language="vbscript" runat="server"> Sub Main( !riteHeader !rite"od# !riteFooter $nd Sub Sub !rite"od#( ... $nd Sub Main <&script> %call sub Main

Are your !include files too big? "here are no hard and fast ru#es for inc#ude0fi#e si2es, +ut $no%in ho% inc#udes %or$ can he#p (ou au e %hether (ou are usin the! efficient#(. Dhen ASP processes inc#udes, it reads the entire fi#e into !e!or(. &ecause ASP %i## cache the entire e-panded code )(our pa e F the inc#ude*, not 1ust the functions (ou ca##, (ou !a( end up %ith #ar e, inefficient na!espaces that ASP !ust search %hen ca##in !ethods or #oo$in up varia+#es. =ote that this process occurs for each pa e that uses the inc#ude. A ood uide is to create fine0 rained inc#udes, so that (ou can +e !ore se#ective a+out %hich

pa es %i## inc#ude the!. >or a !ore detai#ed e-p#anation of ho% ASP processes inc#udes, see 4"he I!p#ications of ASP Ginc#ude.4 Are you using global variables? ?#o+a# varia+#es increase the na!espace used +( ASP to retrieve va#ues fro! !e!or(. .aria+#es dec#ared %ithin su+routines or functions are faster. >or !ore infor!ation, see 42<F ASP "ips to I!prove Perfor!ance and St(#e.4 6http377!sdn.!icrosoft.co!7%or$shop7server7asp7asptips.ht!8 oes your script e"cessively intersperse ASP and #$%&? Heep +#oc$s of ASP server0side script to ether, rather than s%itchin +ac$ and forth +et%een server0side and c#ient0side code. "his s%itchin usua##( happens %hen concatenatin I"MB %ith si!p#e va#ues fro! ASP, as %hen (ou are %ritin out an I"MB ta+#e3
<' For i(tr = ) to )* '> <+,><+->(ounting ... <'= i(tr '><&+-><&+,> <' .e/t '>

Eou can i!prove the code's +( !a$in it a sin #e script +#oc$3


<' For i(tr = ) to )* ,esponse.!rite "<tr><td>(ounting " 0 i(tr 0 "<&td><&tr>" .e/t '>

"his techni'ue has sho%n !easura+#e and si nificant perfor!ance i!prove!ents. Are you buffering output? &ufferin is on +( defau#t in Dindo%s 2000, +ut !a( +e off if (ou've up raded fro! Internet Infor!ation Server )IIS* :.0. Dhen +ufferin is on, ASP %i## %ait unti# processin is co!p#ete +efore sendin do%n the response, reducin net%or$ roundtrips and server0processin de#a(s. Dhen +ufferin is off, ASP %aits for "CP ac$no%#ed e!ents fro! c#ients, %hich can rea##( hurt perfor!ance, particu#ar#( over s#o% connections. =ote that %hi#e +ufferin !a( i!prove throu hput, it !a( reduce perceived perfor!ance. If perceived perfor!ance is an issue, (ou can turn off +ufferin %ith 'esponse.Buffer ( )alse or (ou can ca## 'esponse.)lush. Are you using Session state? ASP Sessions are a convenient faci#it(, +ut the( #i!it sca#a+i#it(. Sessions #i!it the sca#a+i#it( of a sin #e +o- +ecause the( consu!e resources for each user. Dhi#e Session si2e is #ar e#( deter!ined +( %hat (ou stuff into the Session varia+#e, the rea# cost is resource contention. Sessions a#so #i!it (our app#ication's a+i#it( to sca#e out across !u#tip#e !achines, +ecause each Session is De+0server specific. In !an( cases, (ou can avoid the use of Session o+1ects +( usin hidden for! fie#ds or passin data in (our 9uer(Strin s )see 9@J<@KJ 4I5D"53 Persistin .a#ues Dithout Sessions4 6http377support.!icrosoft.co!7support7$+7artic#es79@J<7@7KJ.asp8*. "hese approaches %i## a##o% (ou to sca#e out +ut !a( +eco!e !ore difficu#t to code as the structure of the data ro%s in co!p#e-it(.

Another possi+i#it( is to use a data+ase. "his is suita+#e for !ore co!p#e- structures, such as a shoppin cart. Eou can store (our shoppin cart in a data+ase and #oo$ it up as re'uired. Man( #ar e co!!erce sites ta$e this approach +( trans!ittin a uni'ue ID to the user and #oo$in up infor!ation fro! the data+ase %hen needed. "his approach %i## a##o% (ou to sca#e out transparent#(. It %i## a#so #et (our De+ servers sca#e to !ore users, and it %i## !a$e the carts persistent +et%een re'uests. Man( deve#opers over#oo$ this approach, +ecause the( +e#ieve the cost of reconnectin to the data+ase %i## hurt perfor!ance, +ut that's %here poo#in co!es into p#a( )!ore on poo#in +e#o%*. #ave you disabled Session state if you aren*t using it? If the app#ication doesn't re#( on Sessions, disa+#e Session state for the De+ or virtua# director( throu h the ISM )Internet Services Mana er*. Disa+#in Session state a##o%s ASP to s$ip an e-tensive a!ount of source code, reducin overhead. If (ou need Session state ena+#ed for (ou site, (ou can prevent ASP fro! unnecessari#( chec$in for Session infor!ation on specific pa es +( usin the fo##o%in pa e dec#arative3
1$nableSessionState = False22

Eou !i ht do this on pa es that use fra!es. ASP seria#i2es concurrent re'uests fro! the sa!e session, causin ASP pa es in fra!es to #oad se'uentia##(. If (ou turn off Sessions %ith LMna+#eSessionState, fra!es %i## #oad concurrent#(. Are you using third+party components designed for ASP? As$ (our third0part( co!ponent vendor %hether the co!ponent %as +oth desi ned and tested for ASP. 4"rou+#eshootin Co!ponents Under ASP "echno#o (4 6http377!sdn.!icrosoft.co!7%or$shop7server7asp7server@02<CC.ht!8 provides so!e uide#ines for ASP co!p#iance. Are you using some form of caching for data? Cachin is one of the !ost difficu#t aspects of De+ app#ication deve#op!ent, +ecause it threatens the sca#a+i#it( of (our app#ication. Deter!inin %hat to cache is +ased on data vo#ati#it( and scope. Data that is static or used app#ication0%ide can +e a ood candidate for cachin . Data that chan es fre'uent#( or is user0specific %ou#d not +e a ood candidate. Deter!inin %here in (our app#ication (ou shou#d cache (our data is +ased on (our app#ication oa#s, and (ou need to $no% the trade0offs. >or e-a!p#e, cachin an ActiveN/ Data 5+1ects )AD5* Aecordset offers f#e-i+i#it(, +ecause (ou can sti## ra+ an arra( or save the recordset as NMB. Io%ever, if (our app#ication %i## +e renderin the sa!e I"MB repeated#(, such as to disp#a( a #ist +o- of countries, (ou !i ht cache the I"MB strin in App#ication scope, rather than 1ust the data. NMB has certain#( opened up ne% doors in ter!s of cachin f#e-i+i#it(. >or e-a!p#e, (ou !i ht store data as NMB strin s and app#( NSB transfor!ation as re'uired. >or a !ore thorou h investi ation of this topic, see Pau# Mnfie#d's artic#e 4Usin Server0Side NSB for Mar#( Aenderin 3 ?eneratin >re'uent#( Accessed Data0Driven De+ Pa es in Advance.4 6http377!sdn.!icrosoft.co!7!sdn!a 7issues70:007ear#(rend7ear#(rend.ht!8 A ood stress test ear#( in (our desi n can he#p (ou deter!ine %hich cachin techni'ue

to use. Are you using C ,? If (ou're usin Dindo%s ="/ :.0, use CD50="S and =" SP < or #ater )see 92@:K8< N>5A3 CD5="S =ot "hread0Safe, Crashes Under Stress*. Co##a+oration Data 5+1ects )CD5* %as not tested for server0side use, e-cept in the case of 5ut#oo$ De+ Access. In Dindo%s 2000, use 4CD5 for Dindo%s 2000, CD5SES.d##, %hen possi+#e, %hich is desi ned for server0side deve#op!ent. See the fo##o%in artic#es3 4Co##a+oration Data 5+1ects Aoad!ap4 6#i+rar(7techart7cdoOroad!ap.ht!8 9@C<K8; 4I=>53 Ae#ationship +et%een @.- CD5 Bi+raries and CD5SES.DBB4 6http377support.!icrosoft.co!7support7$+7artic#es79@C<7K78;.asp8 9@JJ8<0 4I=>53 Dhat is the Difference &et%een CD5 @.2 and CD5="SP4 6http377support.!icrosoft.co!7support7$+7artic#es79@JJ787<0.asp8

Are you redimensioning arrays? It is enera##( !ore e-pensive to redi!ension arra(s than it is to ra+ !ore than (ou need up front. Aedi!ensionin arra(s re'uires .isua# &asic Scriptin Mdition ).&Script* to a##ocate space for the ne% arra( 00 and, if (ou've used the Preserve !odifier to preserve the contents of the arra(, to cop( the data fro! the o#d arra( into the ne%. "his !eans that not on#( are (ou spendin e-tra processor c(c#es to redi!ension the arra(, +ut a#so that the process initia##( re'uires t%ice as !uch !e!or( for the cop(. Io%ever, if (ou a##ocate !ore space than (ou need initia##( )(ou need on#( five e#e!ents initia##(, +ut a##ocate space for @28*, then addin !ore data to the arra( re'uires .&Script to insert on#( the ne% va#ues into the e-istin arra(. Are you using multiple languages on a page? Mu#tip#e #an ua es on a iven pa e !ean !u#tip#e script en ines for that pa e. Script en ines use "hread Boca# Stora e )"BS*, so !u#tip#e threads cannot use an instance of a script en ine concurrent#(. "herefore, five si!u#taneous re'uests to the sa!e pa e %i## cause ASP to instantiate five script en ines. More en ines !eans !ore overhead, so (ou !a( +e a+#e to ain so!e perfor!ance +( #i!itin (our nu!+er of #an ua es used on a iven pa e. Are you chec-ing 'esponse.IsClientConnected before processing long routines? &( testin 'esponse.IsClientConnected (our app#ication can avoid %astin CPU c(c#es +( 'uittin !ethods if the c#ient is no #on er connected. =ote that IIS <.0 overco!es a #i!itation in IIS :.0 )the need to send content to the +ro%ser +efore chec$in the propert(*. >or sa!p#e code, refer to 9@828C2 4I5D"53 Use IsC#ientConnected to Chec$ If &ro%ser is Connected.4 6http377support.!icrosoft.co!7support7$+7artic#es79@82787C2.asp8 Are you using Server.%apPath unnecessarily? Dhen (ou re'uest Server.%apPath, (ou are eneratin an additiona# re'uest for the server to process. "o i!prove perfor!ance, rep#ace Server.%apPath %ith a fu##( 'ua#ified path %hen dep#o(in (our De+ site.

Are you parsing strings? Use re u#ar e-pressions in va#idation routines, in for!attin functions, and instead of #oopin throu h strin s. See 4Strin Manipu#ation and Pattern "estin %ith Ae u#ar M-pressions4 for practica# advise on usin re u#ar e-pressions. Are you using the same object many times? .&Script <.0 provides the .ith state!ent. "he .ith state!ent a##o%s (ou to e-ecute a series of state!ents on a specific o+1ect %ithout re'ua#if(in the na!e of the o+1ect. >or !ore infor!ation, see the Dindo%s Script "echno#o ies De+ site 6http377!sdn.!icrosoft.co!7scriptin 78. oes the global.asa contain empty Session/,nStart or Session/,n0nd methods? Strippin out e!pt( Session events reduces the a!ount of source code that ASP !ust traverse, and i!proves perfor!ance.

Component Performance
Are you storing your objects in Session or Application scope? Storin references to o+1ects in ASP's Session or App#ication scope %i## cause !an( perfor!ance and sca#a+i#it( issues if those o+1ects aren't desi ned to +e shared across threads or activities. 5n#( a i#e co!ponents 00 or, in Dindo%s 2000, co!ponents !ar$ed =eutra# 00 can +e referenced in Session or App#ication varia+#es %ith direct access +( c#ient threads. Co!ponents are considered a i#e if the( are !ar$ed &oth and a re ate the free0threaded !arsha#er )>"M*. See 4A i#it( in Server Co!ponents4 6http377!sdn.!icrosoft.co!7%or$shop7server7co!ponents7a i#it(.ht!8 for a discussion on ho% to a re ate the >"M. Co!ponents %ith other threadin !ode#s i!pose restrictions %hen stored in Session or App#ication scope. As !entioned ear#ier, .isua# &asic or other S"A co!ponents shou#d on#( +e used %ithin pa e scope. =ote that so#id#( %ritten .isua# &asic co!ponents can perfor! e-tre!e#( %e## if (ou fo##o% this ru#e. Sin #e0 and >ree0threaded co!ponents are not reco!!ended, +ecause of securit( issues and e-pensive pro-(7stu+s that et created %hen !arsha#in across apart!ent +oundaries. See the fo##o%in artic#es for additiona# infor!ation3 4ASP Co!ponent ?uide#ines4 6http377!sdn.!icrosoft.co!7%or$shop7server7asp7server0@2:2000.ht!8 92:;<:: 4I=>53 Co!ponent "hreadin Mode# Su!!ar( Under ASP4 6http377support.!icrosoft.co!7support7$+7artic#es792:;7<7::.asp8 9@<0JJJ 4I=>53 Descriptions and Dor$in s of 5BM "hreadin Mode#s4 6http377support.!icrosoft.co!7support7$+7artic#es79@<07J7JJ.asp8

Are you concatenating strings in components? Use fi-ed0#en th strin s in .isua# &asic for strin concatenation. Don't 1ust $eep addin to a strin , or (ou'## rea##ocate it !u#tip#e ti!es 00 and rea##ocation is e-pensive. Bad1
3ublic Function "ad(oncatenation( 4s String

-i5 int6oop 4s 7nteger -i5 str+e5p 4s String For int6oop = str+e5p = str+e5p = str+e5p = .e/t int6oop

%t2is 8ill be e/pensive

) +o )*** str+e5p 0 "<tr><td>(ounting " str+e5p 0 (Str(i str+e5p 0 "<&td><&tr>"

"ad(oncatenation = str+e5p $nd Function

2ood1
3ublic Function 9ood(oncatenation( -i5 int(tr 4s 7nteger -i5 int6oop 4s 7nteger -i5 str+e5p 4s String : ;<*** int(tr = ) For int6oop = ) +o )*** Mid(str+e5p= int(tr = "<tr><td>(ounting " int(tr = int(tr > )? Mid(str+e5p= int(tr = (Str(int6oop int(tr = int(tr > 6en((Str(int6oop Mid(str+e5p= int(tr = "<&td><&tr>" int(tr = int(tr > )* .e/t int6oop 9ood(oncatenation = str+e5p $nd Function 4s String %t2is i5proves perfor5ance

Severa# #ar e0sca#e sites found !a1or perfor!ance ains fro! this tip a#one. If (ou've ot e-tensive strin concatenation in (our app#ication, put this techni'ue hi h on (our priorit( #ist. M-peri!ent %ith different strin si2es, and test to see %hich si2e %i## %or$ +est for (our particu#ar routine. Are you using S3& Server for your middle+tier cache? If (ou need to cache data that is read fre'uent#( and se#do! updated in the !idd#e0tier, use S9B Server rather than a ro##0(our0o%n so#ution. S9B Server provides hi h0 perfor!ance !idd#e0tier cachin . >or !ore infor!ation, read 4Midd#e0"ier Ii h0Speed Data Cachin Invo#vin C5M7M"S and C5MF.4 6#i+rar(7+ac$ rnd7ht!#7!idtiercache.ht!8 Are you using transactions 4hen you don*t need to? "ransactions provide a service 00 and that service can add a perfor!ance hit. Mva#uate %hether !ethods actua##( need transactions. >or e-a!p#e, if (ou're ra++in a recordset to hand off to a +ro%ser c#ient for readin data, (ou don't need a transaction. &( factorin out operations that read data into separate co!ponents fro! operations that perfor!

updates, (ou have !ore f#e-i+i#it( in !ar$in (our co!ponents for transactions. "he fo##o%in artic#es provide sca#a+#e patterns that (ou can use as uide#ines to he#p (ou factor out (our o%n co!ponents3 4Sca#a+#e Desi n Patterns4 6#i+rar(7techart7!sdnOsca#edesi n.ht!8 4Si!p#if( M"S Apps %ith a Desi n Pattern4 6#i+rar(7periodic7periodCC7c+02CC.ht!8 4>MStoc$s App#ication3 Start Iere4 6#i+rar(7techart7f!stoc$sOstarthere.ht!8

Are you calling SetComplete5SetAbort in each method? Ca##in SetComplete and SetAbort in each !ethod of (our Microsoft "ransaction Server )M"S* co!ponents %i## re#ease resources ear#ier, and %i## ensure that a co!ponent does not #ive outside the scope of its transaction. In Dindo%s 2000, C5MF provides the settin 'Auto!atica##( deactivate this o+1ect %hen this !ethod returns,' %hich perfor!s the e'uiva#ent code. Eou can ena+#e this settin on a per0!ethod +asis in the Co!ponent Services conso#e. "his perfor!ance ain is !ore app#ica+#e to #ar e0sca#e sites, +ut is a#so ood for!. Are you creating child %$S components 4ith CreateInstance? In Dindo%s =" :.0, use CreateInstance to create chi#d M"S co!ponents. Create non0 M"S co!ponents usin Create,bject or 6e4 )un#ess the co!ponents are in the sa!e .isua# &asic pro1ect*. 5ther co!+inations cause code paths and chec$s that cou#d other%ise +e avoided. >or !ore infor!ation, see "ed Pattison's artic#e 4Creatin 5+1ects Proper#( in an M"S App.4 6#i+rar(7periodic7periodCC7+asics08CC.ht!8 In Dindo%s 2000, this distinction +et%een creatin o+1ects %ith different techni'ues oes a%a(, and (ou si!p#( use Create,bject )see 92<08K< 4I=>53 Create5+1ect and CreateInstance Iave the Sa!e Mffect in C5MF4 6http377support.!icrosoft.co!7support7$+7artic#es792<0787K<.asp8 Are your components in Server pac-ages or &ibrary pac-ages? Bi+rar( pac$a es run in their ca##er's process, %hi#e co!ponents in a Server pac$a e run in a ne% process. As such, Bi+rar( pac$a es do not have the cross0process perfor!ance hit that Server pac$a es have. A t(pica# reco!!endation is to run the De+ app#ication out of process, +ut have the co!ponents in a Bi+rar( pac$a e to provide +oth process iso#ation and hi h perfor!ance. In situations %here (ou need to use a Server pac$a e, as %hen (ou are ca##in re!ote M"S7C5MF co!ponents, ta$e steps to !ini!i2e cross process overhead. Are you crossing processes effectively? Mini!i2in !arsha#in overhead and reducin net%or$ ca##s are $e(s to i!provin perfor!ance of distri+uted app#ications. Use ear#( +indin in (our co!ponents to !ini!i2e e-pensive net%or$ round trips +( e#i!inatin the e-tra ca## to 2etIds,f6ames that #ate +indin incurs. Eou can further reduce net%or$ trips +( +und#in (our para!eters into ar u!ents for !ethod ca##s, instead of settin a +unch of properties individua##(. Aather than pass para!eters By'ef, pass ByVal %here (ou can to !ini!i2e !arsha#in overhead.

Are you using remote components? Man( deve#opers find the!se#ves in situations %here the( need to ca## re!ote co!ponents. A## of the ru#es for crossin processes effective#( app#(. An additiona# reco!!endation is to use an inter!ediar( pac$a e )see 9@<C;@@ 4Instantiatin Ae!ote Co!ponents in M"S and IIS4 6http377support.!icrosoft.co!7support7$+7artic#es79@<C7;7@@.asp8*. Usin an inter!ediar( pac$a e to ca## the re!ote co!ponent avoids so!e securit( co!p#ications and a##o%s (ou to use ear#( +indin . o your client and server machines use the same protocols in C,%? A co!!on cause of activation de#a(s of re!ote co!ponents resu#ts fro! the c#ient and server !achines havin different DC5M protoco# #ists. Use DC5MC=>?.MNM on each !achine to !atch the protoco# se'uence. >or e-a!p#e, if +oth !achines are usin "CP7IP, !ove "CP7IP to the top of the #ist on +oth !achines. A fe% uide#ines app#( %hen !odif(in (our DC5M protoco# #ist3 Move "CP7IP to the top %hen (ou can. Ae!ove protoco#s that (ou don't need. An( chan es to the protoco# #ist re'uire a re+oot.

Are you using ASP built+in objects from a remote component? Don't. Mven if (ou can fi ure out ho% to !arsha# the ASP +ui#t0in o+1ects )Ae'uest, Aesponse, and so forth* across !achines, the perfor!ance cost out%ei hs an( +enefits. Are you using Visual Basic? .isua# &asic perfor!s e-tre!e#( %e## %hen (ou have the ri ht version, use the ri ht settin s and fo##o% ood desi n uide#ines3 Use .isua# &asic K.0 Service Pac$ ;. Set Unattended M-ecution and Aetain in Me!or( in (our pro1ects )See >i ure +e#o%*. See 9@8K2J; 4&U?3 A. Aunnin .&0&ui#t Co!ponent in Mu#ti0 "hreaded Mnviron!ent4 6http377support.!icrosoft.co!7support7$+7artic#es79@8K727J;.asp8 for additiona# infor!ation. Aead 92:;<:8 4I=>53 Desi n ?uide#ines for .& Co!ponents Under ASP4 6http377support.!icrosoft.co!7support7$+7artic#es792:;7<7:8.asp8 to avoid !an( co!!on deve#op!ent !ista$es.

Are you using %)C? Active "e!p#ate Bi+rar( )A"B* co!ponents are #i hter than Microsoft >oundation C#asses )M>C* and are preferred for server co!ponents. M>C code is heav( for the server and !a( +rin a+out une-pected seria#i2ation for state !ana e!ent. A#so, (ou cannot create co!ponents !ar$ed &oth that a re ate the >"M. M>C on#( produces S"A o+1ects, %hich are #i!ited to pa e scope. Are you using 7ava?

Ma$e sure (ou have the #atest .irtua# Machine fro! 6http377%%%.!icrosoft.co!71ava78 Java "hreads &#oc$in %hen Accessin C5M 5+1ects.4 6http377support.!icrosoft.co!7support7$+7artic#es792;27;7K8.asp8 Are you 4aiting for stuff that could be done asynchronously? If (our ASP app#ication is !a$in #on data+ase ca##s or ca##in co!ponents that are %aitin on other co!ponents to raise events, consider !a$in the ca## as(nchronous throu h a 'ueuin !echanis!, such as MSM9. >or infor!ation on MSM9, see the fo##o%in 3 9@J;;;C 4I5D"53 Use MSM9 fro! an ASP Pa e4 6http377support.!icrosoft.co!7support7$+7artic#es79@J;7;7;C.asp8 9@8@8;C 4M'asp.e-e MSM9 &asic 9ueue 5perations Usin IIS7ASP4 6http377support.!icrosoft.co!7support7$+7artic#es79@8@787;C.asp8 92:;<:K 4PA&3 ASP Does =ot Support Mvents4 6http377support.!icrosoft.co!7support7$+7artic#es792:;7<7:K.asp8

Are you looping through large datasets in the middle tier? Push !ore of these #ar e or co!p#e- data operations to stored procedures %here (ou can.

ata Access Performance


Are you using inde"es in your database? Inde-es provide i!!ediate i!pact on (our app#ication's perfor!ance. Poor inde-es %i## s#o% (our app#ication to a cra%#, %hi#e ood inde-es %i## he#p opti!i2e (our app#ication's perfor!ance. >or infor!ation on tunin inde-es, see 4"op "en "ips3 Accessin S9B "hrou h AD5 and ASP.4 6#i+rar(7periodic7periodC87ado.ht!8 or S9B &oo$s 5n#ine. Are you calling stored procedures rather than dynamic S3&? Usin stored procedures prevents (our data+ase fro! havin to reco!pi#e (our S9B state!ents repeated#(. Use stored procedures or para!eteri2ed S9B strin s. Are you returning just the re8uired data? Chec$ (our SMBMC" state!ents to ensure that (ou're returnin on#( the re'uired co#u!ns and on#( the necessar( ro%s. If (ou have 'ueries that can potentia##( return a #ot of records, consider pa in throu h (our recordsets. See the fo##o%in artic#es for !ore infor!ation3 4Aecordset Pa in %ith AD5 2.04 6http377%%%.asp@0@.co!7artic#es7recordsetpa in 7inde-.asp8 4Ad Ioc De+ Aeportin %ith AD5 2.04 6#i+rar(7periodic7periodC87ado@2C8.ht!8 4K Da(s to &oost AD5 App#ication Perfor!ance4 6#i+rar(7periodic7period007adoapp.ht!8

Are you using A, or ' ,?

Ae!ote Data 5+1ects )AD5* and Data Access 5+1ects )DA5* are intended for a sin #e0 c#ient app#ication process, and %eren't tested for the De+. AD5 is desi ned and tested for De+ use. .hich version of % AC are you using? Updated versions of MDAC provide i!proved re#ia+i#it( and perfor!ance. Eou shou#d +e usin MDAC version 2.@ Service Pac$ 2 or #ater. MDAC 2.< is reco!!ended, +ecause it's the !ost sta+#e and it's +een tested e-tensive#(. If (ou don't $no% %hich version (ou have on (our +o-, (ou can ra+ the Co!ponent Chec$er too# fro! http377%%%.!icrosoft.co!7data7 67isapi7 o!sco!.ht!P"AA?M"Q7data78. Are you follo4ing % AC best practices? See 4I!prove MDAC App#ication Perfor!ance.4 6#i+rar(7psd$7dasd$7i!pr8#2!.ht!8 Are you pooling connections? Poo#in a##o%s (ou to reuse the effort of connectin to a data+ase. 5D&C Connection poo#in is on +( defau#t in MDAC 2.0. In MDAC 2.@ or #ater, 5#eD+ Session poo#in is the defau#t. Ae!e!+er that in order for poo#in to %or$, the user na!e, pass%ord, and resource in the connection strin need to !atch )it's a +(te0+(0+(te co!parison*. See the fo##o%in artic#es for additiona# infor!ation on poo#in 3 4Poo#in in the Microsoft Data Access Co!ponents4 6#i+rar(7techart7poo#in 2.ht!8 9@KC:J0 4I=>53 >re'uent#( As$ed 9uestions A+out 5D&C Connection Poo#in 4 6http377support.!icrosoft.co!7support7$+7artic#es79@KC7:7J0.asp8 9@8J8J: 4CnPoo#.e-e "est Connection Poo#in %ith "e!pd+ 5+1ects4 6http377support.!icrosoft.co!7support7$+7artic#es79@8J787J:.asp8 9@C@<J2 4I=>53 Connection Poo# Mana e!ent +( AD5 5+1ects Ca##ed >ro! ASP4 6http377support.!icrosoft.co!7support7$+7artic#es79@C@7<7J2.asp8

Are you storing A , connection in Session or Application scope? "his defeats the purpose of connection poo#in and creates resource contention. Create connection at pa e scope or %ithin the functions that need the!, and set the connections to nothin to free the connection +ac$ to the poo#. Are you e"plicitly closing 'ecordset and Connection variables? Aecordsets need to +e c#osed if the( are oin to +e reused )+ut reusin recordsets is discoura ed*. C#osin Connection varia+#es as soon as (ou can re#eases the! +ac$ to the poo#, so that the( can +e poo#ed for reuse. It is a#%a(s ood practice to e-p#icit#( c#ose (our o+1ect varia+#es. Are you reusing 'ecordset and Command variables? Create ne% Aecordset and Co!!and varia+#es rather than reusin e-istin ones. "his %on't necessari#( i!prove (our app#ication's perfor!ance +ut it %i## !a$e (our app#ication !ore re#ia+#e and easier to !aintain. See 9@CJ::C 4PA&3 Pro+#e!s Aeusin AD5 Co!!and 5+1ect on Mu#tip#e Aecordsets4 6http377support.!icrosoft.co!7support7$+7artic#es79@CJ7:7:C.asp8 for !ore infor!ation.

Are you disconnecting the recordsets? Disconnectin recordsets frees the Connection o+1ect +ac$ to the poo#, a##o%in the Connection to +e c#osed and reused sooner. Are you using the right cursor and loc-+type for the job? Use 4>irehose4 )for%ard0on#(, read0on#(* cursors %hen (ou need to !a$e a sin #e pass throu h the data. >irehose cursors, the defau#t in AD5, provide the fastest perfor!ance and have the #east a!ount of overhead. See AD5 docu!entation for !ore infor!ation on cursor and #oc$ t(pes. Are you using S6+less connections? In enera#, DS=0#ess connections are faster than S(ste! DS=s )data source na!es*, %hich are faster than >i#e DS=s. Are you using Access? Microsoft Access is a fi#e0+ased data+ase, so don't e-pect it to perfor! %e## %ith concurrent users under IIS. Are you using S3& Server? Use S9B Server J.0. S9B Server J.0 is superior to ear#ier versions of S9B Server, and provides ro%0#eve# #oc$in , as %e## as other perfor!ance +enefits. Eou've heard S9B sca#es 00 +ut for proof, see 6http377%%%.tpc.or 78, and read Ji! ?ra('s paper at 6http377research.!icrosoft.co!7sca#a+#e78. Are you using $CP5IP for your net4or- library? Use "CP7IP for (our net%or$ #i+rar( for perfor!ance and sca#a+i#it(. Are you using the ,&0 B S3& provider? "he S9B5BMD&, the S9B provider, is reco!!ended over MSDAS9B, the 5BMD& provider for 5D&C for perfor!ance and re#ia+i#it(. Are you using ,racle? 5rac#e perfor!ance rea##( depends on a co!+ination of the ri ht MDAC +its %ith the correct 5rac#e c#ient patches. If (ou're usin 5rac#e, ta$e the ti!e to read the fo##o%in artic#es3 4Microsoft 5BM D& Provider for 5rac#e3 "ips, "ric$s, and "raps4 6#i+rar(7psd$7dasd$7cano2(Cf.ht!8 4>itch R Mather Stoc$s3 Data Access Ba(er for 5rac#e 84 6#i+rar(7techart7f!stoc$sOda#Oorc#.ht!8 9@C;8C; 4I=>53 Usin 5rac#e Data+ases %ith Microsoft "ransaction Server4 6http377support.!icrosoft.co!7support7$+7artic#es79@C;787C;.asp8 9@C@@K8 4I=>53 >ai#ed to Mn#ist on Ca##in 5+1ect's "ransaction4 6http377support.!icrosoft.co!7support7$+7artic#es79@C@7@7K8.asp8

If (ou're usin 5rac#e and M"S, +e sure to revie% the fo##o%in artic#es3

Are you using the same database for reporting and transactions?

Man( #ar e De+ sites !aintain separate data+ases for read0on#( and transactiona# data as an effective %a( to +oost perfor!ance. "his has the added +enefit of a##o%in (ou to desi n (our data+ase sche!a to +e opti!i2ed for reportin .

IIS Settings
Is ASP debugging enabled? Chec$ the ISM. If ASP de+u in is ena+#ed, the app#ication is #oc$ed do%n to a sin #e thread of e-ecution. See 92@K<80 4PA&3 &#oc$in 7Seria#i2ation Dhen Usin InProc Co!ponent )DBB* fro! ASP.4 6http377support.!icrosoft.co!7support7$+7artic#es792@K7<780.asp8 Is ASP configured to have enough threads5script engines? Aead 4"he Art and Science of De+ Server "unin %ith Internet Infor!ation Services <.04 67isapi7 o!sco!.ht!P"AA?M"Q7%indo%s20007#i+rar(7operations7%e+7tunin .asp8 and 4=avi atin the Ma2e of Settin s for De+ Server Perfor!ance 5pti!i2ation.4 67isapi7 o!sco!.ht!P"AA?M"Q7+ac$sta e7%hitepaper.ht!8 Are you using SS&? Secure Soc$ets Ba(er )SSB* is e-pensive in ter!s of +and%idth and CPU usa e. If (ou're usin SSB, it's +ecause of securit( needs. Eour +est +et is to restrict SSB usa e to %here (ou need it, and $eep the pa es si!p#e.

Stress $esting
It's a co!!on !isconception that perfor!ance e'ua#s sca#a+i#it(. Perfor!ance for ASP !eans the rate at %hich pa es can +e served. Sca#a+i#it( is !easured +( ho% !uch perfor!ance de rades under additiona# #oad. "o put these ter!s in perspective, (our ASP app#ication !a( perfor! %e## %ith @0 users, +ut does not sca#e to @000 users, +ecause perfor!ance +eco!es unaccepta+#e. Use stress testin to !easure the perfor!ance and sca#a+i#it( of (our ASP app#ication. >or !ore infor!ation on sca#a+i#it( of DinD=A app#ications, see 4A &#ueprint for &ui#din De+ Sites Usin the Microsoft Dindo%s P#atfor!.4 67!sdn0on#ine7start7features7D=A+#ueprint.ht!8 .hat are your performance e"pectations? Perfor!ance can +e !easured in ter!s of the nu!+er of ASP re'uests per second that (our servers can hand#e. Usin ASP's perfor!ance counter, ASP Ae'uests Per Second, (ou can set +ench!ar$s to !easure a ainst. Are you trying to stress test 4ith a bro4ser? Stress testin %ith a +ro%ser !a( +e thro%in off (our resu#ts. As !entioned ear#ier, ASP %i## seria#i2e concurrent re'uests fro! the sa!e Session. >or e-a!p#e, if Coo$ies are ena+#ed and (ou're hittin the server fro! one !achine, then those re'uests %i## seria#i2e. Use the De+ App#ication Stress too# )DAS 00 for!er#( $no%n as Io!er*. >or an introduction to DAS, see 4I Can't Stress It Mnou h 00 Boad "est Eour ASP App#ication.4 6http377!sdn.!icrosoft.co!7%or$shop7server7asp7server0C2JCC.ht!8 #ave you performed end+to+end testing? Dhi#e it's i!portant and feasi+#e to stress test (our data+ase, co!ponents, and ASP #a(ers

separate#(, end to end testin is ho% (ou'## find (our app#ication's rea# +ott#enec$s.

Conclusion
Aevie%in ASP app#ications for perfor!ance !eans ta$in a #oo$ at severa# thin s. &( +rea$in the app#ication do%n into its various #a(ers, (ou can +ui#d a fra!e%or$ for ana#(2in perfor!ance issues. Dhi#e there are !an( uide#ines and reco!!endations, nothin rep#aces stress testin (our app#ication and usin sound 1ud !ent. 7. . %eier was born and reared on the U.S. East Coast. Since heeding Horace Greeley's advice, he has worked as a Developer Support engineer speciali ing in server!side co"ponents and #indows D$% applications involving &'S and %S( technology. Send feed+ac$ to MSD= 6!ai#to3!sdnL!icrosoft.co!8 S 200@ Microsoft Corporation. A## ri hts reserved.

Vous aimerez peut-être aussi