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

    View Slide

  2. We help brands excel.
    pushagency.io
    Your website, SimplyBuilt.
    simplybuilt.com

    View Slide

  3. View Slide

  4. ?

    View Slide

  5. 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

    View Slide

  6. HTTP
    DNS
    TCP/IP
    ROUTING
    The Destination
    rubyonrails.org
    192.30.252.153

    View Slide

  7. The Transportation
    HTTP
    DNS
    TCP/IP
    ROUTING

    View Slide

  8. The Directions
    HTTP
    DNS
    TCP/IP
    ROUTING

    View Slide

  9. Package
    Address
    Continent
    Kingdom
    Train
    Router Station
    Network Packet
    IP Address
    Physical Device
    Software Server
    Connection
    Router/Switch
    Legend

    View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. 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

    View Slide

  15. Can you send me
    your home page?
    Request
    Sure thing!
    Here you go!
    Reply

    View Slide

  16. 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

    View Slide

  17. GET
    POST
    PUT
    DELETE
    HTTP
    Methods

    View Slide

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

    View Slide

  19. 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

    View Slide

  20. 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

    View Slide

  21. 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

    View Slide

  22. 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

    View Slide

  23. Accept: */*
    Accept: text/html
    Content-Type: application/json
    Host: rubyonrails.org
    Content-Length: 42
    Key Value
    HTTP Headers

    View Slide

  24. Send back
    whatever you have.
    Accept: */*
    Accept: text/html
    Content-Type: application/json
    Host: rubyonrails.org
    Content-Length: 42
    Key Value
    HTTP Headers

    View Slide

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

    View Slide

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

    View Slide

  27. 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

    View Slide

  28. 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

    View Slide

  29. 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

    Ruby on Rails!
    HTTP
    Version
    Status
    Code
    Status
    Description
    HTTP Reply

    View Slide

  30. 200
    304
    404
    401
    500
    HTTP
    Statuses

    View Slide

  31. HTTP/1.1 200 OK
    200 All good. Here’s
    your reply.
    304
    404
    401
    500
    HTTP
    Statuses

    View Slide

  32. 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

    View Slide

  33. 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

    View Slide

  34. 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

    View Slide

  35. 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

    View Slide

  36. 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

    View Slide

  37. 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

    View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. View Slide

  42. View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. Local Resolver
    (e.g. at internet
    service provider)
    Root Kingdoms
    DNS

    View Slide

  48. Local Resolver
    (e.g. at internet
    service provider)
    rubyonrails.org?
    RECURSIVE
    Root Kingdoms
    DNS

    View Slide

  49. Local Resolver
    (e.g. at internet
    service provider)
    rubyonrails.org?
    RECURSIVE
    Root Kingdoms
    DNS
    ?
    ITERATIVE
    (keep trying)

    View Slide

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

    View Slide

  51. 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)

    View Slide

  52. Local Resolver
    (e.g. at internet
    service provider)
    TLD Kingdoms
    DNS
    NS Kingdoms

    View Slide

  53. 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.

    View Slide

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

    View Slide

  55. Local Resolver
    (e.g. at internet
    service provider)
    DNS
    NS Kingdoms

    View Slide

  56. Local Resolver
    (e.g. at internet
    service provider)
    DNS
    NS Kingdoms
    rubyonrails.org?

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  60. Local Resolver
    (e.g. at internet
    service provider)
    Root Kingdoms
    TLD Kingdoms
    DNS
    NS Kingdoms
    A
    Hierarchy

    View Slide

  61. Local Resolver
    (e.g. at internet
    service provider)
    Root Kingdoms
    TLD Kingdoms
    DNS
    NS Kingdoms
    A
    Hierarchy

    View Slide

  62. x 4 billion IP addresses
    = LOTS of storage
    Can you all update
    my address?

    View Slide

  63. View Slide

  64. View Slide

  65. TCP/IP
    Transmission Control Protocol

    View Slide

  66. TCP/IP
    Transmission Control Protocol

    View Slide

  67. View Slide

  68. ACKnowledging
    the package.
    Here’s your reply.
    ACK

    View Slide

  69. ACKnowledging
    the package.
    Here’s your reply.
    ACK
    I’m not sure you
    got that package.
    I’ll try again!
    ?
    X

    View Slide

  70. View Slide

  71. X
    X
    X
    X
    X
    X
    X X
    X
    X
    X
    X
    X
    Congestion

    View Slide

  72. Sliding
    Window
    (being delivered)
    Awaiting
    delivery
    1
    TCP Congestion Control

    View Slide

  73. Sliding
    Window
    (being delivered)
    Awaiting
    delivery
    1
    1
    TCP Congestion Control

    View Slide

  74. Sliding
    Window
    (being delivered)
    Awaiting
    delivery
    1
    ACK 1
    1
    TCP Congestion Control

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  80. View Slide

  81. TCP Connections - 3 way handshake

    View Slide

  82. SYN
    TCP Connections - 3 way handshake
    1. Client (requester) requests connection with SYNchronize packet.
    1

    View Slide

  83. 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

    View Slide

  84. 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

    View Slide

  85. View Slide

  86. 1
    Sliding Window
    1
    2
    2
    1
    Sequence
    Numbers

    View Slide

  87. 1
    Sliding Window
    1
    2
    2
    1
    Sequence
    Numbers
    Got #1…
    ACK 1

    View Slide

  88. Sliding Window
    1
    2
    2
    1
    Sequence
    Numbers
    Got #1…
    And #2!
    2
    ACK 1
    ACK 2

    View Slide

  89. View Slide

  90. View Slide

  91. 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

    View Slide

  92. CIDR — Classless Inter-domain Routing
    192.30.0.0/16

    View Slide

  93. 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

    View Slide

  94. 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

    View Slide

  95. 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).

    View Slide

  96. View Slide

  97. View Slide

  98. Router Buffer
    (hold unprocessed
    packets)

    View Slide

  99. Router Buffer
    (hold unprocessed
    packets)

    View Slide

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

    View Slide

  101. 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

    View Slide

  102. 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

    View Slide

  103. View Slide

  104. View Slide

  105. View Slide

  106. View Slide

  107. 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

    View Slide

  108. View Slide

  109. View Slide

  110. DNS
    Destination Next Hop
    192.30.0.0/16 192.168.3.1
    Routing
    TCP/IP
    ACK
    Recap

    View Slide

  111. DNS
    Destination Next Hop
    192.30.0.0/16 192.168.3.1
    Routing
    TCP/IP
    ACK
    Recap

    View Slide

  112. • 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!

    View Slide

  113. • 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

    View Slide

  114. Acknowledgement
    Illustrations by Marissa Roeper
    marissaroeper.com

    View Slide

  115. Thanks!
    by: Jeremy Fairbank
    @elpapapollo | github.com/jfairbank
    illustrations: Marissa Roeper
    marissaroeper.com

    View Slide