Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The short but happy lives of TCP and HTTP requests
Search
Starr Horne
September 19, 2014
Programming
4
390
The short but happy lives of TCP and HTTP requests
A talk about network optimization given at the 2014 Golden Gate Ruby Conference.
Starr Horne
September 19, 2014
Tweet
Share
More Decks by Starr Horne
See All by Starr Horne
Ditching the Single Page Application - Madison+Ruby 2015
snhorne
0
250
Ditching the Single Page Application (RubyNation 2015)
snhorne
1
260
SVG Charts and Graphs With Ruby
snhorne
0
200
SVG Charts and Graphs With Ruby
snhorne
0
370
Machine Learning Techniques You Can Use Today
snhorne
4
200
Biggish Data with Rails and Postgresql
snhorne
3
970
Other Decks in Programming
See All in Programming
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
110
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
1
370
SODA - FACT BOOK
sodainc
1
1.1k
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
250
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
950
Datadog RUM 本番導入までの道
shinter61
1
310
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
290
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
XP, Testing and ninja testing
m_seki
2
140
技術同人誌をMCP Serverにしてみた
74th
0
130
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
14k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Code Reviewing Like a Champion
maltzj
524
40k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
GraphQLとの向き合い方2022年版
quramy
46
14k
Agile that works and the tools we love
rasmusluckow
329
21k
Facilitating Awesome Meetings
lara
54
6.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Designing for Performance
lara
609
69k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Transcript
@StarrHorne Hi everybody!! ! I’ll be tweeting this ! slide
deck later at ! @StarrHorne ! ! That’s me!! ! ! ps. Use Honeybadger to monitor your Rails apps for exceptions. (Now my trip is tax deductible!)
@StarrHorne
@StarrHorne
@StarrHorne Short but happy
@StarrHorne Short but happy The lives of HTTP requests
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne Welcome to the internet I’ll be your guide
@StarrHorne OSI Model
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne Wires
@StarrHorne Latency ! ! ! Time spent “in the wire”
! ps. it ain’t bandwidth
@StarrHorne Latency ! ! ! Time spent “in the wire”
! ps. it ain’t bandwidth
@StarrHorne Minimum latency (determined by speed of light) http://trollphysics.tumblr.com
@StarrHorne Minimum latency (determined by speed of light) http://trollphysics.tumblr.com
@StarrHorne 299,792,458 m/s (Speed of light in a vacuum) http://trollphysics.tumblr.com
@StarrHorne Don’t call it SOL in a vacuum (That’s something
else) http://trollphysics.tumblr.com
@StarrHorne
@StarrHorne ! 5,578,593(m) ÷ 299,792,458 (m/s) = 0.0186 (s) !
0.0186 * 1000 (ms/s) = 18.6ms ! 18.6 * 2 = 37.2 ms round trip NYC <=> LON Latency (minimum theoretical)
@StarrHorne
@StarrHorne Latency kills UX 100 ms Doesn’t seem instantaneous 250
ms Feels sluggish 500 ms I start to get distracted 1000 ms I’m cussing at the computer
@StarrHorne Easy Move servers closer to users.
@StarrHorne Harder Eliminate Round Trips
@StarrHorne The Data Link
@StarrHorne Bandwidth It must be important. Just look at that
dude’s face!
@StarrHorne Except when it’s not Source: High Performance Browser Networking
( http://bit.ly/high-performance-browser-networking )
@StarrHorne
@StarrHorne The “lots of small files” problem Slower Faster
@StarrHorne Blame the protocols IP Routes packets between computers No
guarantees of delivery. TCP A simulation of a stable network running on top of IP. HTTP Sends one file at a time over TCP connections.
@StarrHorne ! NEW TCP CONNECTIONS ARE EXPENSIVE
@StarrHorne Opening a connection Hey, we should talk Sure, about
what? Awesome. Send me that funny cat pic
@StarrHorne New connection overhead (1 round trip. 20-100ms depending)
@StarrHorne ! YOU’RE NOT GETTING OFF THAT EASY
@StarrHorne CONGESTION CONTROL
@StarrHorne Slow Start
@StarrHorne Let’s see… Thats 10 round trips at (we’ll assume)
40ms latency. Holy crap that’s 400ms!!!
@StarrHorne ! NEW TCP CONNECTIONS ARE EXPENSIVE
@StarrHorne Keep-Alive Browser opens one TCP connection uses it for
multiple HTTP requests. ! ! ! ! ! ! ! …actually, you get 6 connections per domain.
@StarrHorne Your server controls keepalive ! ! Apache: http://bit.ly/apache-ka !
Nginx: http://bit.ly/nginx-ka !
@StarrHorne “Slow start after idle” kills keepalive ! $> sysctl
net.ipv4.tcp_slow_start_after_idle ! $> sysctl -w net.ipv4.tcp_slow_start_after_idle=0
@StarrHorne TCP Tuning Make sure you’re running a recent linux
kernel If you insist: http://bit.ly/tcp-tuning
@StarrHorne HTTP, WTF!?
@StarrHorne >telnet cern.ch 80 GET /cat.txt HTTP/1.0 host: www.esqsoft.globalservers.com
@StarrHorne >telnet cern.ch 80 GET /cat.txt HTTP/1.0 host: www.esqsoft.globalservers.com
@StarrHorne
@StarrHorne
@StarrHorne
@StarrHorne 112 (Requests per webpage on average)
@StarrHorne Browser Caching (Response headers) Last-Modified Tell the browser when
this file was last modified. ETag Supplies an ETag the browser can use to check freshness. Expires Tells the browser to keep the page until a certain date http://bit.ly/http-caching
@StarrHorne 112 (Requests per webpage on average)
@StarrHorne Concatenate JS & CSS (Hello asset pipeline)
@StarrHorne
@StarrHorne
Down to 30 requests (But I feel dirty for some
reason) @StarrHorne
@StarrHorne
@StarrHorne Could we do them CONCURRENTLY? ! ! ! !
! You DO get 6 connections per domain. And you DO know how to make domains.
@StarrHorne farm4.staticflickr.com farm8.staticflickr.com farm8.staticflickr.com farm4.staticflickr.com farm6.staticflickr.com farm3.staticflickr.com http://bit.ly/p-speed
@StarrHorne I guess you could call it an ugly hack
@StarrHorne www.honeybadger.io d3aei7d2k8qp8j.cloudfront.net cdnjs.cloudflare.com d3dy5gmtp8yhk7.cloudfront.net cdnjs.cloudflare.com But we do it
anyway (As a side-effect of using CDNs)
@StarrHorne Move requests out of band (Supported by newer browsers)
! <script async="async" src="/my.js"></script> ! <link rel="prefetch" href=“/big.jpeg"> ! <link rel="prerender" href=“/next.html”> ! <link rel="dns-prefetch" href="//blah.com">
@StarrHorne Summary ! Move your servers closer to your users
(CDNs) ! Make sure keep-alive works ! Keep cookie size small ! Serve fewer files by whatever means necessary ! Shard files across domains if you must !
@StarrHorne The cavalry is on the way!
@StarrHorne SPDY ! Much better at the “lots of small
files” thing ! Supported by many (but not all) clients ! You still need CDNs for geography ! Requires SSL
@StarrHorne HTTP 2.0 ! Coming soon. ! Also focused on
the “lots of small files” problem ! But HTTP 1.4 ain’t going anywhere soon.
@StarrHorne Buy this book ! You can also read it
online for free - legally! ! http://bit.ly/high-performance-browser-networking
@StarrHorne I’ll be tweeting this slide deck later at @StarrHorne