Process? Thread? Silly? Unclear

Today, I’m going to learn about the browser. I want to make my knowledge system more systematic to learn about processes and threads
What is a process? What is a thread? What is the use? Let’s refer to the architecture of Chrome browser to understand the relationship and use of the two

Let’s take a look at such an interesting situation. We only open a page. Why does it appearFour processesIt’s important to note that this isFour processes!!!

Process? Thread? Silly? Unclear

With this in mind, let’s first understand a question: what is parallel processing???

A: parallel processing in computer is to process multiple tasks at the same time. If we want to calculate the values of these three expressions and display the results.

A = 1+2
B = 20/5
C = 7\*8

When writing code, we can divide this process into four tasks:

Task 1 is to calculate a = 1 + 2;
Task 2 is to calculate B = 20 / 5;
Task 3 is to calculate C = 7 * 8;
Task 4 is to show the result of the last calculation.

Under normal circumstances, the program can make ⽤ single thread to process, that is, it can perform these four tasks in four steps in order.

How to deal with multithreading

Step 1: perform tasks 1, 2, 3 at the same time
Part II: final task 4

Wow, this will save a lot of time,Greatly improved our performance

Hahaha, yes, multithreading can greatly improve performance, butThreads cannot exist independently, they are started and managed by processesWhat is the process???

A process is an instance of a program running.Is to start a program, the operating system will create a block of memory for the program to useIt stores the code, the data in the operation and the main thread that performs the task,Let’s take this oneOperating environmentIt’s calledprocess

Let’s take a look at this comparison chart

Process? Thread? Silly? Unclear
As you can see from the figure,The thread is attached to the process, and the use of multi thread parallel processing in the process can improve the efficiency

To sum up, processes and threads have the following four characteristics:
1. Any one of the processesthread Execution error will lead to the whole processprocesscollapse

2. thread Share betweenprocessData in
Process? Thread? Silly? Unclear

As can be seen from the figure above, thread 1, thread 2 and thread 3 write the execution results to a, B and C respectively, and then thread 2 continues to read data from a, B and C to display the execution results.

3. When a process is shut down, the operating system will reclaim the memory occupied by the process

When a process exits, the operating system will recycle all the resources requested by the process. For example, if you close the page of Chrome browser, the resources occupied by the page will be recycled by the system

Note: even if any of the threads have memory leaks due to improper operation, the memory will be recycled

4. The contents between processes are isolated from each other
A process a and a process B are isolated from each other and cannot be accessed. If you need data communication between processes, you should use IPC

Why change the architecture? What was the previous architecture?

Why should we change the structure? It must be because the times are advancing

You don’t talk nonsense, er… So, his change of architecture certainly can’t meet the needs of users in a stage. You may not have experienced it, but I have experienced it. It’s not Chrome browser, it’s ie

When I opened many pages, one of them crashed, but it caused the whole browser to cool down… WTM… The mentality exploded, ha ha ha, that was the case at that time – that was the case at that timeThe era of single process browser

He runs all the process modules in one processIf you think about it, I opened five pages, all of which are in the same process. If one of my pages collapsed, it must have driven other pages. Why didn’t I feel anything at that time? I still can bear it. Alas, it’s hard to say. Without comparison, there would be no harm!!!

Let’s make a comparison according to the previous architecture

Problems in single process browser:

Problem 1: instability

Obviously, the previous browser is very unstable, specifically, the previous browser to achieve web video, WAB games, etcplug-in unitTo achieve, the plug-in itself is unstable, you are still running in the browser, a plug-in crash, oh also… Collective cool, right!!!

No, the plug-in is stable. OK, the plug-in is stable,Rendering engine modelBlock is also unstable. It’s very difficult to realize this demand with this salary, ha ha ha

Problem 2: not smooth

Why is it not smooth? It’s very simple. I wrote an infinite cycle script and put it into the browser. Hahaha, as long as you open my page, your browser will be cool. Er… The operation is pretty coquettish~~

In addition to this, think about it. Besides JS code running in this process, there are plug-ins… You guarantee that you will not traverse? Er… TMD. Hahaha, at this time, the state of mind will collapse? It’s a little early! What else does TM have?Page memory leak

How can he…, the problem page is closed? No, first of all, the browser’s kernel is very complex, running a complex page, there will be memory can not be fully recycled, this needs to be understood, but with the use of time, the memory occupation is higher, the browser is slower and slower, ah… God, this thing can be used??? Ha ha ha, don’t worry, there are problems… It’s not over!!!

Problem 3: it’s not safe

If a plug-in releases a virus, or a page releases a virus and steals your account password, hey, think about other pages in the same process… Wocao, the legend of my login, my playful blue moon, why the equipment was sold all night… Ha ha ha, TMD… I think of the time when I was stolen

Features of multi process browser:

Feature 1: solve instability

Processes are isolated from each other, one of youpageProcess crash, eh? The browser is OK, ha ha ha, this page is closed and then opened

Feature 2: the solution is not smooth

A page dead cycle, tens of millions of pages not how, ha ha ha, that I this pageMemory leakWhy? Don’t panic, close this page, the return will be recycled by the system, nice, Nb!!!

Feature 3: security issues

Here’s a noun that you should have heard,Safety sandboxWhere there are problems, they will be put into the sandbox. Malicious programs can’t break through the sandbox to obtain system permissions. Oh, roar? Number theft? There is no drop

Now you should understand why there are four processes to open a chrmoe page. At least one network process, one browser process, one GPU process and one rendering process are required. If a plug-in is running, there will be another plug-in process

So there are no shortcomings in the current multiprocessing architecture?
What do you want? What do you need without shortcomings? Hahaha

Disadvantage 1: higher resource consumption

Each process will contain a copy of the common infrastructure (JS running environment), which means that more memory resources will be consumed, and 128G of memory will be replaced. Ha ha ha

Disadvantage 2: more complex architecture

High coupling and poor scalability among browser modules will make it difficult for the current architecture to adapt to new requirements, unpredictable changes of the times, and difficult for developers

To solve the above problems, in 2016, the chrome team usedService Oriented Architecture, I wipe, so tall in 2016???

In this way, the original various modules form independent services, and each service will run in an independent process. To access the service, you must define the interface and communicate through IPC, so as to build a serviceMore cohesive, loosely coupled, easy to maintain extended system

I won’t elaborate more here


  1. We learned what a process is, what a thread is, and how they relate to each other
  2. We understand why there is a multi process architecture, its advantages and disadvantages of a single process architecture
  3. We know the future development direction of Chrome browser, which will be a long process of continuous updating and iteration, and also a long process that our technical personnel need to constantly understand and study

Well, let’s talk here, pay attention to it, avoid getting lost, update it every week from time to time, not quantitatively!!!

Thank you for your support!!!

Recommended Today

Envoy announced alpha version of native support for windows

Author: sunjay Bhatia Since 2016, porting envoy to the windows platform has been an important part of the projectOne of the goalsToday, we are excited to announce the alpha version of envoy’s windows native support. The contributor community has been working hard to bring the rich features of envoy to windows, which is another step […]