




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
HighperformanceWebSitesrichardchang騰訊技術(shù)大講堂不知大家有沒(méi)有看過(guò)這個(gè)ppt以及這個(gè)架構(gòu)圖Yahoo’sCasePerformanceresearchand14rulesExceptionalPerformancestartedin2004quantifyandimprovetheperformanceofallYahoo!productsworldwidecenterofexpertisebuildtools,analyzedatagather,research,andevangelizebestpracticesScopeperformancebreaksintotwocategoriesresponsetimeefficiencycurrentfocusisresponsetimeofwebproductsTheImportanceofFront-EndPerformancepercentageoftimespentonthefront-endBack-endvs.Front-endEmptyCacheFullCache82%86%94%86%81%92%98%92%86%64%97%95%96%86%80%88%95%88%97%95%ThePerformanceGoldenRule80-90%oftheend-userresponsetimeisspentonthefront-end.Startthere.GreaterpotentialforimprovementSimplerProventoworkPerformanceResearch/blog/2006/11/28/performance-research-part-1/80/20PerformanceRuleVilfredoPareto:
80%ofconsequencescomefrom20%ofcausesFocusonthe20%thataffects80%oftheend-userresponsetime.Startatthefront-end.1userrequests2userrequestsotherwebpages3userre-requestsEmptyvs.FullCache1userrequests2userrequestsotherwebpages3userre-requestsEmptyvs.FullCachewithanemptycache1userrequests2userrequestsotherwebpages3userre-requestsEmptyvs.FullCacheEmptyvs.FullCacheExpiresheader1userrequests2userrequestsotherwebpages3userre-requestswithafullcacheEmptyvs.FullCache emptycache 2.4seconds fullcache 0.9seconds83%fewerbytes90%fewerHTTPrequestsHowmuchdoesthisbenefitourusers?Itdependsonhowmanyusershavecomponentsincache.Whatpercentageofusersviewapagewithanemptycache*?
*“Emptycache”meansthebrowserhastorequestthecomponents
insteadofpullingthemfromthebrowserdiskcache.Whatpercentageofpageviews
aredonewithanemptycache*?/blog/2007/01/04/performance-research-part-2/Addanewimagetoyourpage<imgsrc="image/blank.gif"height="1"width="1"/>
withthefollowingresponseheaders:Expires:Thu,15Apr200420:00:00GMTLast-Modified:Wed,28Sep200623:49:57GMT}1pxBrowserCacheExperimentBrowserCacheExperimentRequestsfromthebrowserwillhaveoneoftheseresponsestatuscodes:
200–Thebrowserdoesnothavetheimage
initscache.304–Thebrowserhastheimageinitscache,
butneedstoverifythelastmodifieddate.BrowserCacheExperimentWhatpercentageofusersviewwithanemptycache?#uniqueuserswithatleastone200responsetotal#uniqueusersWhatpercentageofpageviewsaredonewithanemptycache?total#of200responses#of200+#of304responses}1pxSurprisingResultspageviewswith
emptycache40-60%~20%userswith
emptycacheExperimentTakeawaysKeepinmindtheemptycacheuserexperience.Itmightbemoreprevalentthanyouthink!Usedifferenttechniquestooptimizefullversusemptycacheexperience./blog/2007/03/01/performance-research-part-31userrequestsHTTPQuickReviewHTTPresponseheadersentbythewebserver:HTTP/1.1200OKContent-Type:text/html;charset=utf-8Set-Cookie:C=abcdefghijklmnopqrstuvwxyz;domain=.1userrequestsHTTPQuickReview2userrequestsHTTPrequestheadersentbythebrowser:GET/HTTP/1.1Host:User-Agent:Mozilla/4.0(compatible;MSIE6.0;…
Cookie:C=abcdefghijklmnopqrstuvwxyz;1userrequests3userrequestsHTTPQuickReviewHTTPrequestheadersentbythebrowser:GET/HTTP/1.1Host:User-Agent:Mozilla/4.0(compatible;MSIE6.0;…
Cookie:C=abcdefghijklmnopqrstuvwxyz;1userrequests4userrequestsHTTPQuickReviewHTTPrequestheadersentbythebrowser:GET/HTTP/1.1Host:User-Agent:Mozilla/4.0(compatible;MSIE6.0;…
Cookie:C=abcdefghijklmnopqrstuvwxyz;1userrequests5userrequestsHTTPQuickReviewHTTPrequestheadersentbythebrowser:GET/HTTP/1.1Host:User-Agent:Mozilla/4.0(compatible;MSIE6.0;…
Cookie:C=abcdefghijklmnopqrstuvwxyz;ImpactofCookiesonResponseTime80msdelaydialupusersCookieSizeTimeDelta0bytes78ms0ms500bytes79ms+1ms1000bytes94ms+16ms1500bytes109ms+31ms2000bytes125ms+47ms2500bytes141ms+63ms3000bytes156ms+78mskeepsizeslow.cookiesizesAnalysisofCookieSizesacrosstheWebTotalCookieSizeAmazon60bytesGoogle72bytesYahoo122bytesCNN184bytesYouTube218bytesMSN268byteseBay331bytesMySpace500bytesExperimentTakeawayseliminateunnecessarycookieskeepcookiesizeslowsetcookiesatappropriatedomainlevel,orhostingassetsonanewdomainsetExpiresdateappropriatelyearlierdateornoneremovescookiesooner /blog/2007/04/11/performance-research-part-4/ParallelDownloadsTwocomponentsinparallelperhostnameGIFGIFGIFGIFGIFGIFHTTP/1.1ParallelDownloadsTwoinparallelFourinparallelEightinparallelMaximizingParallelDownloadsresponsetime(seconds)aliasesMaximizingParallelDownloadsresponsetime(seconds)aliasesMaximizingParallelDownloadsresponsetime(seconds)aliasesMaximizingParallelDownloadsresponsetime(seconds)ruleofthumb:useatleasttwobutnomorethanfouraliasesExperimentTakeawaysconsidertheeffectsofCPUthrashingDNSlookuptimesvaryacrossISPsandgeographiclocationsdomainnamesmaynotbecached14RulesHowtooptimize?basicoptimizationrulesoptimizingassets(images,scripts,andstyles)optimizationsspecifictoscriptsoptimizationsspecifictostylesBasicRulesDecreaseDownloadSizesMakeFewerHTTPRequestsCombinescriptsandstylesheetsUseimagespritesAvoidredirectsAvoidframes14thingstocheckMakefewerHTTPrequestsUseaCDNAddanExpiresheaderGzipcomponentsPutCSSatthetopMoveJStothebottomAvoidCSSexpressionsMakeJSandCSSexternalReduceDNSlookupsMinifyJSAvoidredirectsRemoveduplicatescriptsTurnoffETagsMakeAJAXcacheableandsmallRule1:MakefewerHTTPrequestsimagemapsCSSspritesinlineimagescombinedscripts,combinedstylesheetsImagemapsserver-side<ahref="navbar.cgi"><imgismapsrc="imagemap.gif"></a>→http://.../navbar.cgi?127,13client-side–preferred<imgusemap="#map1"border=0src="/images/imagemap.gif"><mapname="map1"><areashape="rect"coords="0,0,31,31"href="home.html"title="Home">…</map>drawbacks:mustbecontiguousdefiningareacoordinates–tedious,errors/TR/html401/struct/objects.html#h-13.6CSSSprites–PreferredsizeofcombinedimageislessCSSSpritesGenerator-//articles/sprites#rss{background-image:url(sprite.png);background-position:-8px-40px;width:16px;height:16px;}CombinedScripts,
CombinedStylesheetsScriptsStylesheets3118111272119122314173Average6.51.5CombinedScripts,
CombinedStylesheetscombiningsixscriptsintooneeliminatesfiveHTTPrequestschallenges:developasseparatemodulesnumberofpossiblecombinationsvs.loadingmorethanneededmaximizebrowsercacheonesolution:dynamicallycombineandcacheRule2:UseaCDNdistributeyourstaticcontentbeforedistributingyourdynamiccontentAkamaiAkamaiAkamai,MirrorImageSAVVISAkamai,LimelightAkamaiRule3:AddanExpiresheadernotjustforimagesImagesStylesheetsScripts%MedianAge0/620/10/30%114days23/431/16/1848%217days0/1380/22/111%227days16/200/20/755%140days1/230/10/14%454days32/351/13/980%34days0/180/20/20%1day6/81/12/375%1day23/231/14/4100%n/a0/320/30/70%26daysSettingExpiresheaderinApacheExpiresActiveOnExpiresByTypeapplication/x-javascript"modificationplus2years"ExpiresByTypetext/css"modificationplus5years"Whenmodifinganasset?Modifytheassetname(automatically)!Appendanepochtimestamptothefilename,e.g.img_1185403733.png.Usetheversionnumberfromyoursourcecontrolsystem(cvsorsvnforexample),e.g.img_1.1.png.Manuallyincrementanumberinthefilename(e.g.whenyouseeafilenamedimg1.png,simplysavethemodifiedimageasimg2.png).Rule4:Gzipcomponentsyoucanaffectusers'downloadtimes90%+ofbrowserssupportcompressionGzip:notjustforHTMLHTMLScriptsStylesheetsxxsomesomexxxxxdeflatedeflatexxxxxxxxxxsomesomegzipscripts,stylesheets,XML,JSON(notimages,PDF)GzipConfigurationApache2.x:mod_deflateAddOutputFilterByTypeDEFLATEtext/htmltext/cssapplication/x-javascriptHTTPrequestAccept-Encoding:gzip,deflateHTTPresponseContent-Encoding:gzipVary:Accept-EncodingneededforproxiesRule5:PutCSSatthetopstylesheetsblockrenderinginIE/examples/css-bottom.phpsolution:putstylesheetsinHEAD(perspec)avoidsFlashofUnstyledContentuseLINK(not@import)SlowestisFastestRule6:MovescriptstothebottomscriptsblockparalleldownloadsacrossallhostnamesscriptsblockrenderingofeverythingbelowtheminthepageIEandFF/examples/js-middle.phpRule6:MovescriptstothebottomscriptdeferattributeisnotasolutionblocksrenderinganddownloadsinFFslightblockinginIEsolution:movethemaslowinthepageaspossibleRule7:AvoidCSSexpressionsusedtosetCSSpropertiesdynamicallyinIEwidth:expression(document.body.clientWidth<600?“600px”:“auto”);problem:expressionsexecutemanytimesmousemove,keypress,resize,scroll,etc./examples/expression-counter.phpRule8:MakeJSandCSSexternalinline:HTMLdocumentisbiggerexternal:moreHTTPrequests,butcachedvariablespageviewsperuser(persession)emptyvs.fullcachestatscomponentre-useexternalistypicallybetterhomepagesmaybeanexceptionPost-OnloadDownloadinlineinfrontpagedownloadexternalfilesafteronloadwindow.onload=downloadComponents;functiondownloadComponents(){varelem=document.createElement("script");elem.src="http://.../file1.js";document.body.appendChild(elem);...}speedsupsecondarypagesExample:Googleoncethehomepagehasfinishedloading,thereisarequesttogetaspriteimage,whichisnotactuallyneededuntilsearchresultspageloadsExample:YahooConditionalpre-loading--waitsfortheusertostarttypinginthesearchbox.Onceyou'vebeguntyping,it'salmostguaranteedthatyou'llsubmitasearchquery.DynamicInliningstartwithpost-onloaddownloadsetcookieaftercomponentsdownloadedserver-side:ifcookie,useexternalelse,doinlinewithpost-onloaddownloadcookieexpirationdateiskeyspeedsupallpagesRule9:ReduceDNSlookupstypically20-120msblockparalleldownloadsOSandbrowserbothhaveDNScachesTTL(TimeToLive)1minute1minute10minutes1hour5minutes5minutes1hour1hour1minute5minutesTTL–howlongrecordcanbecachedbrowsersettingsoverrideTTLBrowserDNSCacheIEDnsCacheTimeout:30minutesKeepAliveTimeout:1minuteServerInfoTimeout:2minutesFirefoxnetwork.dnsCacheExpiration:1minutenetwork.dnsCacheEntries:20network.http.keep-alive.timeout:5minutesFasterfox:1hour,512entries,30secondsReducingDNSLookupsfewerhostnames–2-4(whataboutforumsandblogs?)keep-aliveRule10:MinifyJavaScriptMinifyExternal?MinifyInline?nonononononoyesnoyesyesyesyesnonononoyesyesnonominifyinlinescripts,tooMinifyvs.ObfuscateOriginalJSMinSavingsDojoSavings204K31K(15%)48K(24%)44K4K(10%)4K(10%)98K19K(20%)24K(25%)88K23K(27%)24K(28%)42K14K(34%)16K(38%)34K8K(22%)10K(29%)Average85K17K(21%)21K(25%)minify–it'ssafer/javascript/jsmin/docs/shrinksafeRule11:Avoidredirects3xxstatuscodes–mostly301and302HTTP/1.1301MovedPermanentlyLocation:/newuriaddExpiresheaderstocacheredirectsworstformofblocking/Protocols/rfc2616/rfc2616-sec10.htmlRedirectsRedirectsnoyes–secondarypageyes–initialpageyes–secondarypagenoyes–initialpageyes–secondarypageyes–secondarypageyes–secondarypagenoAvoidRedirectsmissingtrailingslash/astrologyuseAliasorDirectorySlashmod_rewriteCNAMEslogreferer–trackinternallinksoutboundlinks–harderbeacons–bewareofraceconditionXHR–bailatreadyState2Rule12:RemoveduplicatescriptshurtsperformanceextraHTTPrequests(IEonly)extraexecutionsatypical?2of10topsitescontainduplicatescriptsteamsize,#ofscriptsScriptInsertionFunctions<?phpfunctioninsertScript($jsfile){if(alreadyInserted($jsfile)){return;}pushInserted($jsfile);if(hasDependencies($jsfile)){$dependencies=getDependencies($jsfile);for($i=0;$i<count($dependencies);$i++){insertScript($dependencies[$i]);}}echo'<scripttype="text/javascript"src="'.getVersion($jsfile).'"></script>";}?>Rule13:TurnoffETagsuniqueidentifierreturnedinresponseETag:"c8897e-aee-4165acf0"Last-Modified:Thu,07Oct200420:54:08GMTusedinconditionalGETrequestsIf-None-Match:"c8897e-aee-4165acf0"If-Modified-Since:Thu,07Oct200420:54:08GMTifETagdoesn'tmatch,can'tsend304TheProblemwithETagsETagforasingleentityisalwaysdifferentacrossserversETagformatApache:inode-size-timestampIIS:Filetimesta
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年廣東省云浮市云城區(qū)高考語(yǔ)文模擬試卷(二)
- 南京2025年江蘇南京金陵華興實(shí)驗(yàn)學(xué)校招聘編外教師2人筆試歷年參考題庫(kù)附帶答案詳解
- 生物科技助力實(shí)現(xiàn)精準(zhǔn)治療與預(yù)防
- 培訓(xùn) 出租合同范本
- Xelafaslatide-ONL-1204-生命科學(xué)試劑-MCE
- BMS-214662-mesylate-生命科學(xué)試劑-MCE
- 中山廣東中山市板芙鎮(zhèn)公開招聘公辦中小學(xué)校臨聘教師14人筆試歷年參考題庫(kù)附帶答案詳解
- 中央2025年中國(guó)作家協(xié)會(huì)所屬單位招聘11人筆試歷年參考題庫(kù)附帶答案詳解
- 工地貼磚合同范本
- 科技產(chǎn)品開發(fā)中的知識(shí)產(chǎn)權(quán)管理
- 2025年中國(guó)國(guó)投高新產(chǎn)業(yè)投資集團(tuán)招聘筆試參考題庫(kù)含答案解析
- 2024-2025學(xué)年小學(xué)美術(shù)一年級(jí)下冊(cè)(2024)嶺南版(2024)教學(xué)設(shè)計(jì)合集
- 《研學(xué)旅行課程設(shè)計(jì)》課件-研學(xué)課程設(shè)計(jì)計(jì)劃
- 年產(chǎn)10噸功能益生菌凍干粉的工廠設(shè)計(jì)改
- 律師事務(wù)所主任在司法行政工作會(huì)議上的發(fā)言稿
- 初中三角函數(shù)計(jì)算題100道
- 蘇州大學(xué)應(yīng)用技術(shù)學(xué)院財(cái)務(wù)管理
- 2022年新目標(biāo)英語(yǔ)七年級(jí)期末考試質(zhì)量分析
- 北師大版五年級(jí)數(shù)學(xué)下冊(cè)導(dǎo)學(xué)案全冊(cè)
- 臺(tái)球俱樂(lè)部助教制度及待遇
- 醫(yī)院護(hù)士勞動(dòng)合同
評(píng)論
0/150
提交評(píng)論