Level 1: Chrome’s multi-process architecture:

The distinction between concurrency and parallelism

  • Concurrency: The ability to multitask

  • Parallelism: The ability to multitask simultaneously

Process and thread:

As a student, I would like to share the most impressive statement I have heard in OS class: process is the smallest unit of resource allocation; A thread is the smallest unit of task scheduling.

  • Threads must exist depending on the process. Threads within the same process share process resources.

  • If a thread in a process crashes, the process crashes. But it will not affect the operating system.

  • Interprocess communication via IPC mechanism: shared memory, socket, pipe communication (via kernel)

Chrome multi-threaded architecture implementation:

  • Main process x 1: user interaction, child process management, storage management.

  • Network process x 1: Resource loading

  • GPU process × 1:3-D rendering

  • Rendering process XN: responsible for document parsing and sub-resource loading (one for each page)

  • Plug-in process x N: Because plug-ins are unstable, they need to be separated from other processes.

The second level: TCP/IP protocol layer 4 network model

  • OSI layer 7 model compared with TCP/IP layer 4 model

    My understanding is that OSI is a more prescriptive architecture, while TCP/IP is the best practice in the current network environment.

    In fact, in the undergraduate textbook, it’s abstracted as a five-level model:

    Application layer (application layer + presentation layer + session layer) => Transport layer => Network layer => Link layer => physical layer

    It can be seen that the specific layering is not the key, but whether the important function corresponding to the middle column of the figure above is implemented.

  • Packet wandering:

    This is a story that every undergraduate teacher is very good at telling. At that time, I did not quickly understand the basic principle of the net because of this story; But I have to admit, this example is still a good guide to my understanding of computer networks.

Domain Name System (DNS)

Prepend content

  • DNS task: for the given URL query its corresponding IP address.

  • There are two methods of DNS query: iterative/recursive;

    1. The browser queries queries from the local DNS server in recursive mode.

    2. The local DNS server queries queries from other servers in iterative mode.

  • DNS uses UDP for query: fast and efficient.

Inquiry process:

  1. The browser sends the URL to the local DNS server (LDNS);

  2. The local DNS server searches for the URL in the local cache. If there is a record of the URL and the record is valid, the DNS server returns the IP address. The DNS query process is complete.

  3. If the local DNS server does not have records corresponding to the URL, iteratively searches for the IP address.

  4. The local DNS server sends DNS packets to the root DNS server, and the root DNS server returns the IP address of the TOP-LEVEL DNS server based on the REQUESTED URL in the packets

  5. The local DNS server sends DNS packets to the TOP-LEVEL DOMAIN name server. The top-level domain name server returns the authoritative server address based on the REQUESTED URL in the packets.

  6. Repeat the process until you get the IP address for the final URL.

  7. The local DNS server writes the record of [IP, URL] to the cache and returns the IP address.

Level 4: SSL protocol – HTTPS

What is HTTPS?

HTTPS = HTTP + mixed encryption + authority authentication + integrity guarantee

Because the detailed introduction of HTTPS in the network is very rich, I will not go into detail here, and go directly to the conclusion.

Running mechanism of THE SSL protocol

The network contains two kinds of statement (3 random number to generate the key or 1 random number to generate the key), but the same, both adopt the symmetric encryption + asymmetric encryption mode:

  1. The Client sends the encryption suite list + random number client_RANDOM to the Server

  2. The Server returns the following information to the Client: Selected encryption suite + random number server_random + digital certificate (with public key)

  3. The Client verifies the validity of the digital certificate. If the certificate is valid, a random pre-master number is generated and the public key in the certificate is used for encryption. The encrypted data packet is sent to the Server

  4. The Server uses the private key to decrypt the packet and obtain the pre-master

  5. In this case, the two parties use the negotiated encryption suite to encrypt client_RANDOM + Server_RANDOM +pre-master to generate symmetric keys. This symmetric key can then be used for encrypted communication

Level 5: TCP

TCP Protocol Features

Connection-oriented, reliable transport layer protocol.

Three-way handshake

  • The basic purpose of the three-way handshake: to confirm whether the sending and receiving ability of our party and the other party are normal

  • Three-way handshake process:

    Both the Client and Server know that their sending and receiving capabilities are normal. Therefore, they need to determine the sending and receiving capabilities of the other party.

    1. First handshake: The Client sends a packet to the Server: SYN=1, seq=x;

    2. Second handshake: The Server receives a packet and sends a packet to the Client: ACK=1, ACK= x+1, SYN=1, SEq =y;

      The Server confirms that the sending capability of the Client is normal: The Client sends a SYN packet.

    3. Third handshake: After receiving the packet, the Client sends the ACK=1, SEq =x+1, and ACK= y+1 packets to the Server.

      The Client confirms that the sending and receiving capabilities of the Server are normal: the Server correctly receives and responds to the Client.

      The Server verifies that the receiving capability of the Client is normal: The Server receives an ACK from the Client.

  • Why not use two handshakes:

    Suppose that the last handshake is discarded, the Server cannot determine whether the receiving capability of the Client is normal.

