




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
HighperformanceWebSitesrichardchang騰訊技術(shù)大講堂不知大家有沒有看過這個ppt以及這個架構(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 沙土買賣合同范本
- 醫(yī)療美容勞務(wù)合同范本
- 保健按摩復(fù)習(xí)題與參考答案
- 業(yè)績差檢討書
- 世界糧食日宣傳的活動總結(jié)
- 各類商標(biāo)授權(quán)轉(zhuǎn)讓合同范本
- 上半年保安個人工作總結(jié)
- 三年級體育教學(xué)工作總結(jié)
- 水利工程師水力學(xué)試題與答案
- 廠房過戶合同范本
- 第6課 識別界限 拒絕性騷擾 課件 2024-2025學(xué)年人教版(2024)初中體育與健康七年級全一冊
- 【MOOC】《思想道德與法治》(東南大學(xué))章節(jié)中國大學(xué)慕課答案
- 廣州電視塔鋼結(jié)構(gòu)施工方案
- 中山2024年廣東中山市人民政府東區(qū)街道辦事處所屬事業(yè)單位第二期招聘3人筆試歷年典型考點(頻考版試卷)附帶答案詳解
- 小學(xué)二年級100以內(nèi)進退位加減法800道題
- 艾滋病丙肝梅毒
- CNAS-CL01-G001:2024檢測和校準(zhǔn)實驗室能力認(rèn)可準(zhǔn)則的應(yīng)用要求
- 通信網(wǎng)絡(luò)習(xí)題(附答案)
- 現(xiàn)代物流基礎(chǔ)練習(xí)題庫及參考答案
- 2024年互聯(lián)網(wǎng)金融客服培訓(xùn)中的法律知識教學(xué)
- 高鐵隧道勞務(wù)分包合同范本(2篇)
評論
0/150
提交評論