Bean curd powder, son, it is the job hunting season yue four, today this issue by beating byte data platform of “HMJ not conger chicken”, to share in the front end of the interview may have a knowledge about browser “why is much Chrome process rather than a single process”, this article to help everybody combed the knowledge content, let you can better understand ~
A year’s plan in spring, I wish you are looking for a new job, offer to get soft, money more ~ below 👇 let us start reading it.
Author: HMJ is not braised chicken
The first thing you need to know is the relationship between a process and a thread
- The failure of any thread in the process can cause the entire process to crash.
- Threads share data in the process.
- The contents of the processes are isolated from each other, and if one process crashes or hangs, it does not affect the other processes. Interprocess communication is through the IPC mechanism.
- After a process is shut down, the operating system reclaims the memory occupied by the process.
Browsers have single-process architecture and multi-process architecture
Single-process architecture browser
All function modules run in the same process, which can make the browser unstable, unstable, and insecure.
- unstable
The functional modules of the single-process browser run in the same process and run in a multi-threaded manner. If one thread crashes or something goes wrong, the whole process may crash. For example, the javascript environment runs in a page thread and can crash the entire browser due to an unexpected crash of the code.
- Not smooth
Page rendering, page rendering, JavaScript environment, plug-ins, and so on all run in the same page thread, meaning that only one task can be executed at a time. For example, writing a wireless loop script to run in a single-process browser page will monopolize the page thread, resulting in other tasks cannot be executed, resulting in the entire browser unresponsive and stuttering. Another page memory leak is also a cause of lag.
- unsafe
Plug-ins or scripts obtain system permissions through the browser, causing security problems.
Browser with multi-process architecture
Official documentation for Chrome
Adopting multiple processes makes the browser more fault tolerant, provides security, and sandboxes. Because the operating system can provide methods to limit the ability of each process has, so the browser can make some processes can only have a specific function, such as Chrome Tab of the limit of system files, speaking, reading and writing, but multi-process browser has a defect, is the process of memory footprint is relatively more, but the Chrome in order to save memory, It limits the number of processes that can be started. When the number of processes reaches the threshold, all tabs that visit the same site are run in the same process.
What processes does Chrome have
- The Browser Process is the main Process of the Browser. It is mainly responsible for the address bar, forward and back buttons, network access, file access, etc.
- Renderer Process, which controls the display of all content in the tabs of the site.
- Plugin Process, which controls all plug-ins used by the site.
- GPU (GPU Process), which processes GPU tasks in isolation from other processes. Gpus are divided into different processes because they Process requests from multiple applications and draw them on the same surface.
- The NetWork Process, which is responsible for loading web resources for a page, is now a separate thread that was previously run in the browser Process.
What happens when you type in a URL in the Chrome address bar?
- When entering an address, the UI thread in the browser process resolves whether to search for the content or the URL.
- When the user confirms the input, the UI thread forwards the URL to the network process, which initiates a network request and waits for a response.
- The network process receives the response header data, parses it, and forwards it to the browser process.
- After receiving the response header data, the browser process sends a CommitNavigation message to the renderer process.
- The renderer process is ready to receive HTML data by establishing a data pipeline with the network process.
- The renderer sends a “confirm submit” message back to the browser process, telling the browser process that it is ready to receive page data.
- The browser process removes the old document and updates the page state.
Service-oriented architecture
In Chrome’s task Manager, you can see that Chrome is already moving in this direction. Network Service, Storage Service, etc., have been servified, so that these functions can be run in different processes or combined into a single process.