Computer network HTTP: HTTP / 1.x and HTTP / 2

  • The ultimate goal WEB performance
    • Reduce the delay to the client, allowing users to open the front pages as fast as possible and related interactions.
    • As little data is sent to the server, downloading data from the server as little as possible to reduce the round-trip (Round Trips).
      image
  • HTTP / 1.x defects
    • Thread is blocked, at the same time, requests for the same domain name has a number of restrictions, the number of requests exceeds the limit will be blocked.
    • HTTP/1.0
      • Defects: the browser and server to maintain only brief connection each time the browser requests a need to establish a TCP connection with the server, the server finishes processing the request immediately disconnect the TCP connection, the server does not track each user, no record of the past request.
      • Solution: Add non-standard headers --- Connection field Connection: keep-alive
    • HTTP/1.1
      • Improve
        • Persistent connections: the introduction of a persistent connection that does not close a TCP connection by default, can be multiplexed multiple requests, do not declare Connection: keep-alive (for the same domain name, most browsers allow simultaneous establishment of six persistent connections)
        • Pipeline Mechanism: i.e. inside the same TCP connection, the client may send multiple requests at the same time
        • Chunked transfer encoding: i.e., a data server each generate, on a transmission, instead of using streaming mode cache mode
        • Request new way: PUT, DELETE, OPTIONS, TRACE, CONNECT
      • Shortcoming
        • Although the connection allows the multiplexing TCP, but which is connected with a TCP, all data communications are carried out in sequence. A server request only processed, will then process the next request. If the preceding process is particularly slow, there will be behind many requests waiting in line. This will result in a "team head clogging."
      • Avoid ways: one is to reduce the number of requests, while the second is more open persistent connection.
  • HTTP/2.0
    • Feature
      • Binary format instead of text format: headers of HTTP / 1.1 is a text, the data may be a text or in binary. HTTP / 2.0 header information and body data are binary.
      • Full multiplexers: HTTP / 2.0 multiplexing TCP connection, in a connection, the client and server may simultaneously send multiple requests or responses, but not in the order of one to one, thus avoiding "head-of clogging . "
      • Header compression
        • HTTP protocol stateless, each request must be accompanied by lead so the information. Therefore, many are repeat request header fields, such as cookie, the same content every time must be accompanied.
        • For the same head, no longer via the request, transmitting only once.
        • Header information is transmitted using gzip compress or after compression.
        • The client and server at the same time maintaining a table header, all fields will be stored in this table to produce an index number, then do not send the same field, simply send the index number.
      • Server push
        • Unsolicited allows the server to take the initiative to send resources to the client
        • Content push through those clients will need to cache the client, avoiding the round-trip delay.

Guess you like

Origin www.cnblogs.com/xiaobaizzz/p/12301986.html