Distributed software architecture - transmission link

transmission link

Link refers to a passive point-to-point physical connection. A link is an important concept in computer networking, which refers to a physical or logical path connecting two network devices. In simple terms, a link is the path through which electrical signals or data are transmitted in the network. In a computer network, links can be divided into physical links and logical links. A physical link refers to the physical medium that connects two network devices, such as network cables and optical fibers. A logical link refers to a logical connection established through a network protocol, such as a connection in the TCP/IP protocol.

Link is a very important concept in computer network, it is responsible for connecting network devices and ensuring reliable data transmission.

Front-end optimization

Front-end design principles aimed at optimizing link transmission may no longer be used in the future, such as

  1. Minimize HTTP Requests, reduce the number of requests
    The means to reduce the number of requests are:
  • a. Sprite map (CSS Sprites)
  • b.CSS, JS file merge/inline (Concatenation/Inline)
  • c. Multipart Document
  • d. Media (picture, audio) inline (Data Base64 URI)
  • e. Combine Ajax requests (Batch Ajax Request)
  • f. … …
  1. Split Components Across Domains to expand the number of concurrent requests.
    Modern browsers (Chrome, Firefox) can generally support 6 (8 to 13 for IE) concurrent requests for each domain name. If you want to load a large number of pictures or other resources faster, you need to perform domain sharding (Domain Sharding) to synchronize pictures to different hosts or different domain names of the same host.
  2. GZip Components, enable compressed transmission
    Enabling compressed transmission can greatly reduce the size of content that needs to be transmitted on the network, saving traffic.
  3. Avoid Redirects, avoid page redirection
    When a page is redirected, it will delay the transmission of the entire document.
  4. Put Stylesheets at the Top, Put Scripts at the Bottom, adjust resource priority according to importance
    Put important resources at the head of HTML for priority download.
  5. … …

Connection number optimization

HTTP is an application layer protocol with TCP as the transport layer, but the combination of HTTP over TCP can only be said to be the result of TCP's current dominance on the Internet, and it cannot be said that the two work together is appropriate.

  • On the one hand, the main characteristics of HTTP transmission objects (HTML, JS, CSS, pictures, etc.) are large number, short time, small resources, and fast switching.
  • On the other hand, the TCP protocol requires the completion of the three-way handshake before data transmission can begin. TCP also has a slow start feature, resulting in the lowest transmission rate when the communication connection is established, and then gradually accelerates and stabilizes.

Since the TCP protocol itself is designed for long-term and large data transmission, the TCP protocol can only show the advantages of stability and reliability within a relatively long time scale, and it will not be because the cost of establishing a connection is too high. become a bottleneck.

The Dilemma of Developing Tricks

In order to alleviate the contradiction between HTTP and TCP, programmers are committed to reducing the number of requests sent on the one hand , and increasing the number of connections from the client to the server on the other hand . That is the fundamental basis for the two optimization measures of Minimize HTTP Requests and Split Components Across Domains mentioned above.

HTTP Archive sampled millions of URL addresses from 2016 to 2020, and came to a conclusion: when the average page request has not changed (the desktop end decreased by 3.8%, and the mobile end increased by 1.4%), TCP connections are continuing and Significantly decreased (36.4% on desktop and 28.6% on mobile), as shown in the figure below
insert image description here

insert image description here
The development of Tricks can not only save TCP connections, but also bring many side effects. for example,

  • After CSS Sprites merge multiple images, as long as one of the small images is used, the entire large image must be loaded; if a small image needs to be modified, the cache of the entire large image will be invalidated; the same is true for merging files such as styles and scripts;
  • When the media is embedded, in addition to bearing the cost of 1/3 of the transmission capacity expansion caused by Base64 encoding, the cache cannot be effectively used;
  • After merging asynchronous requests, the return time of all requests will be dragged down by the slowest request, and the overall response speed of the page will decrease;
  • Placing images under different subdomains will result in a greater DNS resolution burden;

Advantages and disadvantages of connection multiplexing technology

HTTP connection multiplexing technology, that is, persistent connection (Persistent Connection), or connection Keep-Alive mechanism. Its principle is to allow the client to hold one or more TCP connections to the same domain name for a long time. The typical method is to maintain a FIFO queue on the client. The connection is not automatically disconnected so that it can be taken directly when obtaining the next resource, avoiding the cost of creating a TCP connection .
However, the most obvious side effect of connection multiplexing technology is the " Head -of-Line Blocking" problem.

Solution:
In HTTP/1.x, the multiplexing technology of HTTP/2, an HTTP request is the smallest granular information unit in the transmission process, and it is difficult to recombine effective information;
in HTTP/2, a frame (Frame) is the smallest granularity An information unit that can be used to describe various data, such as headers and body of a request, or used as a control identifier (open stream, close stream).
Among them, stream (Stream) is a logical data channel concept, and each frame is accompanied by a stream ID to identify which stream the frame number refers to.
insert image description here
Contrary to HTTP/1.x, HTTP/2 itself becomes more suitable for transmitting small resources, such as transmitting 1000 small images of 10K, HTTP/2 is faster than HTTP/1.x, but transmitting 10 large images of 1000K , then HTTP/1.x should be faster.

transport compression

HTTP has long supported GZip compression, because the main content transmitted by HTTP, such as HTML, CSS, Script, etc., is mainly text data, so the benefits of enabling compression for text data are very high, and the amount of transmitted data will generally be reduced to original Some around 20%. For resources that are not suitable for compression, the Web server can automatically determine whether to compress the response according to the MIME (Multipurpose Internet Mail Extensions) type.
Several compression methods:

  • Static Precompression: Pre-compress static resources into .gz files and store them;
  • On-The-Fly Compression: done in the data stream of the memory;

The persistent connection mechanism no longer depends on whether the TCP connection is closed to determine whether the resource request is over. It reuses the same connection to request multiple resources from the same domain name.
This mechanism initially (HTTP/1.0) judges whether the transmission resource has ended based on Content-Length. But the Content-Length cannot be given after instant compression is started. Relying on Content-Length to determine the end of a transfer is flawed. The HTTP1.1 version fixes the defect and adds another " Chunked Transfer Encoding " ( Chunked Transfer Encoding ) resource end judgment mechanism, which completely solves the conflict between Content-Length and persistent connections.

Fast UDP network connection

If you want to fundamentally improve HTTP, you must directly replace the foundation of HTTP over TCP. Using the UDP protocol to replace the TCP transport protocol is a way of thinking. In 2013, Google enabled a transport protocol called Quick UDP Internet Connections (QUIC) on its servers (Google.com, YouTube.com, etc.). At the end of 2018, the IETF officially approved the HTTP/3 version number for HTTP over QUIC, establishing it as the latest generation of Internet standards.

The advantage of QUIC's own implementation is that it can control each stream independently. If an error occurs in one of the streams, the protocol stack can still continue to provide services for other streams independently.
Another design goal of QUIC is dedicated support for mobile devices. The main advantage on mobile devices is reflected in the response speed of network switching. QUIC proposes the concept of a connection identifier, which can uniquely identify the connection between the client and the server. Connect without relying on IP addresses.

Acho que você gosta

Origin blog.csdn.net/zkkzpp258/article/details/131741291
Recomendado
Clasificación