GuidelinesandTechniquesforDesigninghighperformanceWebsitesHyPerformix,Inc.
4301WestbankDriveBldg.
A,Suite300Austin,TX78746www.
hyperformix.
com1.
800.
759.
6333Abstract:Thisdocumentpresentsadiscussionontips,tricksandtechniquesfordesigninghighperformancewebsites.
Alloftheinformationcontainedwithinthisdocumentisavailableinthepublicdomain.
AlltrademarksusedwithinarethepropertyoftheirrespectiveownersHyPerformix,Inc.
2TableofContents1.
INTRODUCTION.
32.
GENERALCONSIDERATIONS.
33.
GRAPHICS.
34.
CACHING.
55.
HTTPCOMPRESSION66.
PREFERREDCUSTOMERS67.
COOKIES68.
FRAMES.
79.
BROWSERPORTS710.
COMMUNICATIONS.
711.
URLREFERENCES.
812.
COMMENTS.
813.
HTML.
914.
DHMTL.
915.
DYNAMICPAGES.
916.
JAVA.
917.
SCRIPTINGLANGUAGEFORWEBAPPLICATIONS1018.
JAVASCRIPT.
1019.
ACTIVESERVERPAGES.
1020.
VISUALBASIC.
1121.
CANDC+1122.
FASTCGI.
1223.
SERVER.
1224.
WEBAVAILABILITYMANAGEMENT(WAM)1325.
MISCELLANEOUS.
1326.
CONCLUSION.
14APPENDIXAREFERENCES15APPENDIXBIMPROVINGASPAPPLICATIONPERFORMANCE17APPENDIXCTIPSTOIMPROVEASPAPPLICATIONPERFORMANCE.
28APPENDIXDSERVERPERFORMANCEANDSCALABILITYKILLERS.
34HyPerformix,Inc.
31.
IntroductionThepurposeofthisdocumentistopresentasetoftips,tricksandtechniquesfordesigninghighperformancewebsites.
Thesetips,tricksandtechniqueshavebeengleanedfromamultitudeofsources(books,articles,websites,magazines,etc.
).
Thefocusofthisdocumentisonperformanceissues.
BothInternetandIntranetperformanceissuesarepresented;however,Internetperformanceistheprimaryfocus.
ThesourceofeachsetofdataispresentedinAppendixAandnotedwhereusedbyaboldednumberwithinbrackets[00].
AppendicesB,CandDcontainarticlesthathavesignificantcontent,itwasdecidedtopresentthemintheirentiretyratherthanattempttosplitthemintothevarioustopicsections.
2.
GeneralConsiderationsTherearethreewaystoincreaseyourwebsiteperformance[47]:1.
Decreasethegenerationtimeofthepage(server-related).
2.
Increasethespeedthattheinformationreachesyourcustomers(transport-related).
3.
Lowertheamountoftimeittakestorenderyourwebsite(browser-related).
FastdownloadsarethesinglemostimportantusabilityconsiderationinWebdesign[39].
SunMicrosystemsrecentlysurveyed1854usersandfoundthatspeedwasmorethanthreetimesasimportantaslooks.
Anend-to-endPerformanceStudyisnecessarytodeterminethefactorsaffectingresponsetime.
Agoodruleofthumbisthatthesizeofeachpage,includinggraphicfiles,shouldnottakelongerthantensecondstoloadontheslowestmodemaccessingyourWebsite[47].
Forexample,iftheslowestusershave56Kmodemsorbetter,thetotalsizeofyourgraphicsandpageshouldbe56kilobytesorless.
(10bitsperbyte,5.
6Kbytespersecond,times10seconds).
Moretypicallytheactualtransferratefora56Kmodemwouldbecloserto30Kbpswhichwouldlimitthetotalsizeofeachpagetoonly30kilobytesorless.
Experimentwithscrolling,i.
e.
,sendingmoredatathanwillfitonapage.
Theuserwouldthenscrollorhypertexttotheinformationthatisnotshowing.
Thiswayscreensmaybecombinedandduringthetimetheuserisreadingandfillingoutthefirstpartofthepagetherestofpageisbeingsenttothebrowser.
3.
GraphicsItisgooddesignpracticetoprovidetheusertheabilitytochooseGraphicsorTextonly.
Includealternatetextforeachselectableimage,forusersthathaveimagesturnedoff.
Avoidusinglargegraphicalfontsandimages.
WherepossibleuseimagesintheGIFformatratherthantheJPGformat.
Usegraphicsonlywhentheyarecriticaltotheinformationcontentofyourpage,notjustforvisualappeal.
Allimagesshouldhaveheightandwidthparameters.
Providingtheheightandwidthallowsthebrowsertoreservethatspaceforthegraphicandcontinueloadingotherpartsofthepagewhiletheimageisloading[31].
UseGIFtransparencyonlywhenneeded.
Itmakesthefilelargerandtakeslongertoload.
HyPerformix,Inc.
4Minimizethenumberofcolorsbeingusedinasingleimage.
Designyourpagessothattheylookgoodon256-colorscreens.
50colorsareareasonablelimit[1].
Forceallgraphicstousethesamecolorpalette[49],especiallythosethatappearonasinglepage.
ItisalsoworthconsideringusingtheNetscapecolorcube[31]and[35].
Thereareapplicationsthatcanreducethenumberofcolorsandthesizeofimages[31].
Usegraphicalbulletsanddividerbarswhentheyserveapurpose,notbecausetheylook"neat.
"Sinceeachbulletandaccentgraphicisanotherimagethatneedstobeloadedfromthehostcomputer,useasmallsetofbulletsoraccentgraphicsrepeatedly,ratherthanusingalargenumberonlyonceeach.
Oncetheimagehasbeenloadeditiscached(stored)ontheclientcomputerandisavailablewithminimalloadtime.
Experimentwithconsolidatinggraphicobjects.
Eventhoughyoupassthesamenumberofbytes,everyobjectpotentiallyrequiresachecktoseeiftheversioninthebrowsercacheisoutofdate.
Thischeckisamessagesend-receiveroundtripfromthebrowsertotheserver.
Forstaticimages(onesthatrarelychange)thischeckisalloverhead.
ConsolidatingNimagesintoonereducesthisoverhead.
Useclient-sideimagemapstoconsolidatesmallerimagesthatarehyperlinks.
HotspotsontheimagemapcanbeusedtolinkthevariouspartsoftheimagetodifferentURLs.
Experimentwithpre-loadinggraphicsviathe"single-pixel"technique.
If,forexample,thewebsitehasapagewithaformthattheusermustfillout,andthepageaftertheformsubmissionhasalargegraphic,thenitmightbepossibletotransparentlypre-loadthelargegraphicbyincludingthefollowingHTMLcodeatthebottomofthepagethathastheform:.
Thelargeimagewillbeloadedwhiletheuserisfillingouttheform.
Regardlessoftheoriginalsizeoftheimage,itwillappearasasinglepixel(virtuallyinvisible)onthepagewiththeform.
Thebenefitisthatitwillappearinstantaneouslywhenthefollowingpageisaccessed.
FromSunMicrosystems:GuidetoWebStyle[1]1.
Ifyou'regoingtousemanyimagesclosetogetheronapage,loadingeachimagerequiresanewconnectionbetweentheuser'sbrowserandawebserver.
Forusersonlow-bandwidthconnections,orthoseconnectingtooverloadedservers,onelargeimagemayloadfasterthanseveralsmallerones,becauseoftheeliminationofmultiplebrowser/serverconnections.
Usersonhigher-bandwidthconnectionsgoingtofastserversmaybenefitfromhavingmultiplesmallerimages,assomebrowserswillmakemultiplesimultaneousconnectionstoaservertoretrieveimages.
Understandyouraudienceandtheirtypicalbandwidthandbrowserusage,andchooseappropriately.
2.
SupplyinterlacedGIFfilesinyourpagestoallowimagestoloadinmultiplepasses(i.
e.
,the"windowshade"ormulti-layereffect).
Ifyourbrowsersupportsinterlacedimages,theinterlacedpicturewillloadinaseriesofpasses,eachoneaddingmoredetail.
Thenon-interlacedimagewillappearinsuccessivehorizontalbands.
Theinterlacedimageshowsmoreoftheimagesooner,withlessdetailintheearlypasses.
3.
Specifybothlowandhigh-resolutionJPEGfilestoenablesmartbrowserstopaintanentirepageforyourreaderandthengobackandfillinhigh-qualityimagesafterthepagehasloaded.
Thistechniqueisworthwhileonlargeimages,especiallythoseover100K.
FromDesigningHighPerformanceWebPages[31]:1.
Thefirstandmostcriticalistokeepimagessmall(),thebrowseropensanewporttorequesttheinformationforthetag,inadditiontotheportalreadyopenfortheHTMLpageorASPpagethatcontainsthetag.
SinceNTcanprocessonlyoneportatatime,throughputdegradesbecauseNThastoswapbetweenthetwoopenportstoretrievedata.
Sniffertracescaneasilyidentifythisproblem.
Solution:Mostofthetime,thissituationdoesnotcauseaperformanceproblem,becausethekindsoftagsthathaveaSRCattributeareassociatedwithfilesthatcanbecachedontheworkstation.
So,atmost,therewouldbeanegativeperformanceimpactonlythefirsttimethewebpageisaccessed.
ThescenariothatcouldcauserepeatedperformanceproblemsiswhentheSRCattributereferencesanASPpage.
AnexampleofthiswouldbeanASPpagethatcontainsanIFRAME,andthisIFRAMEloadsanotherASPpage.
IftheIFRAMEhasaSRCattributespecified,throughputwouldberestrictedbecausetheoperatingsystemwouldbeswappingbetweentwoportstodownloadthedataneededforbothASPpages.
AbetterapproachistowaituntilthefirstASPisfinishedloading,andthenfromits"window_onload"methodyoushouldsettheSRCattributefortheIFRAME.
LoadingthesecondASPpagethiswaywouldallowtheportforthefirstASPpagetoclosebeforeanewoneisopenedforthesecondASPpage.
UseHTTPRound-triptimeandKeep-Alives[46page53],[47page74-76].
HTTP1.
1allowsmultipleHTTPtransactionsacrossthesameconnection,or"persistentconnection".
Thisalsoenables"pipelining"ofnewclientrequestsbeforepreviousrequestsareresolved,andsimplifiesauthentication.
DoenableKeep-Alives.
HTTP1.
1allowsmultipletransactionsacrossthesameconnection.
Thistransmitsfewernetworkpacketsandreducesoveralllatency[27],[46page53].
DoenablepipelinedrequestsacrossHTTP1.
1[27],[47page76].
Sendingmultipleclientrequestsbeforeareplyisreceivedimprovesboththroughputandoverallresponsetime.
10.
CommunicationsAll56Kmodemsdonothavethesameperformance.
Themodemshavesignificantperformancedifferencesinregardtolatency[4].
Latencyisthattimefromwhenthemodemreceivesacommanduntilthedesiredactionbegins,e.
g.
,thetimefromwhenatransmitcommandisreceivedbythemodemandwhenthedataactuallybeginstransmitting.
Itisimportanttoselectamodemwithlowlatencyespeciallywhentherearemanysmallmessagesbeingtransmitted.
Improvethequalityofthetelephoneline[6].
IncreaseTCP/IPlistenintervals[27],[46page139].
MuchofTCP/IP'sresilienceandcongestioncontrolreliesontheassumptionthatcommunicationssessionsarepersistent.
IncreasingTCPlistenintervalsandqueuelengthspermitsmorependingrequeststohangaround,ratherthanbedeniedservice.
HyPerformix,Inc.
8Disable"slow-start"sessionsforweb-basedapplications[27],[47page139].
Disabling"slowstart"sessionsmeansthatsmallIPwindowsdon'tprevailbecausethere'snotimeinanaverageHTTPtransmissiontorenegotiatelargerwindows.
Therelativelysmalldatavolumeforweb-basedapplicationsdoesnotjustifytimelostdeterminingtheoptimumtransferwindow.
TCP/IPslow-startwasdesignedforInternetservicessuchasFTPorremoteloginthatinvolvelongconnectionsand/ormassivedatatransfer[46page139].
Effectively,thewebserverfirstsendsasmallnumberofpacketsandthenrampsuptoanoptimum.
Thisoccursforeachnewconnection.
Mostwebtransactionstransfersuchsmallamountsofdatathatslow-startisanuisanceandwastestime.
UseTCP/IPforyournetworklibraryforperformanceandscalability[51].
DisablereverseDNSlookups[27].
Althoughcheckingontheidentityofthosewhovisityoursiteisimportantwheresecurityisparamount,otherWebsitescangreatlyspeeduptheirWebservicesbyomittingthistime-consumingstep(iteffectivelydoublestheround-triptimeforHTTPrequests).
Youcanalwaysusethird-partysecuritymonitors,likeHaystackLabs'sWebStalker,toperformthiskindofserviceforyouifyoususpectasecuritybreakorabreak-inattempt.
11.
URLReferencesMakesurealllinksarevalidURL's.
ReducethenumberofcharactersineachURL.
TheURLhttp://x.
com/a.
htmwillloadfasterthantheURLhttp://x.
com/web/code/first_stuff/intro/first_page_code.
htm.
Thereare3waysofcodingaURLreferencetogetapage[31].
Theyeachhaveslightlydifferentperformance.
Theyare,inhighestperformancetoslowestperformanceorder:a.
page_name/index.
htmlb.
page_name/c.
page_nameIf"c"iscoded,itcausesahittothewebsite,thena"/"getsaddedandanotherhitoccursandthenthesitemustfindthedefaultpage.
If"b"iscoded,thesitemustfindthedefaultpage.
Ifthecompletefilenameisprovidedasin"a",thepageisdirectlyaccessed.
Onaheavilyhitsiteitcanmakealargedifference.
So,itisimportantthatallURLsincludethefullfilename.
AdditionalURLinformationisinSection4,Caching.
12.
CommentsMaximizeyourcommentsinthedevelopmentcopyofeachhtmlfileinordertoassistinthemaintenanceofthefile.
However,stripallcommentsandwhitespacefromthehtmlfilethatisloadedontothewebserver[49]and[52].
HyPerformix,Inc.
913.
HTMLReadAppendixB[51]andAppendixC[52].
Threemethodsofrequestingafile(HTTPGET,CGIinCandCGIinPerl)showedthestandardGETwasequivalentorsuperiortotheothermethodsinallcases[28].
Inaddition,compiledCoutperformedinterpretedPerl.
RemoveembeddedtablesandavoidusingtheCOLSPANattribute[47].
Netscape,morethenInternetExplorer,slowsdownwithnestedtables.
Avoidverbosityindefiningthenamesofthehtmldirectorytree.
Forsiteswithmanylinks,thetimetodownloadtheseextracharactersmayaddahalf-secondormoretotheresponsetimes.
Useshortnameslikeg/forgraphics,etc.
longnamesarejustmoredatatotransmit(twice,oncefromtheserverthenbacktotheserver)[49].
14.
DHMTLDHTMLprovidestheabilitytomodifyanHTMLpageafterithasbeenrenderedbythebrowserusingcodethatiswrittenandpackagedwiththeHMTL.
ThiscodecanbeVBScript,Javascript,Java,and/orVisualBasic.
YoushouldrefrainfromusingVisualBasicandJavatodriveaDHTMLpageatthepresenttime.
NetscapeNavigatorandInternetExplorer3.
02doprovidesomeclientsidescriptingcapabilitiesbuttheydon'tsupportthefullDHTMLmodel.
CareneedstobetakenindevelopingawebapplicationusingJavascript,whichistargetedfortheseBrowserplatforms.
15.
DynamicPagesDynamicpages(writteninCGI,Perl,ASP,ColdFusion,etc.
)haveahighresponsetimebecausethemachinemustexecutesomecodetogetthepagetogethersothatitcanbestreamedoutthenetworkcard[47].
Theamountofresponsetimethatitcantakecanbeuptotwentytimesgreaterthenstaticpagesthatarejustreadfromtheharddisk.
Onewaytoreducetheresponsetimeofdynamicpagesistochangethemtostaticpages[47].
TheXBuildertoolcanconvertdynamicpagestostaticpages.
Thisworksespeciallywellifthepagesdonotchangeforeveryuser.
Forexample,ifyouarestoringinformationinadatabase,thenpublishingusingdynamicpages,yourpagesdonotchangeperuser,onlywhenthedatabasechanges.
BuildingthesepagesstaticwithXBuilder[48]everytimecanincreaseyourperformancedramatically.
XBuilder[48]canalsoreducethesizeofthepagebyremovingthetabswhenitbuildsthepages.
Tabsarenotrecognizedbybrowsersandareonlyusedfordevelopmentclarity[47].
Removingthemcandecreasethepagesizeonaverageby10%.
16.
JavaBecauseofacoupleofsecurityscares(seeCERTVulnerabilityVB9806)manyusershaveturnedoffJavaandJavascriptontheirbrowsers[31].
Whendesigningawebsiteitshouldbemadeclearwheneveralinkisgoingtorequirethese.
MakesureyouhavethelatestVirtualMachinefromhttp://www.
microsoft.
com/java/[51].
ReadAppendixB[51]andAppendixC[52].
HyPerformix,Inc.
1017.
ScriptingLanguageforWebApplicationsDonotuseinterpretivescriptsifthescriptinglanguagepermitscompilation[27],[28].
Rewritenon-compiledscriptsinacompiledlanguage.
Compiledcodeusuallyrunsanorderofmagnitudefasterandreducesprocessoverhead.
InterpretivescriptiscostlycomparedtocompiledC[46page70].
Interpretiveprogramsaregenerallyslowerthancompiledcodebecauseoftheline-at-a-timeexecutionoverhead.
TheCGIscriptsexecuteinitsownprocessspace,thereforeitdoesnotbenefitfrommultithreading[46page148].
18.
JavaScriptBecauseofacoupleofsecurityscares(seeCERTVulnerabilityVB9806)manyusershaveturnedoffJavaandJavaScriptontheirbrowsers[31].
Whendesigningawebsiteitshouldbemadeclearwheneveralinkisgoingtorequirethese.
FromSiteOptimizationTutorialbyPaulBoutin[50]:1.
JunktheJavaScript.
WeusetohaveaJavaScriptfunctioninHotBotthatsetthebrowser'skeyboardfocustothetext-inputbox.
Justthatonefunctioncausedanoticeabledelayintheloadingofthepage.
2.
Ifyou'reusingJavaScripttocontrolplug-insorDHTML,readthemanualsforthosecomponents.
Youmayfindthatyour20-lineJavaScriptprogramcanbereplacedbyabuilt-infunctionthatbothloadsandrunsfaster.
Wewrotea"NextTen"functioninJavaScripttochangethecontentsofatableloadedintoMSIE4.
ThenwelearnedthatIE'sbuilt-innextPagefunctionwasmorethan10timesfasteranddidn'tmessupthepagewhenitran.
19.
ActiveServerPagesReadAppendixB[51]andAppendixC[52].
Dousebuffer=true[2].
Donotuseresponse.
flush[2].
SpeedTipsbyCharlesCarroll[6]1.
Anypagethatdoesnotneedsessioncanbenefitfromthisdirectiveatthetop[6],[7]:2.
Allpagesshouldbebufferedsee[2],[6].
Addthistotop:3.
FlushbufferandHTMLtagstoimproveperceivedspeed[8].
4.
Pagesdoingdatabaseaccesswillimproveperformanceifthefollowingtechniquesareused:Getrows[9],[10]GetString[11]Disconnectedrecordsets[12]5.
BeforejustbelievinganyarticleyoureadontheweborinanASPbook(manyarticlesarenotresearchedthoroughly)andimplementingcodechangesTIMETHECODEBEFOREANDAFTERchanges.
Speedtimer[13]hastheneededcodethatwilltimescriptstomillisecondaccuracy.
6.
Eliminateanycodethatreadscompropertiestwice[14].
7.
JustsaynotoVBcomponentsand/orrecordsetsstoredatthesessionlevel[15],[16],[17],[18],[19],[20].
8.
Cachefrequentqueryresults/HTMLgeneratedfromdatabasesinapplicationvariables[21].
HyPerformix,Inc.
119.
Opendatabaseconnectionsaslateaspossible,Closedatabaseconnectionsimmediatelywhendone.
Placingyourcodeafewlineslatercouldmakeahugedifferenceasyourscriptsrunround-robinwithotherscripts[22].
10.
Don'twastetimerunningscriptsiftheuserhitthe"stop"buttonorwenttodifferentpage/site[25].
Normallyscriptsstartedbyauserruntocompletionwhethertheuseristheretoreadoutputornotrunninginvisiblyonserver.
11.
BitethebulletandmasterremotescriptingsoyourHTMLandASPscriptscancommunicatewithASPasynchronouslyandrefreshportionsofpagewithoutsubmittingpagetoserver.
RemotescriptingworksinbothNetscapeandIE;anyJavascriptcapablebrowser.
Someremotescriptinglinksandalistservertogethelpisat[26].
FromWebWorkshop–"ImprovingASPApplicationPerformance"[44]1.
StoreallVisualBasicobjectsandtheScripting.
Dictionaryatpagescope.
Single-threadedapartment(STA)objectsatSessionorApplicationscopethwartconcurrencythroughlockingorserialization.
2.
MigratemassiveASPscriptcodetocustomcomponentsandtofunctions.
Theformerissomewhatofaspecialcaseofthe"compiledon'tinterpret"adviceofferedfrommanysources.
Thelatter,partitioncodeintogenericfunctions,alsoimprovesperformanceandlaysthegroundworkforfuturecomponents.
3.
Avoidlarge#includefiles.
Therearetwoseriousissues.
First,acompletecopyofeach#includefilereferencedbyeachASPpageisloadedintomemory,soredundantcopiesmanyexistandunusedroutinesarenotremoved.
Second,thetimetosearchthenamespaceforroutineandvariablereferencesexpands.
4.
Globalvariablesshouldbescarce.
Itisbettertodenormalizealarge#includefileintomultiplefilesofgreaterspecificityandgranularity.
5.
Significantperformanceimprovementsaregainedbykeepingblocksofserver-sidescripttogetherratherthaninterspersingASPandHTML[45].
Thisreducesthecontextswitchingoverhead.
6.
AvoidSessionstatealtogether.
ASPsessionsareWeb-serverspecificandlimitscalabilityacrossmultiplemachines.
Plusthestatefulenvironmentconsumesresourcesforeachuser.
TryworkaroundssuchaspassingdatainQueryStringsorhiddenformfields.
AlsoconsideradatabasekeyedtoauserIDthatpersistsacrossthe"session".
7.
TestResponse.
IsClientConnectedbeforelongroutines.
8.
Parsestringswithregularexpressionsinsteadofloops.
9.
Investigatetheeffectof#includefilesandSingle-threadApartmentversusMulti-threadApartment[46].
20.
VisualBasicVisualBasicperformswellwhenyouhavetherightversion,usetherightsettingsandfollowgooddesignguidelines:AppendixB[51]andAppendixC[52].
21.
CandC++Itisimportanttopayattentiontocompileroptionsandoperatingsystemlevels[31].
ThereareseveraloptionsontheUNIXCcompilerthatshouldbetested–O,O2andO3,Qandqstrict.
Ataminimumjustusing–O(basicoptimization)willnormallyimproveperformanceforaCPUintensiveapplication100%.
Itshouldalsobenotedthatupgradingtoanewversionoftheoperatingsystemcanalsochangecompiledprogramperformance.
Numbersashighasa17%improvementwitharecompilearenotuncommon.
ThereareanumberofotherprogrammingtipsthatcanimproveCperformance:1.
UseANSIstandardlibraryfunctionsHyPerformix,Inc.
122.
Useabbreviatedassignmentse.
g.
c+=33.
Don'tcodeconstantssuchascat=1inaloop4.
Avoidrecursion–recursivecallsusemorememoryandtakemoreCPU5.
Inlinefunctions(-Q)reduceexecutiontime6.
Functioncallsaddoverheadsolimitthenumberoffunctionstowhatisnecessarytokeeptheprogrammanageable7.
Callbyreferenceforarraysreducesmemoryneeds8.
Gotoismoreefficientthanacase,howeveritisviewedasbadprogrammingpracticethatleadstohardtomaintaincode9.
Globalvariablesimproveperformancebecausedatadoesn'tneedtobepassedaround22.
FastcgiEveryinvocationofaCGIscriptorprogramspawnsanewprocessorthread[31].
Becauseoftheoverheadassociatedwiththis,manyservervendorsnowprovideaseparateAPIinterfacetotheirserverwherethemainscriptisdynamicallylinkedandexecuted.
Unfortunatelythesescriptshavetorunundertheserver'sidentityandtheythushaveaccesstotheserverinternals.
Anotheralternativeistolookintothenewopeninterfaceforperformance–Fastcgi.
Fastcgi[37]hasbeendevelopedatNCSAasalanguageindependentinterfacethatremovestheneedtouseAPIstogetperformance.
23.
ServerTuneyourserver[23],[24].
Dousemultithreadingorapre-allocatedprocesspoolasanalternativetoforkinganewprocessforeachrequest[27],[30].
Thisreducescontext-switchingoverhead.
Ifitisnecessarytospawnatask,dosowithintherun-timecontextoftheWebserver.
Useserver-sideAPIs[27],[46page148].
MostwebserversincludeproprietaryAPI'sthatcreatethreadsorsub-processesthatrunwithintheWebserverprocessspace.
Thisavoids95%oftheusualcontext-switchingoverheadassociatedwithCGI.
NotethatCGIscriptsexecutewithintheirownprocessspace,negatingsomeofthebenefitsofmultithreading.
ReducetheuseofCGIsandotherinter-process(IPC)causes[27].
WhileCGIsandotherformsofinterprocesscommunicationdoindeedaddtoaWebserver'soverallcapabilities,theoverheadinvolvedincallingacrossprocessboundariescanbearealdragonperformance.
Ifperformancehaspriorityoverportability,useWeb-serverAPIandserver-sideincludes.
FileLocking[31].
TowriteCGIprogramsitisoftennecessarytohavecodethatneedstobeexecutedinaserialfashion.
Areasthatrequirethismaybeupdatingfiles,generatingcountersandothersimilarfunctions.
Todothis,itisnecessarytousefilelocking.
Duringthetimethelockisheld,anyotherapplicationusingthatlockwillwaitforthelocktobefreed.
Forperformanceandresponsetimereasons,itisimportanttolockthefileaslateaspossibleandtofreethelockasearlyaspossible.
Obviously,locksshouldonlybeusedwhenitiscriticaltodoso.
ItiscommonintheUNIXworldtowriteapplicationsthatusesleeploopswhiletheywaitonaneventtooccur[31].
Thisisnotagoodwaytowritecodeasresourcessuchasmemoryareheldduringthistime.
ThiskindofspinloopalsowastesCPUresourcesasitwakesupperiodicallytocheckwhetheranythinghashappened.
Loopsshouldbekeptsmallandsimplewithanyconstantvariablesbeinginitializedbeforetheloopisentered.
Thisavoidsrepeatedlyexecutinginstructionsthatonlyneedtobeexecutedonce.
DNS(domainnameservices)isusedtoresolveanIPaddressintoanamesoitcanbewrittentothelogfilefortheserver,whichmakesitmorereadableforpostprocessingofthelogs[31].
ThisisthereverseofwhatnormallyhappensattheclientendwheretheservernameneedstobetranslatedintoanIPaddresstofindtheserver.
IftheIPaddresscan'tberesolvedintoaname,thenatimeoutoccursand,HyPerformix,Inc.
13dependingontheoptionschosen,eithertheIPaddressisloggedortheconnectionisrefused.
Onabusyserver,thisshouldeitherbeturnedofforaDNSservershouldbeloadedontothewebservertospeedupthetimeforthelookupsandtoreducenetworkdelays.
CGIprogramsandhttpdconnectionstendtorunassubtasksorthreadsunderthemainserver[31].
Becauseofthis,themaxuprocparameterontheserver(ormaximumchildren/threads)shouldbereviewedtoensureitishighenoughtocopewithpeakload.
Thedefaultonmanysystemsis40andwebserverswilltypicallyneednumbersintherangeof1000to4000.
WebserversalsobenefitfromrunningonanSMPserverwheremultipleCPUscanbeactiveatthesametimeservicingrequests.
Manyserversalsoallowthedynamiccreation(inetdcontrolled)ofhttpdprocesseswheneverarequestisreceived–itisnormallybettertoconfiguretheservertokeepaminimumnumberofprocessesreadytogoandtoletthatrangeuptoamaximum.
Thisreducestheoverheadincreatingaddressspaces.
Therearethreesecuritylevelsforthewebpages–none,basicoruuencodedandSSL(certificateswithencryption)[31].
Thehigherinthesecurityhierarchythepagesare,themoreofaperformancehitthatwillbetaken.
EncryptiontakesCPUcyclesandtheimpactofthisshouldbecarefullymeasuredbeforeproduction.
TherearealsosomegoodoptionsavailabletoreduceI/Oandnetworkdelays[31].
Forthenetwork,lookatMbufs,transmitqueuesize,collisions,andTCPsendandreceivespace.
Recommendationsonwhattolookataredescribedin[34].
ForI/Olookatplacementoffilesandlogs.
Unlesstheyareactivelybeingused,turnoffthereferrerandagentlogs.
Thereferrerlogtellsyouwhatwebpagetheusercamefromwhiletheagentlogtellsyouthebrowsertheyareusing.
TheseareveryI/Ointensiveandshouldbeavoided.
Thelogsthatareofmostusearetheaccesslogandtheerrorlog.
Ataminimum,theseshouldbeintheirownfilesystemandonareserveddisk.
Itisalsopossibletosplitoutwriteonlydirectorieswithinthewebspacetotheirowndisksortosplitupthecgiprogramsanddocumentdirectoriesontoseparatedisks.
ThiswillreduceI/Ocontention.
ReadAppendixD[53].
24.
WebAvailabilityManagement(WAM)WAMisaconceptthatrevolvesaroundtheideaofcongestion-control[38].
Insteadofgivingeverybodyabadexperience,orsimplyrejectingusers('connectionrefused'typemessages),youemploytheWeb-equivalentofMuzak(presentapagethatsays'Yourcallisimportanttous.
Here'ssomeniceprettymarketingfluffwhileyouwait.
.
.
').
Byprotectingtheoverloadedsegmentsofthesystemfromfurthercongestion,youallowamuchfasterrecoverytime.
Forexample,CNNcutthegraphicsfromtheirpageswhenthesiteisunderload.
Ithasalsobeenproposedtodropfunctionality,e.
g.
,anon-linemartmayallowuserstobrowsethecatalogbutnotsubmitneworders,untilthecongestionhaseased.
25.
MiscellaneousAUTOMATICOPTIMIZATIONOFWEBSITESUtilize"sitecheckers"todetermineperformancemetricsand"optimizer"programstoreducetheresponsetimeofwebsites.
Asmallsamplingofavailableproducts:SpaceAgent.
Optimizeseachpageofanentirewebsite.
WebSiteGarage.
Offersseveralweb-basedproductsforperformancediagnostics,imageoptimization,andtrafficanalysis[41].
GIFWizard.
ReducesGIFs,JPGs,andBMPs[42].
Showstheuseraselectionofpossiblesizesandcolordepthsforeachgraphicorperformsautomaticreduction.
HyPerformix,Inc.
14DeBabelizer.
Amultimediafileconversionandoptimizationprogram[43].
Scripting,batching,andHTMLparsingfeaturesallowgraphicstobeconvertedamongformatsandoptimizedforspeedversusquality.
BrowserInstances[55]Whennewbrowserwindowsarelaunchedfromexistingbrowserwindows,newinstancesofInternetExplorerarenotcreated.
ItispossibletohaveseveralbrowserwindowsassociatedwithoneinstanceofI.
E.
Toquantifythememorysavingsofhavingmultiplewindowsassociatedwithoneinstance,amemoryconstrainedenvironmentwascreatedonthedesktop,andthentwotestswereperformed.
Inonetest,severalinstancesofI.
E.
werelaunched,eachwithonebrowserwindow.
Intheothertest,severalbrowserwindowswerelaunched,allwithinthesameinstanceofI.
E.
ThetestsrevealedthatlaunchingadditionalbrowserwindowswithinthesameinstanceofI.
E.
consumedaboutMBofadditionalmemoryperbrowserwindow.
Incontrast,eachadditionalinstanceofInternetExplorerconsumedabout3MBofadditionalmemory.
Itwasalsonoticedthatwhenanewwindowwaslaunchedfromanexistingwindow,itcameupmuchfasterthanwhenanewinstanceofI.
E.
waslaunched.
Asanaddedsavings,theuserisnotpromptedforauseridandpasswordwhenthenewwindowwaslaunchedfromanexistingwindow.
However,theuserispromptedforauseridandpasswordeachtimeanewinstanceofI.
E.
waslaunched.
TolaunchanewbrowserwindowwithinthesameinstanceofI.
E.
,selectFile->New->Window.
TheshortcutisCtrl+N.
26.
ConclusionThispaperhaspresentedasamplingofguidelinesandtechniquesfordesigninghighperformancewebsites.
FollowingthesetipsandhintswillhelpyoubuildaWebsitethatensuresoptimalperformance.
HyPerformix,Inc.
15AppendixAReferences[1]Sunonthenet:GuidetoWebStyle.
http://www.
sun.
com/styleguide/tables/Welcome.
html[2]WhyBufferhttp://www.
learnasp.
com/learn/whybuffer.
asp[3]TCPtechniques:http://support.
microsoft.
com/support/kb/articles/Q240/1/46.
ASPLN=EN-US&SD=gn&FR=0[4]It'stheLatencyStupid,http://rescomp.
stanford.
edu/cheshire/rants/Latency.
html[5]3Comlinetestsite:http://www.
3com.
com/56k/need4_56k/linetest.
html[6]SpeedTipsbyCharlesCarroll,http://www.
learnasp.
com/learn/speedtips.
asp[7]ASPFastcode,http://www.
asplists.
com/asplists/aspfastcode.
asp)[8]ASPflushing:http://www.
learnasp.
com//learn/speedtables.
asp[9]Getrows,http://www.
learnasp.
com/learn/dbtablegetrows.
asp[10]Getrows,http://www.
learnasp.
com/advice/whygetrows.
asp[11]GetString,http://learnasp.
com/learn/dbtablegetstring.
asp[12]Disconnectedrecordsets:http://www.
learnasp.
com/learn/dbtabledisconnected.
asp[13]Speedtimer:http://www.
learnasp.
com/learn/speedtimer.
asp[14]Comproperties,http://www.
learnasp.
com/learn/propertyexpense.
asp[15]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/advice/dbsessionapp.
asp[16]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/learn/nosessionobjects.
asp[17]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/learn/sessionoverview.
asp[18]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/learn/sessionoverview.
asp[19]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/learn/buildvbthreads.
asp[20]VBcomponentsand/orrecordsetsstoredatthesessionlevel:http://www.
learnasp.
com/learn/globalproblems.
asp[21]Cachefrequentqueryresults.
http://www.
learnasp.
com/learn/speedappdata.
asp.
[22]Round-robin,/advice/roundrobin.
asp.
[23]Tuneyourserver,http://www.
learnasp.
com/advice/threads.
asp).
[24]Tuneyourserver,http://www.
learnasp.
com/learn/speedserver.
asp[25]Stopcode,http://www.
learnasp.
com/learn/isclientconnected.
asp[26]Remotescripting:http://www.
asplists.
com/asplists/aspremotescripting.
asp.
[27]WebServerPerformanceGuidelines,byEdTittelhttp://sunsite.
icm.
edu.
pl/sunworldonline/swol-09-1997/swol-09-webserver.
html[28]WebServerTechnology,byYeagerandMcGrath.
[29]CapacityPlanningandPerformanceModeling-FromMainframestoClient-ServerSystems,byMenasce&Almeida:[30]Keepingthe400lb.
GorillaatBayOptimizingWebPerformance,byJamesRubarth-Lay.
http://eunuch.
ddg.
com/LIS/CyberHornsS96/j.
rubarth-lay/PAPER.
html[31]DesigningHighPerformanceWebPages,byJaquiLynch,Circle4ComputerConsultants[32]1996and1999websurveysbyJakobNielsen,www.
useit.
com/alertbox.
[33]CacheNowCampaign:http://vancouver-webpages.
com/CacheNow[34]J.
Lynch–UNIXPerformanceTuning–CMG96.
[35]Netscapepalette:www.
dsiegel.
com/tips/wonk10/images.
html.
[36]Giftutorial:www.
infohiway.
com/way/faster/gif.
html.
[37]Fastcgi:www.
fastcgi.
com.
[38]UKCMGpaperbyAdrianJohnson.
HyPerformix,Inc.
16[39]Sun'sNewWebDesign,byJakobNielsen.
[40]FortuneMagazine'slistoftopcorporateWebsites:www.
fortune.
com/fortune/buyersguide/websites/product1.
html[41]WebSiteGarage:http://websitegarage.
netscape.
com/[42]GifWizard:http://www.
gifwizard.
com/[43]DeBabelizer:http://www.
equilibrium.
com/debab/index.
html[44]ImprovingASPApplicationPerformance,byJ.
D.
Meier.
http://msdn.
microsoft.
com/workshop/server/asp/server03272000.
asp[45]ArticlebyWaynePlourde:http://www.
asptoday.
com/articles/20000113.
htm[46]ActiveServerPagesandCOMApartments:http://www.
develop.
com/dbox/aspapt.
asp[47]ImprovingWebSitePerformance:http://help.
xbuilder.
net/xbuilder/htmlhelp/general_whitepaper_improving_web_site_performance.
htm[48]XBuilder:http://www.
15seconds.
com/XBuilder.
htm[49]KimWalker:kim@kimwalker.
com[50]SiteOptimizationTutorialbyPaulBoutin:http://hotwired.
lycos.
com/webmonkey/98/26/index3a_page2.
htmltw=design)[51]ImprovingASPApplicationPerformance,byJ.
D.
Meier,MicrosoftCorporation,March28,2000,AppendixB:http://msdn.
microsoft.
com/workshop/server/asp/server03272000.
asp[52]TipstoImproveASPApplicationPerformance,bySrinivasaSivakumar,AppendixC,http://www.
15seconds.
com/issue/000106.
htm[53]ServerPerformanceandScalabilityKillers,byGeorgeV.
Reilly,MicrosoftCorporation,February22,1999:http://msdn.
microsoft.
com/workshop/server/iis/tencom.
asp[54]FireclickBlueflame:AcceleratingtheWeb:http://www.
fireclick.
com/products/whitepapers_1a.
html[55]EmailfromCraigMason,August16,2000.
[56]SpaceAgent,http://www.
insidersoftware.
com/index.
htm[57]http://webreference.
com/internet/software/http/compress.
html[58]http://webreference.
com/internet/software/http/compression.
html.
[59]http://www.
microsoft.
com/TechNet/iis/httpcomp.
asp[60]HTTPPerformanceOverviewfromW3orghttp://www.
w3.
org/Protocols/HTTP/Performance/[61]USATodayarticle:http://www.
usatoday.
com/life/cyber/tech/cti628.
htm[62]JupiterCaching.
comwhitepapers:http://www.
caching.
com/whitepapers.
htmHyPerformix,Inc.
17AppendixBImprovingASPApplicationPerformanceFromhttp://msdn.
microsoft.
com/workshop/server/asp/server03272000.
asp[51]J.
D.
Meier,MicrosoftCorporation,March28,2000IntroductionDevelopersoftenaskhowtogetmoreperformanceoutoftheirASPapplications.
BecauseIfrequentlyreviewActiveServerPages(ASP)applicationsforperformance,IfiguredI'dsharethesetofquestionsIasktoidentifyproblemsandrecommendimprovements.
Someofthesetipsmayseemlikecommonsense,whileothersmaybelessobvious;however,alloftherecommendationsarebackedbyrealworldexperience.
ASPPagePerformanceAreyoustoringVisualBasicobjectsinSessionorApplicationscopeVisualBasicandotherSingle-ThreadedApartment(STA)objectsshouldbeusedonlyatpagescope.
StoringSTAsinaSessionvariablelockstheobjectdowntothethreadthatcreatedtheobject,defeatingthepurposeofathreadpool.
StoringanSTAinApplicationscopeserializesaccessforallusers.
Seethefollowingarticlesformoreinformationonthisissue:DonBox's"ASPandCOMApartments"Q243543"INFO:DoNotStoreSTAObjectsinSessionorApplication"Q243548"INFO:DesignGuidelinesforVisualBasicComponentsUnderASP"Q243815"PRB:StoringSTACOMComponentinSessionLockstoSingleThread"AreyoustoringtheScripting.
DictionaryinSessionorApplicationscopeTheScripting.
DictionaryisApartmentthreadedandshouldbeusedonlyatpagescope,oryourapplicationwillsufferseriousserializationissues(seeQ194803"PRB:Scripting.
DictionaryObjectFailsinASPApplicationScope").
ThislimitationusuallyraisesthequestionofwhatdictionariescanbeusedatSessionorApplicationscope.
Optionsaresomewhatlimited,butincludetheCommerceDictionaryandtheLookupTableObject.
See"AbridgingtheDictionaryObject:TheASPTeamCreatesaLookup-TableObject.
"AreyourASPscriptshundredsoflineslongScriptisinterpretedlinebyline,soeliminatingredundantscriptorcreatingmoreefficientscriptcanimproveperformance.
IfyouhavehundredsoflinesofASPscriptinasinglepage,perhapsyoucanbetterpartitionyouruser,business,anddataservices.
ASPscriptisgreatforgatheringinputorformattingoutput,butwhenitcomestobusinessanddataservices,componentsoffersomeadditionalbenefits--suchasearlybindingandprotectionofintellectualproperty.
Inhisarticle"Componentvs.
ComponentPartII,"JasonTaylordiscussessignificantperformancegainshefoundportinghisASPscripttocustomcomponents,usingWindowsScriptComponents(WSC)asanintermediatestep.
Ifyouaren'tusingcomponents,youcanstillpartitionyourserviceswithfunctions.
Forexample,ifyourscriptisrenderingseveraltables,makeagenericfunctiontogenerateyourtables.
Youcanthenputthesefunctionsintoincludes,orlaythegroundworkforafutureporttocomponents.
Thefollowingsampleillustratesusingfunctionsandincludesforimprovedmaintenance.
HyPerformix,Inc.
18SubMain()WriteHeaderWriteBodyWriteFooterEndSubSubWriteBody().
.
.
EndSubMain'callsubMainAreyour#includefilestoobigTherearenohardandfastrulesforinclude-filesizes,butknowinghowincludesworkcanhelpyougaugewhetheryouareusingthemefficiently.
WhenASPprocessesincludes,itreadstheentirefileintomemory.
BecauseASPwillcachetheentireexpandedcode(yourpage+theinclude),notjustthefunctionsyoucall,youmayendupwithlarge,inefficientnamespacesthatASPmustsearchwhencallingmethodsorlookingupvariables.
Notethatthisprocessoccursforeachpagethatusestheinclude.
Agoodguideistocreatefine-grainedincludes,sothatyoucanbemoreselectiveaboutwhichpageswillincludethem.
ForamoredetailedexplanationofhowASPprocessesincludes,see"TheImplicationsofASP#include.
"AreyouusingglobalvariablesGlobalvariablesincreasethenamespaceusedbyASPtoretrievevaluesfrommemory.
Variablesdeclaredwithinsubroutinesorfunctionsarefaster.
Formoreinformation,see"25+ASPTipstoImprovePerformanceandStyle.
"DoesyourscriptexcessivelyintersperseASPandHTMLKeepblocksofASPserver-sidescripttogether,ratherthanswitchingbackandforthbetweenserver-sideandclient-sidecode.
ThisswitchingusuallyhappenswhenconcatenatingHTMLwithsimplevaluesfromASP,aswhenyouarewritingoutanHTMLtable:Counting.
.
.
Youcanimprovethecode'sbymakingitasinglescriptblock:Counting"&iCtr&""Next%>Thistechniquehasshownmeasurableandsignificantperformanceimprovements.
AreyoubufferingoutputBufferingisonbydefaultinWindows2000,butmaybeoffifyou'veupgradedfromInternetInformationServer(IIS)4.
0.
Whenbufferingison,ASPwillwaituntilprocessingiscompletebeforesendingdowntheresponse,reducingnetworkroundtripsandserver-processingdelays.
Whenbufferingisoff,ASPwaitsforTCPacknowledgementsfromclients,whichcanreallyhurtperformance,particularlyoverslowconnections.
Notethatwhilebufferingmayimprovethroughput,itmayreduceperceivedperformance.
Ifperceivedperformanceisanissue,youcanturnoffbufferingwithResponse.
Buffer=FalseoryoucancallResponse.
Flush.
HyPerformix,Inc.
19AreyouusingSessionstateASPSessionsareaconvenientfacility,buttheylimitscalability.
Sessionslimitthescalabilityofasingleboxbecausetheyconsumeresourcesforeachuser.
WhileSessionsizeislargelydeterminedbywhatyoustuffintotheSessionvariable,therealcostisresourcecontention.
Sessionsalsolimityourapplication'sabilitytoscaleoutacrossmultiplemachines,becauseeachSessionisWeb-serverspecific.
Inmanycases,youcanavoidtheuseofSessionobjectsbyusinghiddenformfieldsorpassingdatainyourQueryStrings(seeQ175167"HOWTO:PersistingValuesWithoutSessions".
Theseapproacheswillallowyoutoscaleoutbutmaybecomemoredifficulttocodeasthestructureofthedatagrowsincomplexity.
Anotherpossibilityistouseadatabase.
Thisissuitableformorecomplexstructures,suchasashoppingcart.
Youcanstoreyourshoppingcartinadatabaseandlookitupasrequired.
ManylargecommercesitestakethisapproachbytransmittingauniqueIDtotheuserandlookingupinformationfromthedatabasewhenneeded.
Thisapproachwillallowyoutoscaleouttransparently.
ItwillalsoletyourWebserversscaletomoreusers,anditwillmakethecartspersistentbetweenrequests.
Manydevelopersoverlookthisapproach,becausetheybelievethecostofreconnectingtothedatabasewillhurtperformance,butthat'swherepoolingcomesintoplay(moreonpoolingbelow).
HaveyoudisabledSessionstateifyouaren'tusingitIftheapplicationdoesn'trelyonSessions,disableSessionstatefortheWeborvirtualdirectorythroughtheISM(InternetServicesManager).
DisablingSessionstateallowsASPtoskipanextensiveamountofsourcecode,reducingoverhead.
IfyouneedSessionstateenabledforyousite,youcanpreventASPfromunnecessarilycheckingforSessioninformationonspecificpagesbyusingthefollowingpagedeclarative:@EnableSessionState=FalseYoumightdothisonpagesthatuseframes.
ASPserializesconcurrentrequestsfromthesamesession,causingASPpagesinframestoloadsequentially.
IfyouturnoffSessionswith@EnableSessionState,frameswillloadconcurrently.
Areyouusingthird-partycomponentsdesignedforASPAskyourthird-partycomponentvendorwhetherthecomponentwasbothdesignedandtestedforASP.
"TroubleshootingComponentsUnderASPTechnology"providessomeguidelinesforASPcompliance.
AreyouusingsomeformofcachingfordataCachingisoneofthemostdifficultaspectsofWebapplicationdevelopment,becauseitthreatensthescalabilityofyourapplication.
Determiningwhattocacheisbasedondatavolatilityandscope.
Datathatisstaticorusedapplication-widecanbeagoodcandidateforcaching.
Datathatchangesfrequentlyorisuser-specificwouldnotbeagoodcandidate.
Determiningwhereinyourapplicationyoushouldcacheyourdataisbasedonyourapplicationgoals,andyouneedtoknowthetrade-offs.
Forexample,cachinganActiveXDataObjects(ADO)Recordsetoffersflexibility,becauseyoucanstillgrabanarrayorsavetherecordsetasXML.
However,ifyourapplicationwillberenderingthesameHTMLrepeatedly,suchastodisplayalistboxofcountries,youmightcachetheHTMLstringinApplicationscope,ratherthanjustthedata.
XMLhascertainlyopenedupnewdoorsintermsofcachingflexibility.
Forexample,youmightstoredataasXMLstringsandapplyXSLtransformationasrequired.
Foramorethoroughinvestigationofthistopic,seePaulEnfield'sarticle"UsingServer-SideXSLforEarlyRendering:GeneratingFrequentlyAccessedData-DrivenWebPagesinAdvance.
"HyPerformix,Inc.
20Agoodstresstestearlyinyourdesigncanhelpyoudeterminewhichcachingtechniquetouse.
AreyouusingCDOIfyou'reusingWindowsNT4.
0,useCDO-NTSandNTSP5orlater(seeQ214685XFOR:CDONTSNotThread-Safe,CrashesUnderStress).
CollaborationDataObjects(CDO)wasnottestedforserver-sideuse,exceptinthecaseofOutlookWebAccess.
InWindows2000,use"CDOforWindows2000,CDOSYS.
dll,whenpossible,whichisdesignedforserver-sidedevelopment.
Seethefollowingarticles:"CollaborationDataObjectsRoadmap"Q195683"INFO:Relationshipbetween1.
xCDOLibrariesandCDOSYS.
DLL"Q177850"INFO:WhatistheDifferenceBetweenCDO1.
2andCDONTS"AreyouredimensioningarraysItisgenerallymoreexpensivetoredimensionarraysthanitistograbmorethanyouneedupfront.
RedimensioningarraysrequiresVisualBasicScriptingEdition(VBScript)toallocatespaceforthenewarray--and,ifyou'veusedthePreservemodifiertopreservethecontentsofthearray,tocopythedatafromtheoldarrayintothenew.
Thismeansthatnotonlyareyouspendingextraprocessorcyclestoredimensionthearray,buttheprocessinitiallyrequirestwiceasmuchmemoryforthecopy.
However,ifyouallocatemorespacethanyouneedinitially(youneedonlyfiveelementsinitially,butallocatespacefor128),thenaddingmoredatatothearrayrequiresVBScripttoinsertonlythenewvaluesintotheexistingarray.
AreyouusingmultiplelanguagesonapageMultiplelanguagesonagivenpagemeanmultiplescriptenginesforthatpage.
ScriptenginesuseThreadLocalStorage(TLS),somultiplethreadscannotuseaninstanceofascriptengineconcurrently.
Therefore,fivesimultaneousrequeststothesamepagewillcauseASPtoinstantiatefivescriptengines.
Moreenginesmeansmoreoverhead,soyoumaybeabletogainsomeperformancebylimitingyournumberoflanguagesusedonagivenpage.
AreyoucheckingResponse.
IsClientConnectedbeforeprocessinglongroutinesBytestingResponse.
IsClientConnectedyourapplicationcanavoidwastingCPUcyclesbyquittingmethodsiftheclientisnolongerconnected.
NotethatIIS5.
0overcomesalimitationinIIS4.
0(theneedtosendcontenttothebrowserbeforecheckingtheproperty).
Forsamplecode,refertoQ182892"HOWTO:UseIsClientConnectedtoCheckIfBrowserisConnected.
"AreyouusingServer.
MapPathunnecessarilyWhenyourequestServer.
MapPath,youaregeneratinganadditionalrequestfortheservertoprocess.
Toimproveperformance,replaceServer.
MapPathwithafullyqualifiedpathwhendeployingyourWebsite.
AreyouparsingstringsUseregularexpressionsinvalidationroutines,informattingfunctions,andinsteadofloopingthroughstrings.
See"StringManipulationandPatternTestingwithRegularExpressions"forpracticaladviseonusingregularexpressions.
AreyouusingthesameobjectmanytimesVBScript5.
0providestheWithstatement.
TheWithstatementallowsyoutoexecuteaseriesofstatementsonaspecificobjectwithoutrequalifyingthenameoftheobject.
Formoreinformation,seetheWindowsScriptTechnologiesWebsite.
HyPerformix,Inc.
21Doestheglobal.
asacontainemptySession_OnStartorSession_OnEndmethodsStrippingoutemptySessioneventsreducestheamountofsourcecodethatASPmusttraverse,andimprovesperformance.
ComponentPerformanceAreyoustoringyourobjectsinSessionorApplicationscopeStoringreferencestoobjectsinASP'sSessionorApplicationscopewillcausemanyperformanceandscalabilityissuesifthoseobjectsaren'tdesignedtobesharedacrossthreadsoractivities.
Onlyagilecomponents--or,inWindows2000,componentsmarkedNeutral--canbereferencedinSessionorApplicationvariableswithdirectaccessbyclientthreads.
ComponentsareconsideredagileiftheyaremarkedBothandaggregatethefree-threadedmarshaler(FTM).
See"AgilityinServerComponents"foradiscussiononhowtoaggregatetheFTM.
ComponentswithotherthreadingmodelsimposerestrictionswhenstoredinSessionorApplicationscope.
Asmentionedearlier,VisualBasicorotherSTAcomponentsshouldonlybeusedwithinpagescope.
NotethatsolidlywrittenVisualBasiccomponentscanperformextremelywellifyoufollowthisrule.
Single-andFree-threadedcomponentsarenotrecommended,becauseofsecurityissuesandexpensiveproxy/stubsthatgetcreatedwhenmarshalingacrossapartmentboundaries.
Seethefollowingarticlesforadditionalinformation:"ASPComponentGuidelines"Q243544"INFO:ComponentThreadingModelSummaryUnderASP"Q150777"INFO:DescriptionsandWorkingsofOLEThreadingModels"AreyouconcatenatingstringsincomponentsUsefixed-lengthstringsinVisualBasicforstringconcatenation.
Don'tjustkeepaddingtoastring,oryou'llreallocateitmultipletimes--andreallocationisexpensive.
Bad:PublicFunctionBadConcatenation()AsStringDimintLoopAsIntegerDimstrTempAsString'thiswillbeexpensiveForintLoop=1To1000strTemp=strTemp&"Counting"strTemp=strTemp&CStr(i)strTemp=strTemp&""NextintLoopBadConcatenation=strTempEndFunctionGood:PublicFunctionGoodConcatenation()AsStringDimintCtrAsIntegerDimintLoopAsIntegerDimstrTempAsString*32000'thisimprovesperformanceintCtr=1ForintLoop=1To1000Mid(strTemp,intCtr)="Counting"HyPerformix,Inc.
22intCtr=intCtr+17Mid(strTemp,intCtr)=CStr(intLoop)intCtr=intCtr+Len(CStr(intLoop))Mid(strTemp,intCtr)=""intCtr=intCtr+10NextintLoopGoodConcatenation=strTempEndFunctionSeverallarge-scalesitesfoundmajorperformancegainsfromthistipalone.
Ifyou'vegotextensivestringconcatenationinyourapplication,putthistechniquehighonyourprioritylist.
Experimentwithdifferentstringsizes,andtesttoseewhichsizewillworkbestforyourparticularroutine.
AreyouusingSQLServerforyourmiddle-tiercacheIfyouneedtocachedatathatisreadfrequentlyandseldomupdatedinthemiddle-tier,useSQLServerratherthanaroll-your-ownsolution.
SQLServerprovideshigh-performancemiddle-tiercaching.
Formoreinformation,read"Middle-TierHigh-SpeedDataCachingInvolvingCOM/MTSandCOM+.
"Areyouusingtransactionswhenyoudon'tneedtoTransactionsprovideaservice--andthatservicecanaddaperformancehit.
Evaluatewhethermethodsactuallyneedtransactions.
Forexample,ifyou'regrabbingarecordsettohandofftoabrowserclientforreadingdata,youdon'tneedatransaction.
Byfactoringoutoperationsthatreaddataintoseparatecomponentsfromoperationsthatperformupdates,youhavemoreflexibilityinmarkingyourcomponentsfortransactions.
Thefollowingarticlesprovidescalablepatternsthatyoucanuseasguidelinestohelpyoufactoroutyourowncomponents:"ScalableDesignPatterns""SimplifyMTSAppswithaDesignPattern""FMStocksApplication:StartHere"AreyoucallingSetComplete/SetAbortineachmethodCallingSetCompleteandSetAbortineachmethodofyourMicrosoftTransactionServer(MTS)componentswillreleaseresourcesearlier,andwillensurethatacomponentdoesnotliveoutsidethescopeofitstransaction.
InWindows2000,COM+providesthesetting'Automaticallydeactivatethisobjectwhenthismethodreturns,'whichperformstheequivalentcode.
Youcanenablethissettingonaper-methodbasisintheComponentServicesconsole.
Thisperformancegainismoreapplicabletolarge-scalesites,butisalsogoodform.
AreyoucreatingchildMTScomponentswithCreateInstanceInWindowsNT4.
0,useCreateInstancetocreatechildMTScomponents.
Createnon-MTScomponentsusingCreateObjectorNew(unlessthecomponentsareinthesameVisualBasicproject).
Othercombinationscausecodepathsandchecksthatcouldotherwisebeavoided.
Formoreinformation,seeTedPattison'sarticle"CreatingObjectsProperlyinanMTSApp.
"InWindows2000,thisdistinctionbetweencreatingobjectswithdifferenttechniquesgoesaway,andyousimplyuseCreateObject(seeQ250865"INFO:CreateObjectandCreateInstanceHavetheSameEffectinCOM+".
HyPerformix,Inc.
23AreyourcomponentsinServerpackagesorLibrarypackagesLibrarypackagesrunintheircaller'sprocess,whilecomponentsinaServerpackageruninanewprocess.
Assuch,Librarypackagesdonothavethecross-processperformancehitthatServerpackageshave.
AtypicalrecommendationistoruntheWebapplicationoutofprocess,buthavethecomponentsinaLibrarypackagetoprovidebothprocessisolationandhighperformance.
InsituationswhereyouneedtouseaServerpackage,aswhenyouarecallingremoteMTS/COM+components,takestepstominimizecrossprocessoverhead.
AreyoucrossingprocesseseffectivelyMinimizingmarshalingoverheadandreducingnetworkcallsarekeystoimprovingperformanceofdistributedapplications.
UseearlybindinginyourcomponentstominimizeexpensivenetworkroundtripsbyeliminatingtheextracalltoGetIdsOfNamesthatlatebindingincurs.
Youcanfurtherreducenetworktripsbybundlingyourparametersintoargumentsformethodcalls,insteadofsettingabunchofpropertiesindividually.
RatherthanpassparametersByRef,passByValwhereyoucantominimizemarshalingoverhead.
AreyouusingremotecomponentsManydevelopersfindthemselvesinsituationswheretheyneedtocallremotecomponents.
Alloftherulesforcrossingprocesseseffectivelyapply.
Anadditionalrecommendationistouseanintermediarypackage(seeQ159311"InstantiatingRemoteComponentsinMTSandIIS".
Usinganintermediarypackagetocalltheremotecomponentavoidssomesecuritycomplicationsandallowsyoutouseearlybinding.
DoyourclientandservermachinesusethesameprotocolsinDCOMAcommoncauseofactivationdelaysofremotecomponentsresultsfromtheclientandservermachineshavingdifferentDCOMprotocollists.
UseDCOMCNFG.
EXEoneachmachinetomatchtheprotocolsequence.
Forexample,ifbothmachinesareusingTCP/IP,moveTCP/IPtothetopofthelistonbothmachines.
AfewguidelinesapplywhenmodifyingyourDCOMprotocollist:MoveTCP/IPtothetopwhenyoucan.
Removeprotocolsthatyoudon'tneed.
Anychangestotheprotocollistrequireareboot.
AreyouusingASPbuilt-inobjectsfromaremotecomponentDon't.
EvenifyoucanfigureouthowtomarshaltheASPbuilt-inobjects(Request,Response,andsoforth)acrossmachines,theperformancecostoutweighsanybenefits.
AreyouusingVisualBasicVisualBasicperformsextremelywellwhenyouhavetherightversion,usetherightsettingsandfollowgooddesignguidelines:UseVisualBasic6.
0ServicePack3.
SetUnattendedExecutionandRetaininMemoryinyourprojects(SeeFigurebelow).
SeeQ186273"BUG:AVRunningVB-BuiltComponentinMulti-ThreadedEnvironment"oradditionalinformation.
ReadQ243548"INFO:DesignGuidelinesforVBComponentsUnderASP"toavoidmanycommondevelopmentmistakes.
HyPerformix,Inc.
24AREYOUUSINGMFCActiveTemplateLibrary(ATL)componentsarelighterthanMicrosoftFoundationClasses(MFC)andarepreferredforservercomponents.
MFCcodeisheavyfortheserverandmaybringaboutunexpectedserializationforstatemanagement.
Also,youcannotcreatecomponentsmarkedBoththataggregatetheFTM.
MFConlyproducesSTAobjects,whicharelimitedtopagescope.
AreyouusingJavaMakesureyouhavethelatestVirtualMachinefromhttp://www.
microsoft.
com/java/andreadQ232368"PRB:JavaThreadsBlockingwhenAccessingCOMObjects.
"AreyouwaitingforstuffthatcouldbedoneasynchronouslyIfyourASPapplicationismakinglongdatabasecallsorcallingcomponentsthatarewaitingonothercomponentstoraiseevents,considermakingthecallasynchronousthroughaqueueingmechanism,suchasMSMQ.
ForinformationonMSMQ,seethefollowing:Q173339"HOWTO:UseMSMQfromanASPPage"Q181839"Mqasp.
exeMSMQBasicQueueOperationsUsingIIS/ASP"Q243546"PRB:ASPDoesNotSupportEvents"AreyouloopingthroughlargedatasetsinthemiddletierPushmoreoftheselargeorcomplexdataoperationstostoredprocedureswhereyoucan.
DataAccessPerformanceAreyouusingindexesinyourdatabaseIndexesprovideimmediateimpactonyourapplication'sperformance.
Poorindexeswillslowyourapplicationtoacrawl,whilegoodindexeswillhelpoptimizeyourapplication'sperformance.
Forinformationontuningindexes,see"TopTenTips:AccessingSQLThroughADOandASP.
"orSQLBooksOnline.
AreyoucallingstoredproceduresratherthandynamicSQLUsingstoredprocedurespreventsyourdatabasefromhavingtorecompileyourSQLstatementsrepeatedly.
UsestoredproceduresorparameterizedSQLstrings.
AreyoureturningjusttherequireddataCheckyourSELECTstatementstoensurethatyou'rereturningonlytherequiredcolumnsandonlythenecessaryrows.
Ifyouhavequeriesthatcanpotentiallyreturnalotofrecords,considerpagingthroughyourrecordsets.
Seethefollowingarticlesformoreinformation:"RecordsetPagingwithADO2.
0""AdHocWebReportingwithADO2.
0""6WaystoBoostADOApplicationPerformance"AreyouusingDAOorRDORemoteDataObjects(RDO)andDataAccessObjects(DAO)areintendedforasingle-clientapplicationprocess,andweren'ttestedfortheWeb.
ADOisdesignedandtestedforWebuse.
HyPerformix,Inc.
25WhichversionofMDACareyouusingUpdatedversionsofMDACprovideimprovedreliabilityandperformance.
YoushouldbeusingMDACversion2.
1ServicePack2orlater.
MDAC2.
5isrecommended,becauseit'sthemoststableandit'sbeentestedextensively.
Ifyoudon'tknowwhichversionyouhaveonyourbox,youcangrabtheComponentCheckertoolfromhttp://www.
microsoft.
com/data/AreyoufollowingMDACbestpracticesSee"ImproveMDACApplicationPerformance.
"AreyoupoolingconnectionsPoolingallowsyoutoreusetheeffortofconnectingtoadatabase.
ODBCConnectionpoolingisonbydefaultinMDAC2.
0.
InMDAC2.
1orlater,OleDbSessionpoolingisthedefault.
Rememberthatinorderforpoolingtowork,theusername,password,andresourceintheconnectionstringneedtomatch(it'sabyte-by-bytecomparison).
Seethefollowingarticlesforadditionalinformationonpooling:"PoolingintheMicrosoftDataAccessComponents"Q169470"INFO:FrequentlyAskedQuestionsAboutODBCConnectionPooling"Q187874"CnPool.
exeTestConnectionPoolingwithTempdbObjects"Q191572"INFO:ConnectionPoolManagementbyADOObjectsCalledFromASP"AreyoustoringADOconnectioninSessionorApplicationscopeThisdefeatsthepurposeofconnectionpoolingandcreatesresourcecontention.
Createconnectionatpagescopeorwithinthefunctionsthatneedthem,andsettheconnectionstonothingtofreetheconnectionbacktothepool.
AreyouexplicitlyclosingRecordsetandConnectionvariablesRecordsetsneedtobeclosediftheyaregoingtobereused(butreusingrecordsetsisdiscouraged).
ClosingConnectionvariablesassoonasyoucanreleasesthembacktothepool,sothattheycanbepooledforreuse.
Itisalwaysgoodpracticetoexplicitlycloseyourobjectvariables.
AreyoureusingRecordsetandCommandvariablesCreatenewRecordsetandCommandvariablesratherthanreusingexistingones.
Thiswon'tnecessarilyimproveyourapplication'sperformancebutitwillmakeyourapplicationmorereliableandeasiertomaintain.
SeeQ197449"PRB:ProblemsReusingADOCommandObjectonMultipleRecordsets"ormoreinformation.
AreyoudisconnectingtherecordsetsDisconnectingrecordsetsfreestheConnectionobjectbacktothepool,allowingtheConnectiontobeclosedandreusedsooner.
Areyouusingtherightcursorandlock-typeforthejobUse"Firehose"(forward-only,read-only)cursorswhenyouneedtomakeasinglepassthroughthedata.
Firehosecursors,thedefaultinADO,providethefastestperformanceandhavetheleastamountofoverhead.
SeeADOdocumentationformoreinformationoncursorandlocktypes.
AreyouusingDSN-lessconnectionsIngeneral,DSN-lessconnectionsarefasterthanSystemDSNs(datasourcenames),whicharefasterthanFileDSNs.
HyPerformix,Inc.
26AreyouusingAccessMicrosoftAccessisafile-baseddatabase,sodon'texpectittoperformwellwithconcurrentusersunderIIS.
AreyouusingSQLServerUseSQLServer7.
0.
SQLServer7.
0issuperiortoearlierversionsofSQLServer,andprovidesrow-levellocking,aswellasotherperformancebenefits.
You'veheardSQLscales--butforproof,seehttp://www.
tpc.
org/andreadJimGray'spaperathttp://research.
microsoft.
com/scalable/AreyouusingTCP/IPforyournetworklibraryUseTCP/IPforyournetworklibraryforperformanceandscalability.
AreyouusingtheOLEDBSQLproviderTheSQLOLEDB,theSQLprovider,isrecommendedoverMSDASQL,theOLEDBproviderforODBCforperformanceandreliability.
AreyouusingOracleOracleperformancereallydependsonacombinationoftherightMDACbitswiththecorrectOracleclientpatches.
Ifyou'reusingOracle,takethetimetoreadthefollowingarticles:"MicrosoftOLEDBProviderforOracle:Tips,Tricks,andTraps""Fitch&MatherStocks:DataAccessLayerforOracle8"Ifyou'reusingOracleandMTS,besuretoreviewthefollowingarticles:Q193893"INFO:UsingOracleDatabaseswithMicrosoftTransactionServer"Q191168"INFO:FailedtoEnlistonCallingObject'sTransaction"AreyouusingthesamedatabaseforreportingandtransactionsManylargeWebsitesmaintainseparatedatabasesforread-onlyandtransactionaldataasaneffectivewaytoboostperformance.
Thishastheaddedbenefitofallowingyoutodesignyourdatabaseschematobeoptimizedforreporting.
IISSettingsIsASPdebuggingenabledChecktheISM.
IfASPdebuggingisenabled,theapplicationislockeddowntoasinglethreadofexecution.
SeeQ216580"PRB:Blocking/SerializationWhenUsingInProcComponent(DLL)fromASP.
"IsASPconfiguredtohaveenoughthreads/scriptenginesRead"TheArtandScienceofWebServerTuningwithInternetInformationServices5.
0"and"NavigatingtheMazeofSettingsforWebServerPerformanceOptimization.
"AreyouusingSSLSecureSocketsLayer(SSL)isexpensiveintermsofbandwidthandCPUusage.
Ifyou'reusingSSL,it'sbecauseofsecurityneeds.
YourbestbetistorestrictSSLusagetowhereyouneedit,andkeepthepagessimple.
StressTestingIt'sacommonmisconceptionthatperformanceequalsscalability.
PerformanceforASPmeanstherateatwhichpagescanbeserved.
Scalabilityismeasuredbyhowmuchperformancedegradesunderadditionalload.
Toputthesetermsinperspective,yourASPapplicationmayperformwellwith10users,butdoesnotscaleto1000users,becauseperformancebecomesunacceptable.
UsestresstestingtomeasuretheHyPerformix,Inc.
27performanceandscalabilityofyourASPapplication.
FormoreinformationonscalabilityofWinDNAapplications,see"ABlueprintforBuildingWebSitesUsingtheMicrosoftWindowsDNAPlatform.
"WhatareyourperformanceexpectationsPerformancecanbemeasuredintermsofthenumberofASPrequestspersecondthatyourserverscanhandle.
UsingASP'sperformancecounter,ASPRequestsPerSecond,youcansetbenchmarkstomeasureagainst.
AreyoutryingtostresstestwithabrowserStresstestingwithabrowsermaybethrowingoffyourresults.
Asmentionedearlier,ASPwillserializeconcurrentrequestsfromthesameSession.
Forexample,ifCookiesareenabledandyou'rehittingtheserverfromonemachine,thenthoserequestswillserialize.
UsetheWebApplicationStresstool(WAS--formerlyknownasHomer).
ForanintroductiontoWAS,see"ICan'tStressItEnough--LoadTestYourASPApplication.
"Haveyouperformedend-to-endtestingWhileit'simportantandfeasibletostresstestyourdatabase,components,andASPlayersseparately,endtoendtestingishowyou'llfindyourapplication'srealbottlenecks.
ConclusionReviewingASPapplicationsforperformancemeanstakingalookatseveralthings.
Bybreakingtheapplicationdownintoitsvariouslayers,youcanbuildaframeworkforanalyzingperformanceissues.
Whiletherearemanyguidelinesandrecommendations,nothingreplacesstresstestingyourapplicationandusingsoundjudgment.
HyPerformix,Inc.
28AppendixCTipstoImproveASPApplicationPerformanceFromhttp://www.
15seconds.
com/issue/000106.
htm[52]BySrinivasaSivakumarIntroductionPerformancetuningcanbetricky.
It'sespeciallytoughinInternet-relatedprojectswithlotsofcomponentsrunningaround,likeHTMLclient,HTTPnetwork,Webserver,middle-tiercomponents,databasecomponents,resource-managementcomponents,TCP/IPnetworks,anddatabaseservers.
Performancetuningdependsonalotofparametersandsometimes,bychangingasingleparameter,performancecanincreasedrastically.
PerformanceIssuesASPapplicationperformanceinvolvestwoparts:HTMLpageperformanceResponsetimeFurther,wecanboildownresponserimeto:ASPpageperformanceNetworkbandwidthDatabaseissuesLet'sseeeachofthemindetail.
HTMLPagePerformanceHTMLpageperformanceispurelyaclientproblem.
Thisproblemcanberelatedtotheclient'shardwareandthebandwidth.
Apartfromthese,therearefewotherfactorsthatcanaffectthepageperformance.
Asweallknow,thesmallerthefilesize,thebettertheperformance.
HereareafewelementsthatcanreducetheHTMLfilesize,whichwillimprovethepageloadperformanceinthebrowser.
Avoidlotofimages.
Whenabrowserrequestsapage,itmakesNnumberofcallstotheWebservertodisplayNnumberofimages.
Thiswillslowdownthepageloadprocess.
Whenyoucan'tavoidmultipleimages,trytoshowtheimagesasthumbnails.
Framesareanotherelementsthatwillslowdowntheloadprocess.
Forframesalso,therewillbeNnumberofrequeststodisplayNnumberofframes.
Ifyoucanavoidtables,that'sgoodnews.
Butwecan'talwaysdothat,sotrytoavoidnestedtables.
Thiswillboosttheloadperformance.
Ifyouknowyourusers,youcandesignbetterpages.
Well,thisisnotpossibleintheInternet.
But,ifyouaredevelopinganIntranetproductforacorporation,thenthecorporationwillhaveastandardbrowser.
Forexample,ifthecorporation'sstandardbrowserisa4.
0browserthenyoucanavoidsomecomplextablesandyoucanuseCascadingStyleSheetstopositionyourHTMLelements.
Avoidredundanttags.
Let'stakethefollowingexample:HyPerformix,Inc.
29YoucanavoidthetagSource2:Avoidlotofjazzycomments.
Thiswillreducethefilesize.
IhatetoleavecommentsintheHTMLpage.
Thiswillallowtheotherstheviewmypageandunderstandmystyle.
Avoidlongfilenamesanduserelativepathnamestoidentifyotherfiles.
EvenyoucanreducetheformattingandindentingfortheHTMLpage.
Thiswillminimizethepagesize.
SomeoftheWYSIWYGHTMLeditorswillputlotofunwantedHTMLtagsinthepage.
So,it'sagoodideatocleanuptheunwantedtags,onceyouhavedesignedyourpagewiththeWYSIWYGeditor.
AvoidJavaAppletsintheHTMLpages,whentheyarenotneeded.
Forexample,ifyouareonlyusingtheJavaAppletsforanimations,thentrytouseanimatedgiffilesoraFlashanimation.
TheyarefasterthanJavaApplets.
ASPPagePerformance1.
Readingfromtheobjectvariableisalwaysslowerthanreadingfromthelocalvariable.
So,ifyouaregoingtoreadfromtheobjectvariableoften,thenstoreitinalocalvariableandaccessit.
Slower:ifMyobj.
Value=0thenDosomethingelseifMyobj.
Value>0thenDosomethingelseifMyobj.
Value0thenDosomethingelseifMyVar.
7.
Enablingbufferingwillimprovetheperformance,likeResponse.
Buffer=True.
8.
Wrapallyourdata-accesscodeinsideaCOMcomponent.
Inthiswayyoucantakeadvantageofspeedofthecompiledandmultithreaded.
Asyouknow,creatingadatabaseconnectiontakeslotsofsystemresourcesandtime.
Youcanavoidthistime-lagbytakingadvantageoftheconnectionpooling,whenyourcomponentrunsinsidetheMicrosoftTransactionServer(MTS).
MTSisaWindowsNT-basedtechnologythatwhenusedwithDistributedCOM(DCOM),letsyoubuildCOMobjectsthataremoreeasilydistributedacrossanetworkthanwhenusingDCOMalone9.
AvoidmultiplecallstotheCOMcomponent.
Forexample,ifyouwanttowrite10valuestoaCOMcomponent,youwilldoitwith10callstothecomponent.
However,ifyoucandoitwithonecall,thenthatwillimprovetheperformance.
Slower:Myobj.
FirstName="Srinivasa"Myobj.
LastName="Sivakumar"Myobj.
City="Chicago"Faster:Insteadofexposing3propertiesfromtheCOMcomponent,youcanexposeasinglepropertycalled"Value,"andyoucantakeadvantageofthesinglecall.
Let'sseehowthecodewilllookintheCOMcomponent:Declaretheprivatevariablestoholdthevaluesoftheproperties.
Declarethreemoreconstantstoholdthepropertyvaluepositioninthearray.
OptionExplicit'LocalvariablestoholdpropertyvaluesPrivatemvarFirstNameAsStringPrivatemvarLastNameAsStringHyPerformix,Inc.
31PrivatemvarCityAsString'PropertyValueConstantsPrivateConstCN_FirstName=0PrivateConstCN_LastName=1PrivateConstCN_City=2Addthe"Value"propertyprocedure.
PublicPropertyLetValue(ByValvDataAsVariant)OnErrorGoToErrHand'CheckiftheparametervalueisanarrayIfIsArray(vData)=FalseThenErr.
Raise100,App.
Title&"-PropertyLet:Value","Invalidpropertyvalue.
Anarrayisexpected.
"GoToCleanExitElsemvarFirstName=vData(CN_FirstName)mvarLastName=vData(CN_LastName)mvarCity=vData(CN_City)EndIfCleanExit:ExitPropertyErrHand:Err.
RaiseErr.
Number,Err.
Source,Err.
DescriptionExitPropertyEndPropertyHereishowyouwillcallthemethodfromtheASPpage.
Myobj.
Value=Array("Srinivasa","Sivakumar","Chicago")EvenyoucanwritetheGetpropertyproceduretopassthedatafromthecomponenttotheASPapplicationwithasinglecall.
Note:Alwayshaveerrorhandlersinallyourfunctions,subs,properties,etc.
Thiswillavoidthewholesystemgoingdownwhenanerroroccursinthecomponent.
Evenanerrorinacomponentcouldbringalltheapplicationsdowninthesamememoryspace.
ItcouldbringtheInternetInformationServer(IIS)down,ifthecomponentisrunningintheIISmemoryspace.
10.
Never,everdeclareaCOMcomponentsuchasanADOconnectionobjectwiththeapplicationorsessionscope.
Thiswillalsohittheperformancebecauseofthethreadingeachcallhastobemarshaledbetweenthreads.
11.
TheApartment-ThreadedCOMcomponentobjectsareonlygoodforpagescope.
IfyouwanttoaccesstheCOMobjectsacrossthepage,thenconsiderthefree-threadedorboththreadedcomponents.
Note:YoucanonlydevelopApartment-ThreadedcomponentsinVisualBasic.
Ifyouareseriousaboutthefree-threadedcomponent,thenyouhavetodeveloptheminVC++orinJava.
12.
DonotuseOnStartPageandOnEndPagemethodstoaccesstheASPintrinsic.
ThesemethodsareprovidedforlegacysupportwithIIS3.
Insteadofthis,usetheObjectContextwithImplementskeyword.
HyPerformix,Inc.
3213.
Whenyouareaccessingthecomponentacrosstheprocessormachine,passthevariablestotheobjectsasByVal.
ThiswillreducetheMarshalingoverhead.
14.
Whenyouhavemorethan100linesofcodeinASP,itisadvisabletomovethatcodetoaCOMcomponent.
ASPscriptsareinterpretedatruntimeandCOMcomponentsarecompiled.
Note:Thereisatime-lagforthecomponenttobeinitialized,upandrunning.
Thiscouldalsoaffecttheapplicationperformance,sobecarefulbeforemakingthedecisionbetweentheASPscriptandCOMcomponent.
15.
NeverusecomponentssuchasMicrosoftWordorExceltomanipulatethedata.
Theyareout-of-processcomponentsandtheyarenotoptimizedforperformance.
16.
Theotheradvantageofthecomponentoverthescriptisearlybindingvs.
latebinding.
17.
AsaWebdeveloper,wealwaysliketocreatealargeIncludefilethatwillincludealltheglobalcodeandconstants.
Theproblemwiththisapproachissomeofthecodeorthedeclarationwillnotbeusedineverypage.
SoforeachandeverypagetheseIncludefileswillbeprocessedandthiswilldefinitelyslowdownthepageperformance.
18.
AvoidmultipleRequest.
Writestatementsandgroupthemintofew.
Slower:'AddadefaultSelectWordResponse.
Write"(SelectaProgramManager)"¨DoWhileNotobjRs.
EOFResponse.
Write""&objRs!
ProjMan&""objRs.
MoveNextLoopResponse.
Write""Faster:DimstrHTML'AddadefaultSelectWordstrHTML="(SelectaProgramManager)"DoWhileNotobjRs.
EOFstrHTML=strHTML&""&objRs!
ProjMan&""objRs.
MoveNextLoopstrHTML=strHTML&""Response.
WritestrHTMLNetworkBandwidthIssues1.
InmostcasesnetworkperformancecanruintheASPperformance.
Use10/100networkcardsforbetterperformance.
2.
IfyourWebserverandthedatabaseserverarerunninginthesameserver,thenitisadvisabletomovethemintodifferentservers.
3.
Evenyoucanintroduceanewmiddle-tierservertohandletheCOMcomponentswithMTS.
ThisdecisiontotallydependsontheloadontheWebandMTSservers.
HyPerformix,Inc.
33DatabaseIssuesWell,agooddatabasedesigncancontributealottotheperformance.
Databasedesignissuesareoutofthescopeofthisarticle.
Let'sseefewpointsthatcouldimprovethedatabaseperformance.
1.
Wheneveryouaccessthedatabase,avoidthedynamicSQLandusestoredproceduresordatabaseviews.
BeforefinalizingtheSQLstatementforthestoredprocedureorview,analyzetheSQLqueryandmakesureitisoptimized,andalsomakesurethatitusestheproperindicesforrecordscanning.
Note:IfyouareusingSQLServer7orlater.
thenyoucantakeadvantageofthevisualoutputofthe"QueryAnalyzer.
"2.
ThejointypeusedintheSQLstatementwillalsoincreaseordecreasetheperformanceofthequery.
3.
WhenusingtheADORecordsetobjects,usethepropercursortypeandlocktype.
Forexample,ifyouaregoingtofillacombobox,thenyoucanusethecursortypeadOpenForwardOnlyandlocktypeadLockReadOnly.
4.
Sometimesallocatingappropriatedatabasebufferswillincreasetheperformance.
Forexample,ifyouareworkingwiththeOracledatabase,foreachconnectionyoushouldhavethreesessionsopen.
Ifyoucanfine-tunethesethings,you'llgetdrasticperformanceincrease.
5.
Ifyoursitehaslotofhitsandyourservercan'thandletheentireload,thenreplicatetheASPapplicationandthedatabase.
Note:Whiledesigningthedatabase,youhavetomakeappropriatedesignconsiderationsfordatabasereplication.
Whenwearereplicatingthedatabases,fewelementswillnotbereplicated.
Forexample,ifyouareusingOracleasthedatabaseserver,DatabaseSequenceswillnotbereplicated.
So,ifyouarerelyonDatabaseSequencesforyourprimarykey,thenyouareintrouble.
SummaryWhenwetalkaboutASPperformance,therearelotsoffactorsandIhavediscussedeachofthemindetail.
Butdon'tthinkthatifyoucanfixallthesefactors,yourASPperformancewillincrease.
AllthesetipswillnotsuiteachandeveryASPapplication.
Wehavetoconsidertheminapplicationbyapplicationbasis.
Well,makesometimetoreadthebook"MicrosoftInternetInformationServerResourceKit"fromMSPress.
Trythesefollowingformoreinformation:ImprovingWebSitePerformanceServerPerformanceMicrosoftWebCapacityAnalysisToolSimulatingCookieswiththeMungerHyPerformix,Inc.
34AppendixDServerPerformanceandScalabilityKillersFromhttp://msdn.
microsoft.
com/workshop/server/iis/tencom.
asp[53]GeorgeV.
Reilly,MicrosoftCorporation,February22,1999TheTenCommandmentsofKillingServerPerformanceFollowingeachofthese"commandments"willeffectivelyhampertheperformanceandscalabilityofyourcode.
Inotherwords,thesecommandmentsshouldbebrokenwheneverpossible!
Iexplainwhyandhowtobreaktheminordertoimproveperformanceandscalability.
1.
Thoushaltallocateandfreelotsofobjects.
Youshouldavoidexcessiveallocation,becausememoryallocationcanbecostly.
Freeingblocksofmemorycanbeevenmorecostly,asmostallocatorsattempttocoalesceadjacentblocksoffreedmemoryintolargerblocks.
UntilthereleaseofWindowsNT4.
0servicepack4,thesystemheapoftenperformedbadlyinmultithreadedprocesses.
Theheapwasprotectedbyasinglegloballockandscalednegativelyonmultiprocessorsystems.
2.
Thoushaltnotthinkaboutprocessorcache.
Mostpeopleknowthathardpagefaultscausedbythevirtualmemorysubsystemareexpensiveandbestavoided,butstillbelievethatallothermemoryaccesspatternsareequallygood.
Thishasnotbeentruesincethe80486wasintroduced.
ModernCPUshavebecomesomuchfasterthanRAMthattheyneedatleasttwolevelsofmemorycache.
OnPentium-classmachines,thefastL1cacheholds8KBofdataand8KBofinstructions,whiletheslowerL2cacheholdsseveralhundredKBofmixedcodeanddata.
AreferencetoamemorylocationfoundintheL1cachecostsonecycle,referencestotheL2cachecostfourtosevencycles,whilereferencestomainmemorycostdozensofprocessorcycles.
Thelatterfigurewillsoonexceed100cycles.
Inmanyways,thecachesarelikeasmall,fast,virtualmemorysystem.
Thefundamentalunitofmemoryasfarasthecachesareconcernedisnotabyte,butacacheline.
Pentiumcachelinesare32byteswide,Alphacachelinesare64byteswide.
Thismeansthatthereareonly512slotsforcodeanddataintheL1cache.
Ifdatathatisusedtogether(temporallocality)isnotstoredtogether(spatiallocality),itcanleadtopoorperformance.
Arrayshaveexcellentspatiallocality,whilelinkedlistsandotherpointer-baseddatastructurestendtohavepoorlocality.
Packingdataintothesamecachelineusuallyhelpsperformance,butitcanalsohurtperformanceonmultiprocessorsystems.
Thememorysubsystemworkshardtokeepthecachescoherentbetweenprocessors.
Ifaread-onlydatum,usedbyalloftheprocessors,sharesacachelinewithadatumthatisbeingupdatedfrequentlybyoneoftheprocessors,thecacheswillspendalotoftimeupdatingtheircopyofthecacheline.
Thishigh-speedgameofPing-Pongisoftenreferredtoas"cachesloshing.
"Iftheread-onlydatawereinadifferentcacheline,thissloshingcouldbeavoided.
Optimizingcodeforspaceismoreeffectivethanoptimizingforspeed.
Smallercodefitsinfewerpages,leadingtoasmallerworkingsetandfewerpagefaults,anditfitsinfewercachelines.
However,certaincorefunctionsshouldbeoptimizedforspeed.
Useaprofilertoidentifythesefunctions.
3.
Thoushaltnevercachefrequentlyuseddata.
Softwarecachingcanbeusedbyallkindsofapplications.
Whenacalculationisexpensive,youstoreacopyoftheresult.
Thisistheclassicspace-timetradeoff:Sacrificesomememorytosavesometime.
Ifdonewell,itcanbeextremelyeffective.
HyPerformix,Inc.
35Youmustcachejudiciously.
Ifyoucachethewrongdata,you'rewastingmemory.
Ifyoucachetoomuch,you'llhavelessmemoryforotheroperations.
Ifyoucachetoolittle,thecachewillbeineffectivebecauseyou'llhavetorecalculatethedatamissedbythecache.
Ifyoucachetime-sensitivedatafortoolong,itwillbecomestale.
Serversgenerallycaremoreaboutspeedthanspace,sotheycachemoreaggressivelythandesktopsystems.
Besuretoinvalidateandflushunusedcacheentriesperiodically;otherwiseyou'llhaveworkingsetproblems.
4.
Thoushaltcreatelotsofthreads.
Themore,themerrier.
Tuningthenumberofthreadsactiveinaserveriscritical.
IfthethreadsareI/O-bound,they'llspendmuchoftheirtimeblocking,waitingforI/Otocomplete—andablockedthreadisathreadthat'snotdoingusefulwork.
Addingadditionalthreadscanincreasethroughput,butaddingtoomanythreadswilldecreaseserverperformance,becausecontextswappingwillbecomeasignificantoverhead.
Therateofcontextswitchesshouldbekeptlowforthreereasons:contextswitchesarepureoverheadandcontributenothingusefultotheapplication'swork;contextswitchesuseupvaluablecycles;andworstofall,contextswitchesleavetheprocessor'scachesfullofstaledata,whichisexpensivetoreplace.
Muchdependsuponyourthreadingarchitecture.
Onethreadperclientisalmostneverappropriate,asitdoesnotscalewelltolargenumbersofclients.
ContextswitchingbecomesintolerableandWindowsNTrunsoutofresources.
Athreadpoolmodel,whereapoolofworkerthreadsconsumesaqueueofrequests,worksbetter.
Inthefuture,youwillnolongerneedtowriteyourownthreadpool,becauseWindows2000providessuitableAPIs,suchasQueueUserWorkItem.
5.
Thoushaltusegloballocksfordatastructures.
Theeasiestwaytomakedatathread-safeistosurrounditwithonebiglock.
Forsimplicity,makeeverythingusethesamelock.
There'saproblemwiththisapproach:serialization.
Everythreadthatneedstomanipulatethedataisgoingtohavetowaitinlinetoacquirethelock.
Ifathreadisblockedonalock,it'snotdoingusefulwork.
Whentheserverisunderlightload,thisisseldomaproblem,becauseonlyonethreadislikelytowantthelockatatime.
Underheavyload,ahigh-contentionlockcanbecomeahugeproblem.
Consideranaccidentonamultilanefreeway,whereallthetraffichasbeendivertedintoonelane.
Iftrafficislight,thediversionwillhaveanegligibleeffectontherateoftrafficflow.
Whentrafficisheavy,thetrafficjamwillstretchformilesasthecarsslowlymergeintothesinglelane.
Severaltechniquescanreducelockcontention.
Don'tbeoverprotective,thatis,don'tlockdatawhenyoudon'thaveto.
Holdlocksforjustaslongasyouneedthem,andnolonger.
Itisimportantnottoholdlocksunnecessarilyaroundlargesectionsofcodeorinfrequentlyexecutedsectionsofcode.
Partitionyourdatasothatit'sprotectedbyasetofdisjointlocks.
Forexample,asymboltablecouldbepartitionedonthefirstletteroftheidentifiers,sothatmodifyingthevalueofasymbolwhosenamestartswithQdoesnotinterferewithreadingthevalueofasymbolwhosenamestartswithH.
UsetheInterlockedfamilyofAPIs(InterlockedIncrement,InterlockedCompareExchangePointer,etc.
)toatomicallymodifydatawithoutacquiringalock.
Usemulti-reader/single-writerlockswhenthedataisn'tmodifiedoften.
You'llgetbetterconcurrency,thoughthelockoperationswillbemoreexpensiveandyoumayriskstarvingwriters.
Usespincountsoncriticalsections.
SeetheSetCriticalSectionSpinCountAPIintroducedintheWindowsNT4.
0servicepack3.
UseTryEnterCriticalSectionanddosomeotherusefulworkifyoucan'tacquirethelock.
Highcontentionleadstoserialization,whichleadstolowCPUutilization,whichencouragesuserstoaddmorethreads,whichmakesmattersevenworse.
HyPerformix,Inc.
366.
Thoushaltnotpayattentiontomultiprocessormachines.
Itcanbeanastysurprisetofindthatyourcodeperformsworseonamultiprocessorsystemthanitdoesonauniprocessorsystem.
ThenaturalexpectationisthatitwillperformNtimesbetteronanN-waysystem.
Thereasonforthepoorperformanceiscontention:lockcontention,buscontention,and/orcachelinecontention.
Theprocessorsarefightingovertheownershipofsharedresourcesinsteadofdoingproductivework.
Ifyou'reatallseriousaboutwritingmultithreadedapplications,youshouldbestress-testingandperformance-testingyourapplicationonmultiprocessorboxes.
Uniprocessorsystemsprovideacoarse-grainedillusionofconcurrencybytime-slicingtheexecutionofthreads.
Multiprocessorboxeshavetrueconcurrency,andraceconditionsandcontentionsarefarmorelikelytoarise.
7.
Thoushaltuseblockingcallsallthetime;theyarefun.
SynchronousblockingcallstoperformI/Oareappropriateformostdesktopapplications,butthey'reapoorwaytoexploittheCPU(s)onaserver.
I/Otakesmillionsofcyclestocomplete;cyclesthatcouldbeputtogooduse.
YoucanachievesignificantlyhigherratesofclientrequestandI/OthroughputbyusingasynchronousI/O,atacostofadditionalcomplexity.
IfyouhaveblockingcallsorI/Ooperationsthatcantakealongtime,youshouldthinkabouthowmanyresourcesyouwanttocommit.
Doyouwantallthethreadstobeused,oronlyalimitedsetIngeneral,itisbettertousealimitedsetofthreads.
Buildasmallthreadpoolandaqueue,andusethequeuetoscheduleworkforthethreadstocompletetheblockingcalls.
Thiswillenableyourapplicationtoleaveotherthreadsavailabletopickupandprocessnew,non-blockingrequests.
8.
Thoushaltnotmeasure.
Whenyoucanmeasurewhatyouarespeakingabout,andexpressitinnumbers,youknowsomethingaboutit;butwhenyoucannotexpressitinnumbers,yourknowledgeisofameagerandunsatisfactorykind;itmaybethebeginningofknowledge,butyouhavescarcelyinyourthoughtsadvancedtothestateofscience.
LordKelvin(WilliamThomson)Withoutmeasurements,youdonotunderstandyourapplication'sperformance.
Youaregropingblindly,makinghalf-informedguesses.
Youhavenotidentifiedyourperformanceproblemsandyoucannotbegintomakeanyimprovementsordocapacityplanning.
Measurementencompassesblack-boxmeasurementandprofiling.
Black-boxmeasurementmeansgatheringthenumbersexposedbyperformancecounters(memoryusage,contextswitches,CPUutilization,etc.
)andexternaltestingtools(throughput,responsetimes,etc.
).
Toprofileyourcode,youcompileaninstrumentedversionofyourcodeandrunitthroughvariousscenarios,gatheringstatisticsonexecutiontimeandprocedurecallfrequency.
Measurementisoflittleuseifitisnotcomplementedbyanalysis.
Measurementwilltellyouthatyouhaveproblemsanditmayevenhelpyouisolatewherethoseproblemsare,butitwon'ttellyouwhyyouhaveproblems.
Analyzetheproblemssothatyoucandeterminehowtofixthemproperly.
Addresstheunderlyingproblemsandnotjustthesymptoms.
Whenyoumakeyourchanges,measureagain.
Youneedtolearnifyourchangeswereeffective.
Thechangesmayunmaskotherperformanceproblems,andthecycleofmeasure-analyze-fix-measurewillbeginanew.
Youmustalsomeasureregularlytocatchperformanceregressions.
HyPerformix,Inc.
379.
Thoushaltusesingle-client,single-requesttesting.
AcommonmistakeforpeoplewritingASPandISAPIapplicationsistotesttheirapplicationsbyusingasinglebrowser.
WhentheydeploytheirapplicationsontheInternet,theydiscoverthattheycannotcopewithhighloadsandthattheyhavemiserablethroughputandresponsetimes.
Testingwithabrowserisnecessary,butnotsufficient.
Iftheserverdoesnotrespondquicklyenough,youknowyouhaveaproblem.
Butevenifitissnappywhenyou'reusingasinglebrowser,youdon'tknowhowwellitcopeswithload.
WhathappensifadozenclientsaremakingrequestssimultaneouslyOrahundredWhatsortofthroughputcanyourapplicationsustainWhatsortofresponsetimedoesitprovideWhatarethesenumberslikewhenyourapplicationisunderlightloadMediumloadHeavyloadHowwelldoesyourapplicationscaleifyourunitonamultiprocessormachineStresstestingyourapplicationisessentialtoshakeoutbugsandit'sessentialtodiscoverperformanceproblems.
Similarconsiderationsaboutloadtestingapplytoallserverapplications.
10.
Thoushaltnotusereal-worldscenarios.
It'seasytofallintothetrapoftuningyourapplicationforafewspecific,artificialscenarios(suchasbenchmarks).
It'simportanttopickabroadspectrumofscenariosthatcorrespondtoreal-worldusageandoptimizeforabroadrangeofoperations.
Ifyoudon'tfindthesescenarios,yourusersandreviewerscertainlywill,andthey'llpanyouforit.
ConclusionWe'velearnedafewthingsaboutkillingserverperformanceandscalabilitysincewestarteddevelopingIIS.
Writinghigh-performanceserverapplicationsisnoteasy.
Inadditiontothetraditionalperformanceissuesthatarisewhenwritingdesktopapplications,youmustpayspecialattentiontomemoryallocations,cachelines,cachingdata,threadproliferation,lockingstrategies,multiprocessormachines,blockingcalls,measurementandanalysis,multiclienttesting,andreal-worldscenarios.
Theseissueswillmakeyouorbreakyou.
pacificrack官方在搞2021年七夕促销,两款便宜vps给的配置都是挺不错的,依旧是接入1Gbps带宽,KVM虚拟、纯SSD raid10阵列,支持包括Linux、Windows 7、10、server2003、2008、2012、2016、2019在内多种操作系统。本次促销的VPS请特别注意限制条件,见本文末尾!官方网站:https://pacificrack.com支持PayPal、支...
ZJI是成立于2011年原Wordpress圈知名主机商—维翔主机,2018年9月更名为ZJI,主要提供香港、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册业务。本月商家针对香港阿里云线路独立服务器提供月付立减270-400元优惠码,优惠后香港独立服务器(阿里云专线)E3或者E5 CPU,SSD硬盘,最低每月仅480元起。阿里一型CPU:Intel E5-2630L...
麻花云在7月特意为主机测评用户群定制了促销活动:香港宽频CN2云服务器、安徽移动云服务器(BGP网络,非单线,效果更好)、安徽移动独立服务器、安徽电信独立服务器,全部不限制流量,自带一个IPv4,默认5Gbps的DDoS防御。活动链接:https://www.mhyun.net/act/zjcp特价云服务器不限流量,自带一个IPv4,5Gbps防御香港宽频CN2全固态Ⅲ型 4核4G【KVM】内存:...
response.flush为你推荐
定向fastreport2贵州省127支持ipad支持ipad支持ioswin10445端口WIN7怎么打开3306端口csshack什么是Css Hack?ie6,7,8的hack分别是什么micromediamacromedia FreeHand MX是干什么用的?css选择器CSS中选择器包括 A,超文本标记选择器 B,类选择器 C,标签选择器 D,ID选择器迅雷下载速度迅雷下载快慢和什么有关
.cn域名注册 代理域名备案 拜登买域名批特朗普 互联网域名管理办法 ftp空间 主机点评 Vultr 360抢票助手 ev证书 免费网站申请 炎黄盛世 135邮箱 国外代理服务器软件 可外链相册 美国在线代理服务器 万网主机管理 架设邮件服务器 带宽租赁 沈阳主机托管 我的世界服务器ip 更多