Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The short but happy lives of TCP and HTTP requests

Starr Horne
September 19, 2014

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

More Decks by Starr Horne

Other Decks in Programming

Transcript

  1. @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!)
  2. @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)
  3. @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
  4. @StarrHorne Except when it’s not Source: High Performance Browser Networking

    ( http://bit.ly/high-performance-browser-networking )
  5. @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.
  6. @StarrHorne Opening a connection Hey, we should talk Sure, about

    what? Awesome. Send me that funny cat pic
  7. @StarrHorne Keep-Alive Browser opens one TCP connection uses it for

    multiple HTTP requests. ! ! ! ! ! ! ! …actually, you get 6 connections per domain.
  8. @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
  9. @StarrHorne TCP Tuning Make sure you’re running a recent linux

    kernel If you insist: http://bit.ly/tcp-tuning
  10. @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
  11. @StarrHorne Could we do them CONCURRENTLY? ! ! ! !

    ! You DO get 6 connections per domain. And you DO know how to make domains.
  12. @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">
  13. @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 !
  14. @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
  15. @StarrHorne HTTP 2.0 ! Coming soon. ! Also focused on

    the “lots of small files” problem ! But HTTP 1.4 ain’t going anywhere soon.
  16. @StarrHorne Buy this book ! You can also read it

    online for free - legally! ! http://bit.ly/high-performance-browser-networking