This is the sixth day of my participation in Gwen Challenge
Code word is not easy, your praise is my motivation to continue to update the creation.
What is a process? What is a thread?
Process definition
A process is a program in execution, that is, once a program is loaded into memory and ready to execute, it is a process. Process is the basic concept of resource allocation, the basic unit of scheduling operation, and the unit of concurrent execution in the system.
Definition of thread
Each task executed in a single process is a thread. A thread is the smallest unit of operation performed in a process. A thread can belong to only one process, but a process can have multiple threads. Multithreading allows multiple tasks to be performed at the same time in a single process.
To understand the relationship between the two, consider the following:
Process vs. Thread
First of all, we know that browsers can significantly improve performance when processing tasks using parallel processing rather than serial processing. Corresponding to the inside of the thread, that is, the single thread is serial, multithreading can achieve parallel. Thread is attached to process, and using multi-thread parallel processing in process can improve computing efficiency.
To sum up, the relationship between processes and threads has the following four characteristics:
- Any thread execution error in the process will lead to the crash of the whole process;
- Threads share data in a process.
- When a process is shut down, the operating system reclaims the memory occupied by the process.
- The contents of processes are isolated from each other. If processes need to communicate with each other, they need to use IPC.
Single-process browser era
Single-process browser means that all the functional modules of the browser run in the same process. These modules include networks, plug-ins, JS runtime environments, rendering engines and pages.
Disadvantages of single-process browsers:
- Unstable;
If the plug-in crashes or memory leaks, the main process of the browser is easily blocked and the browser crashes.
- Not smooth;
If there is special time consuming in the JS running environment, such as the execution of an infinite loop script, it will monopolize the whole county, resulting in the failure of the browser response, lag, etc.
- No security;
Plug-in module in the main process, can obtain any resources of the operating system, which gives malicious plug-ins to invade the computer can take advantage of the opportunity.
Multi-process browser era
Early multi-process architectures
This is Chrome’s process architecture when it was released in 2008. As you can see from the figure, Chrome’s page is running in a separate rendering process, and the plug-in in the page is also running in a separate plug-in process, and the communication between processes depends on IPC.
The multi-process browser solves these three problems well:
- Because processes are isolated from each other, a crash of one process does not affect browsers or other pages.
- Js also runs in the renderer process, so even if JS blocks the renderer process, it does not affect other pages.
- An added benefit of the multi-process architecture is the use of a secure sandbox, which you can think of as a lock placed on the process by the operating system. Programs in the sandbox can run, but they cannot write any data to your hard drive or read any data from sensitive locations, such as your documents and desktop. Chrome locks the plugin and renderer processes in a sandbox, so that even if a malicious program is executed in the renderer or renderer process, the malicious program cannot break through the sandbox to obtain system permissions.
Current multi-process architecture
As can be seen from the figure, the latest Chrome Browser includes: one main Browser process, one GPU process, one NetWork process, multiple rendering processes and multiple plug-in processes.
- Browser process. It is mainly responsible for interface display, user interaction, sub-process management, and storage.
- Render process. The core task is to turn HTML, CSS, and JavaScript into web pages that users can interact with. Both the typography engine Blink and JavaScript engine V8 run in this process. By default, Chrome creates a rendering process for each Tab Tab. For security reasons, renderers are run in sandbox mode.
- Process of GPU. In fact, Chrome didn’t have a GPU process when it was first released. The original intention of using GPU was to achieve 3D CSS effect, but later the UI interface of web page and Chrome were drawn on GPU, which made GPU become a common requirement of browser. Finally, Chrome has introduced GPU processes on top of its multi-process architecture.
- Network process. It is responsible for loading web resources on the page. It used to run as a module in the browser process until recently, when it became a separate process.
- Plug-in process. It is mainly responsible for the running of plug-ins. Plug-ins are prone to crash. Therefore, plug-ins need to be isolated through the plug-in process to ensure that the plug-in process crash does not affect the browser and page.
Disadvantages of multi-process model:
- Higher resource occupancy;
- More complex architectures;
The future of service-oriented architecture
In order to solve these problems, in 2016, the Chrome official team designed a new Chrome Architecture using the idea of “Services Oriented Architecture” (SOA). In other words, the overall Chrome architecture will move toward the “service-oriented architecture” of modern operating systems, where the various modules will be reorganized into separate services, each of which can run in a separate process. Access to services must use defined interfaces and communicate via IPC to build a more cohesive, loosely-coupled system that is easy to maintain and expand, better meeting Chrome’s goals of simplicity, stability, speed, and security.
Chrome eventually reconstructs UI, database, files, devices, and network modules into basic services, similar to operating system underlying services. Here is a diagram of Chrome’s “Service-oriented Architecture” process model: