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
380
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
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
170
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
5.8k
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
220
PicoRuby on Rails
makicamel
2
130
Discover Metal 4
rei315
2
140
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
12
4.5k
生成AI時代のコンポーネントライブラリの作り方
touyou
1
220
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
530
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
650
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
Featured
See All Featured
Site-Speed That Sticks
csswizardry
10
690
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Speed Design
sergeychernyshev
32
1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
The Language of Interfaces
destraynor
158
25k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Why Our Code Smells
bkeepers
PRO
336
57k
How to Ace a Technical Interview
jacobian
278
23k
Automating Front-end Workflow
addyosmani
1370
200k
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