配色: 字号:
腾讯大讲堂09-如何建设高性能网站
2020-02-28 | 阅:  转:  |  分享 
  
LookoutfortheNumberOneThedatainTable2refl
ectsonlycookiessetatthetopdomainlevelstoeliminateanyc
ookiesthatmayhavebeensetbyadsAcookiesetatthe.yaho
o.comdomainimpactstheresponsetimeforeveryYahoo!pageint
he.yahoo.comdomainthatauservisits.尽量减少不必要的cookies将cookie的
size缩小将cookie放到domainlevel的时候要谨慎小心,尽量不要影响其他的subdomain将expirat
iondate合理设置既然对最终用户反应时间的最大影响来自与有多少个组件要被请求,为什么不能一次同时将他们下载完呢
?主要是因为http/1.1的规范,浏览器每次只能同时从单个hostname下载两个组件但是如果一个网站将自己的组件平均地
分配到两个hostname上,就会像下图那么到底是不是将组件分配到越多hostname越好呢,我们也做了测试。The
experimentmeasuredanemptyHTMLdocumentwith20imagesonthe
page.Theimageswerefetchedfromthesameserversasthoseused
byrealYahoo!pages.Werantheexperimentinacontrolledenvi
ronmentusingatestharnessthatfetchesasetofURLsrepeatedl
ywhilemeasuringhowlongittakestoloadthepageonDSL.
Wefetch20smaller-sizedimages(36x36px)and20medium-si
zedimages(116x61px).Tooursurprise,increasingthenumber
ofaliasesforloadingthemedium-sizeimages(116x61px)worsen
stheresponsetimesusingfourormorealiases.Increasingthen
umberofaliasesbymorethantwoforsmaller-sizedimages(36x
36px)doesn’tmakemuchofanimpactontheoverallresponsetime
.Onaverage,usingtwoaliasesisbest.Onepossiblecontribut
orforslowerresponsetimesistheamountofCPUthrashingonth
eclientcausedbyincreasingthenumberofparalleldownloads.A
notherissuetoconsideristhatDNSlookuptimesvarysignifican
tlyacrossISPsandgeographiclocations.checkout
thisimage,usedonYahoo!''shomepage,orthisonefromGoogle''s.
servingcompressedHTML,CSS,client-sidescripts,anda
nyothertypeoftextcontent.IfyoumakeXMLHttpRequeststose
rvicesthatreturnXML(orJSON,orplaintext),makesureyours
ervergzipsaswellThere''sonegotchawhenitcomestoservin
ggzippedcontent:youmustmakesurethatproxiesdonotgetin
yourway.IfanISP''sproxycachesyourgzippedcontentandserve
sittoallofitscustomers,chancesarethatsomeonewithabro
wserthatdoesn''tsupportcompressionwillreceiveyourcompresse
dcontent.ToavoidthisyoucanusetheVary:Accept-Encodingr
esponseheadertotelltheproxytocachethisresponseonlyfor
clientsthatsendthesameAccept-Encodingrequestheader.
duetothenatureofthescripts(theycouldpotentiallychange
anythingonapage),browsersblockalldownloadswhentheyencou
ntersa