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

RailsConf 2016: Pat Packet visits Ruby Rails

RailsConf 2016: Pat Packet visits Ruby Rails

Jeremy Fairbank

May 04, 2016
Tweet

More Decks by Jeremy Fairbank

Other Decks in Programming

Transcript

  1. Pat Packet Visits Ruby Rails by: Jeremy Fairbank @elpapapollo |

    github.com/jfairbank illustrations: Marissa Roeper marissaroeper.com
  2. ?

  3. HTTP DNS TCP/IP ROUTING GET / HTTP/1.1 
 Host: rubyonrails.org

    Accept: text/html Accept-Encoding: gzip, deflate, sdch Accept-Language: en-US,en;q=0.8 Cache-Control: no-cache Connection: keep-alive 
 Hello World The Message
  4. Package Address Continent Kingdom Train Router Station Network Packet IP

    Address Physical Device Software Server Connection Router/Switch Legend
  5. WAN - Wide Area Network The Internet LAN - Local

    Area Network Router + computers Protocol Official rules/guidelines to follow HTTP - Hyper Text Transfer Protocol Protocol for HTML, JSON, XML
  6. GET / HTTP/1.1 Host: rubyonrails.org Accept: text/html Accept-Encoding: gzip, deflate,

    sdch Accept-Language: en-US,en;q=0.8 Cache-Control: no-cache Connection: keep-alive 
 Hello World Request Line Method Resource HTTP Version HTTP Request Headers Optional Message
  7. GET Can you send me your home page? GET /

    HTTP/1.1 POST PUT DELETE HTTP Methods
  8. GET Can you send me your home page? POST Here

    is my shopping cart for checkout. PUT DELETE POST /checkout HTTP/1.1 HTTP Methods
  9. GET Can you send me your home page? POST Here

    is my shopping cart for checkout. PUT I changed my name. Can you please update your records? DELETE PUT /user/info HTTP/1.1 HTTP Methods
  10. GET Can you send me your home page? POST Here

    is my shopping cart for checkout. PUT I changed my name. Can you please update your records? DELETE I no longer use this address. Can you remove it? DELETE /address/2 HTTP/1.1 HTTP Methods
  11. Meta data is like saying I’d prefer the list of

    friends in HTML. Data is like saying Please send me a list of my friends. HTTP Headers
  12. Send back whatever you have. Accept: */* Accept: text/html Content-Type:

    application/json Host: rubyonrails.org Content-Length: 42 Key Value HTTP Headers
  13. Send back HTML please. Accept: */* Accept: text/html Content-Type: application/json

    Host: rubyonrails.org Content-Length: 42 Key Value HTTP Headers
  14. I’m sending you some JSON. Accept: */* Accept: text/html Content-Type:

    application/json Host: rubyonrails.org Content-Length: 42 Key Value HTTP Headers
  15. Please give this message to rubyonrails.org. Accept: */* Accept: text/html

    Content-Type: application/json Host: rubyonrails.org Content-Length: 42 Key Value HTTP Headers
  16. Here’s how much information I’m sending. Accept: */* Accept: text/html

    Content-Type: application/json Host: rubyonrails.org Content-Length: 42 Key Value HTTP Headers
  17. Status Line Headers Message HTTP/1.1 200 OK Server: GitHub.com Date:

    Sun, 17 Apr 2016 11:19:48 GMT Content-Type: text/html; charset=utf-8 Content-Length: 4127 Last-Modified: Tue, 01 Mar 2016 10:32:49 GMT 
 <html><body>Ruby on Rails!</body></html> HTTP Version Status Code Status Description HTTP Reply
  18. HTTP/1.1 304 Not Modified 200 All good. Here’s your reply.

    304 Nothing changed. Keep what you already have. 404 401 500 HTTP Statuses
  19. HTTP/1.1 404 Not Found 200 All good. Here’s your reply.

    304 Nothing changed. Keep what you already have. 404 Sorry, I can’t find that. 401 500 HTTP Statuses
  20. HTTP/1.1 401 Unauthorized 200 All good. Here’s your reply. 304

    Nothing changed. Keep what you already have. 404 Sorry, I can’t find that. 401 Sorry, you’re not allowed to request that. 500 HTTP Statuses
  21. HTTP/1.1 500 Internal Server Error 200 All good. Here’s your

    reply. 304 Nothing changed. Keep what you already have. 404 Sorry, I can’t find that. 401 Sorry, you’re not allowed to request that. 500 Sorry, we’re having problems right now. HTTP Statuses
  22. GET / HTTP/1.1 Host: rubyonrails.org Accept: text/html Accept-Encoding: gzip, deflate,

    sdch Accept-Language: en-US,en;q=0.8 Cache-Control: no-cache Connection: keep-alive
  23. DNS - Domain Name System Where is rubyonrails.org? Oh, you

    can find it at 192.30.252.153. Translate domain names into IP addresses. Client DNS Server
  24. Local Resolver (e.g. at internet service provider) rubyonrails.org? RECURSIVE Root

    Kingdoms DNS TLDs .org .com .net .io ? ITERATIVE (keep trying)
  25. Local Resolver (e.g. at internet service provider) rubyonrails.org? RECURSIVE Root

    Kingdoms DNS TLDs .org .com .net .io NS a0.org… a2.org… ? Try these kingdoms. ITERATIVE (keep trying)
  26. Local Resolver (e.g. at internet service provider) TLD Kingdoms DNS

    Please associate rubyonrails.org with my IP address. ns1.gratisdns.dk. ns2.gratisdns.dk. NS Kingdoms Please associate us with rubyonrails.org.
  27. Local Resolver (e.g. at internet service provider) TLD Kingdoms DNS

    ? NS ns1.gratisdns.dk. ns2.gratisdns.dk. Try these kingdoms. NS Kingdoms
  28. Local Resolver (e.g. at internet service provider) DNS NS Kingdoms

    rubyonrails.org? A 192.30.252.153 rubyonrailsftw.com?
  29. Local Resolver (e.g. at internet service provider) DNS NS Kingdoms

    rubyonrails.org? A 192.30.252.153 rubyonrailsftw.com? CNAME rubyonrails.org.
  30. ACKnowledging the package. Here’s your reply. ACK I’m not sure

    you got that package. I’ll try again! ? X
  31. X X X X X X X X X X

    X X X Congestion
  32. 2 3 ACK 1 1 Awaiting delivery 2 Delivered Sliding

    Window (being delivered) TCP Congestion Control
  33. 2 3 ACK 1 1 Awaiting delivery 2 Delivered Sliding

    Window (being delivered) TCP Congestion Control X X
  34. 2 3 ACK 1 1 Awaiting delivery 1 Delivered Sliding

    Window (being delivered) TCP Congestion Control X X
  35. 2 3 ACK 1 1 Awaiting delivery 1 Delivered Sliding

    Window (being delivered) TCP Congestion Control X X 2
  36. SYN TCP Connections - 3 way handshake 1. Client (requester)

    requests connection with SYNchronize packet. 1
  37. ACK-SYN Window = 1 SYN TCP Connections - 3 way

    handshake 1. Client (requester) requests connection with SYNchronize packet. 2. Server (recipient) ACKnowledges SYN and sends its own SYN. Server can specify initial window size to prevent too much coming in. 1 2
  38. ACK-SYN Window = 1 SYN TCP Connections - 3 way

    handshake ACK 1. Client (requester) requests connection with SYNchronize packet. 2. Server (recipient) ACKnowledges SYN and sends its own SYN. Server can specify initial window size to prevent too much coming in. 3. Client ACKnowledges server’s SYN and connection is established. 1 3 2
  39. Destination Next Hop 23.235.44.0/24 192.168.1.1 104.0.0.0/8 192.168.2.1 192.30.0.0/16 192.168.3.1 23.21.0.0/16

    192.168.4.1 Routing Tables Tell which location to go to next for a range of IP addresses. IP Address Range with CIDR Path to follow, i.e. the next router
  40. 192.30.252.153 8 bits = 2^8 = 256 numbers => 0-255

    4 of 2^8 => 0-255.0-255.0-255.0-255 IPV4 Addresses - Dotted Quads 0—255 1st quad 0—255 2nd quad 0—255 3rd quad 0—255 4th quad
  41. CIDR — Classless Inter-domain Routing 192.30.0.0/16 192.30.0.0/8 1. Use the

    first /8 bits to mask the first quad. Masks “lock” a number in. 2. Use the next /8 bits to mask the second quad. 3. This leaves a range of possible IP addresses to find a match in. 192.30.0.0/0 192.30.0-255.0-255 -or- 192.30.0.0 - 192.30.255.255
  42. Destination Next Hop 23.235.44.0/24 192.168.1.1 192.30.0.0/16 192.168.3.1 23.21.0.0/16 192.168.4.1 Destination

    Next Hop 107.20.0.0/16 192.168.5.1 192.30.252.0/24 192.168.6.1 Destination Next Hop 192.30.252.50.144/28 192.168.7.1 192.30.0.0/16 192.168.8.1 192.30.252.153? Routing Range grows smaller and more specific (mask grows larger).
  43. Router Buffer (hold unprocessed packets) No room for packets. They

    must be dropped. Requester must try again and potentially slow down sending rate.
  44. Router Buffer (hold unprocessed packets) No room for packets. They

    must be dropped. Requester must try again and potentially slow down sending rate. Slow down please! X X
  45. Router Buffer (hold unprocessed packets) No room for packets. They

    must be dropped. Requester must try again and potentially slow down sending rate. Slow down please! X X
  46. GET / HTTP/1.1 Host: rubyonrails.org Accept: text/html Accept-Encoding: gzip, deflate,

    sdch Accept-Language: en-US,en;q=0.8 Cache-Control: no-cache Connection: keep-alive
  47. • Physical distance and latency unavoidable • Persistent/shared TCP connections

    • Caching DNS queries • Caching HTML, scripts, images, etc. • Content distribution networks (CDNs) and mirrors • HTTP 2 Performance Matters!
  48. • https://commons.wikimedia.org/wiki/File:Cartoon_cloud.svg • https://commons.wikimedia.org/wiki/File:Checkmark_green.svg • https://commons.wikimedia.org/wiki/File:Computer.svg • https://commons.wikimedia.org/wiki/File:Gnome-web-browser.svg • https://commons.wikimedia.org/wiki/File:Modern_clock_chris_kemps_01.svg

    • https://commons.wikimedia.org/wiki/File:Network-server.svg • https://commons.wikimedia.org/wiki/File:Server-web.svg • https://commons.wikimedia.org/wiki/File:Server.svg • https://commons.wikimedia.org/wiki/File:Simple_crown_icon.svg • https://pixabay.com/en/metro-subway-tramway-159004/ • https://pixabay.com/en/postal-parcel-post-package-32383/ • https://pixabay.com/en/subway-map-transportation-metro-576776/ • https://upload.wikimedia.org/wikipedia/commons/3/3e/I-80_Eastshore_Fwy.jpg • https://commons.wikimedia.org/wiki/File:Osa_device-wireless-router.svg Sources