Skip to content

Instantly share code, notes, and snippets.

@jmikkola
Created April 18, 2015 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmikkola/1b89cdd8cd0a4269a346 to your computer and use it in GitHub Desktop.
Save jmikkola/1b89cdd8cd0a4269a346 to your computer and use it in GitHub Desktop.

Hyperactive: HTTP/2 and Python

12:10pm Friday

Cory Benfield. (Core contributor to the requests library)

HTTP/1.1

  • HTTP/1.1 was standardized in 1996.
  • TCP works best if you keep a connection alive and keep sending data down it.
  • HTTP doesn't reuse connections.
  • HTTP/1.1 slows down the web currently, requiring strange techniques like spriting images to reduce the number of round trips
    • Though that technique tends to break caching

HTTP/2

  • It is a binary protocol. The headers are not longer human readable.
  • It's really tricky to correctly write a HTTP/1.1 parser that's completely standards-compliant
  • It's also hard to figure out how much resources to allocate to parsing
  • With binary protocols, you use less and more predictable resources, they are simpler, and faster

Efficiency

  • The added multiplexing so once TCP connections can do multiple things at the same time.
    • A request/response pair is now called a "stream", and has a stream ID (e.g. 56)
    • Individual things within a stream can be given a priority
  • Added header compression (in 1.1, sometimes the header is larger than the message)
    • Optimizing the structure (HPACK) that's specially designed for headers
    • Has special control codes to save lots of bytes
  • You can abort requests/responses without losing the connection
  • Server push - the server can send responses to requests it thinks you'll make
    • This is only for priming caches
    • The server also sends what request is thinks you'll make

Problems with it

  • It's harder to reason about
  • It maintains a lot of state, you can't replay any given request without the past requests
    • E.g. header compression may just request that you repeat header 5
  • It has awkward edge cases to make it backwards compatible.
  • It's inherently concurrent. It will likey require a pick up of async IO.

How do you play with it?

  • There are currently at least 34 implementations
  • e.g. hyper (a python client library, written by speaker)
    • Fits in basically the same place as httpclient. You build other libraries (like requests) on top of it.
    • It sounds like OS contributioos would be appreciated.
  • nghttp2, the reference implementation (client, server, proxy) - hard to compile
  • http2bin.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment