当前位置:网站首页>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.

边栏推荐
- Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!
- Idea connection MySQL custom generated entity class code
- ssh-keygen 配置无需每次输入密码
- Baidu map API drawing points and tips
- Getting to know cloud native security for the first time: the best guarantee in the cloud Era
- Kotlin shared mutable state and concurrency
- IList of PostgreSQL
- 【深度学习】NCHW、NHWC和CHWN格式数据的存储形式
- [deep learning] storage form of nchw, nhwc and chwn format data
- GO语言-goroutine协程的使用
猜你喜欢

【LeetCode】10、正则表达式匹配

A review of text contrastive learning

unity 等高线创建方法

Baidu map API drawing points and tips

box-sizing

Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire

One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?

在宇宙的眼眸下,如何正确地关心东数西算?

文本对比学习综述

【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
随机推荐
Detailed explanation of redis data types
Unity 热力图建立方法
MySQL log management, backup and recovery
leetcode 139. Word Break 单词拆分(中等)
遠程辦公之:在家露營辦公小工具| 社區征文
Overview of SAP marketing cloud functions (IV)
打败 二叉树!
专精特新“小巨人”再启动,“企业上云”数字赋能
postgresql之List
Defoaming
Puzzle (016.2) finger painting Galaxy
Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
Mit-6.824-lab4a-2022 (ten thousand words explanation - code construction)
AQS初探
Baidu map API drawing points and tips
Jericho turns on shouting in all modes to increase mic automatic mute [chapter]
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
15 differences between MES in process and discrete manufacturing enterprises (Part 2)
JS remove string spaces
The difference between V-IF and v-show