当前位置:网站首页>Go language concurrency model mpg model
Go language concurrency model mpg model
2022-06-24 14:21:00 【Crying while learning】

Go There are three important components in the language scheduler :M、P、G
- M yes Machine, System threads . It is managed by the operating system ,goroutine Just run in M Above .M It's a big structure , It maintains small object memory cache(mcache)、 Currently executed goroutine、 Random number generator and so on .
- P yes Processor, Represents the program execution context 、 processor .P It can be seen as a local scheduler ,P Will wait to run G And M Docking . It maintains a goroutine queue , namely runqueue.GO The runtime system will make M and P Build or disconnect in time .
- G yes goroutine, There can be multiple . It contains the stack 、 Instruction pointer 、 Waiting place channel, And other effects on scheduling goroutine Important information .
MPG Model

Ongoing goroutine For blue , In a state of pending execution goroutine It's gray . Execu goroutine All stored in runqueue in ,P Maintainer this runqueue. Whenever by new goroutine Be performed , Will join in runqueue.
Actually go Language runtime systems did not exist in the early days P The concept ,go The language scheduler directly puts G Assign to the appropriate M On . But the problem with this is G The concurrent runtime needs to apply for resources from the system , It will cause performance loss .
from go Of 1.1 Version start , Add... To the runtime system P, from P To manage G object ,M Want to run G You need to bind P. The advantage of this is , Can be in P Object to apply for some system resources in advance , When G When you need it, ask your P To apply .P If resources are not enough , To apply for resources from the global , And will take some more resources for the later G To use the .
and P Decoupled M and G The relationship between . If there is G There's a blockage ,P You can take other G With the new M Binding , bring G It always works in time , To improve concurrency .
goroutine happening

M1 May be newly created , It may also be taken directly from the cache .
When G0 When blocking occurs ,P Will be with the current M0、G0 Unbundling .M1 And P Binding , Carry on P Others under goroutine.
runqueue Execution completed
When Processor Of runqueue Execution completed , It's empty time . He will learn from others Processor Steal half of the goroutine.

边栏推荐
猜你喜欢

GO语言并发模型-MPG模型

leetcode:1504. Count the number of all 1 sub rectangles
![[leetcode] 10. Regular expression matching](/img/a9/4cdf8d46068a2d7ea6ac212f416157.png)
[leetcode] 10. Regular expression matching
![[deep learning] storage form of nchw, nhwc and chwn format data](/img/4f/4478d96132eb2547f6ec09ae49639e.jpg)
[deep learning] storage form of nchw, nhwc and chwn format data

The function and principle of key in V-for

Win10 system problems

远程办公之:在家露营办公小工具| 社区征文

Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers

常见的单例模式&简单工厂

Common singleton mode & simple factory
随机推荐
专精特新“小巨人”再启动,“企业上云”数字赋能
常见的单例模式&简单工厂
SAP Marketing Cloud 功能概述(三)
Daily knowledge popularization
R语言构建回归模型诊断(正态性无效)、进行变量变换、使用car包中的powerTransform函数对目标变量进行Box-Cox变换(Box–Cox transform to normality)
Telecommuting: camping at home office gadgets | community essay solicitation
Linux 安装 CenOS7 MySQL - 8.0.26
六月集训(第24天) —— 线段树
Halcon 绘制区域 到图片中
根据前序&中序遍历生成二叉树[左子树|根|右子树的划分/生成/拼接问题]
遠程辦公之:在家露營辦公小工具| 社區征文
ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)
greendao使用问题
Solution of channel management system for food and beverage industry: realize channel digital marketing layout
A review of text contrastive learning
Common sense knowledge points
Return to new list
Detailed explanation of redis data types
Convolution kernel and characteristic graph visualization
数据库一些基本操作(提供了原数据库信息)