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
190
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
950
Other Decks in Programming
See All in Programming
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
520
Ruby on cygwin 2025-02
fd0
0
140
sappoRo.R #12 初心者セッション
kosugitti
0
240
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
550
『品質』という言葉が嫌いな理由
korimu
0
160
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
9
3.4k
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
SwiftUI Viewの責務分離
elmetal
PRO
1
220
チームリードになって変わったこと
isaka1022
0
190
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
870
WebDriver BiDiとは何なのか
yotahada3
1
140
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
4
1.3k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Typedesign – Prime Four
hannesfritz
40
2.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
Designing for Performance
lara
604
68k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
What's in a price? How to price your products and services
michaelherold
244
12k
Gamification - CAS2011
davidbonilla
80
5.1k
RailsConf 2023
tenderlove
29
1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
21
2.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
9
430
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