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
380
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
240
SVG Charts and Graphs With Ruby
snhorne
0
170
SVG Charts and Graphs With Ruby
snhorne
0
360
Machine Learning Techniques You Can Use Today
snhorne
4
190
Biggish Data with Rails and Postgresql
snhorne
3
940
Other Decks in Programming
See All in Programming
C++でシェーダを書く
fadis
6
4.1k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
940
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
subpath importsで始めるモック生活
10tera
0
310
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Arm移行タイムアタック
qnighy
0
330
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Building Adaptive Systems
keathley
38
2.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
The Invisible Side of Design
smashingmag
298
50k
Adopting Sorbet at Scale
ufuk
73
9.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
4 Signs Your Business is Dying
shpigford
180
21k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
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