Four times to wave

  • The purpose of the four-way handshake is to ensure that both data have been sent before closing the connection.

  • Four waves:

    1. First wave: The Client sends a FIN packet to the Server, indicating that the Client will not send data to the Server: FIN=1,seq=x

    2. Second wave: The Server sends an ACK packet to the Client to indicate the response: AKC=1, SEQ =y, ACK =x+1

      During this period, the Server can continue to send data to the Client, which is in the half-connection state of TCP.

      The Client needs to continue listening for packets sent by the Server.

    3. Third wave: The Server sends a FIN packet to the Client, indicating that the Server will not send data to the Client: FIN=1, SEq = Z, ACK =x+1

    4. Fourth wave: The Client sends an ACK packet to the Server to indicate the response: ACK=1, SEq =x+1, ACK= z+1. At the same time, wait for 2MSL. If no packet is received during this period, the TCP connection is disconnected.

  • Why four waves instead of three waves like the one used to establish a connection?

    This is because the server in the LISTEN state receives the SYN request and sends the ACK and SYN packets to the client in a single packet. When the connection is closed and the peer party receives a FIN packet, it only indicates that the peer party no longer sends data but can still receive data. The upper-layer application determines whether to close the data sending channel. Therefore, the ACK and FIN are usually sent separately.

  • Why wait for 2MSL?

    1. In the fourth handshake, the client sends an ACK but does not receive a response. Therefore, the client cannot confirm whether its ACK can arrive successfully. Therefore, it needs to wait for 2MSL to send the server a second FIN packet.

    2. Within 1MSL after the client sends an ACK, the timer on the server also expires. If the client does not receive an ACK for some reason, the server resends the FIN packet.

    3. The FIN file will reach the client within 1MSL; At this time, the timer of the client has not cleared. After receiving the FIN, restart the 2MSL timer and send back the ACK.

Level 5: ARP

define

  • Address resolution protocol is an important network transmission protocol that resolves IP addresses to find MAC addresses in network protocol packets. ARP is a link layer protocol.

The working process of the

  • On the same network segment: Broadcast Query -> Unicast response

  • Different network segments: broadcast query -> Unicast response -> Gateway relay -> Repeat

  • Reference: juejin. Cn/post / 689016…

What happens from the input URL to the page display?

Browser side:

  1. The user enters the URL

    The browser determines whether the string in the address bar complies with the URL naming rules. If not, the string will be submitted to the search engine for processing; If reasonable, go to the second step.

  2. Constructing HTTP Packets

    The GET url HTTP / 1.1

    The main process sends the packet to the network process through IPC.

  3. Find the file cache in your browser

    If the browser has requested the resource and the resource is not expired, the network process returns the cached file and intercepts the HTTP request. If no match is found in the cache, go to step 4.

  4. The DNS query

    See second DNS for details;

    The resulting IP is eventually returned to the browser’s network process.

  5. HTTP packets are processed at the application layer and are ready to be sent to the transport layer (TCP).

    Chrome has a limit on TCP connections (a maximum of six TCP connections can be maintained for the same domain name). If the number of TCP connections exceeds six, you need to wait in the TCP queue.

  6. If HTTPS is used, an SSL layer is added between HTTP at the application layer and TCP at the transport layer to ensure connection security

    See HTTPS above for details.

  7. Make a TCP three-way handshake connection:

    See the fourth level TCP protocol for details

  8. Transport layer TCP processes packets
    • The TCP layer divides HTTP packets into equal segments and adds TCP headers to the segments.

    • Add sequence number to header: ensure sequential delivery and reassembly at destination.

    • Add the source and destination port numbers to the header: confirm which application (port) the packet should be delivered to at the destination.

    • The segment is relegated to the network layer

  9. At the network layer, the IP protocol processes packet segments
    • Add an IP header, source IP address, and destination IP address to a packet segment.

    • The static or dynamic routing algorithm is used for routing at the network layer

  10. The link layer transmits packets
    • Added the Ethernet header to the IP packet and added the MAC address

    • Apply ARP to transmit data at the link layer. For details, see Level 6

Server side:

  1. Link layer and network layer:

    Remove the Ethernet header and IP header at a time and commit to the transport layer

  2. The transport layer reassembles the message and delivers it to the specified application
    • TCP ensures the correctness and integrity of the data according to the sequence number of the packet segment header and forms HTTP packets

    • HTTP packets are delivered to the application layer by the program with the destination port number specified in the TCP header

  3. The server analyzes the HTTP request and builds the response packet
    1. For the URL specified in the request line, see if a redirection is required.

      If redirection is required, the system returns 301 (permanent redirection) or 302 (temporary redirection) status code and writes the redirected address in the Location field of the response header.

    2. Check whether the resource corresponding to the if-none-match field in the request packet header is updated

      If the status code 304 is returned, the resource is not updated.

    3. Check whether the browser needs to be notified for caching

      If browser update is required, set cache-control: max-age=2000 (for example, 2000 seconds).

  4. The application layer on the server sends THE HTTP packet back to the client

    The process is the same as above.

  5. Close the HTTP connection

    Check whether the link is in the persistent state

    • HTTP1.0 uses Connection:keep-alive to declare long connections. Otherwise, short connections are used by default. Persistent links by default in HTTP1.1)

    • If a persistent connection is used, do not close the HTTP connection temporarily. For short connections, perform the HTTP wave four times (see level 5 for details)

Browser side:

  1. The network process receives HTTP response packets and analyzes them
    1. If the response status code is 301 or 302, the HTTP request packet is rebuilt. The URL is the URL corresponding to the location of the response packet

    2. If the response code is 304, the browser cache is used

    3. If the status code is 200, the request succeeds. Processing is based on the resource type.

  2. The data is processed according to the content-type
    • If the content-type is HTML /text, it is an HTML page, and the main thread of the browser is notified via IPC to prepare the page for rendering.

    • If the content-type is a byte stream, the download manager is used to download resources.

  3. Render the page and display it

    This part is quite complex (including the browser rendering process and Javascript execution mechanism)

    Please see the next blog share ~