当前位置:网站首页>Go language series - synergy GMP introduction - with ByteDance interpolation
Go language series - synergy GMP introduction - with ByteDance interpolation
2022-07-24 04:04:00 【kkkkk7210】
Concurrency is not equal to parallelism ( Concurrency is not parallelism) —— Rob Pike
Go Language is especially suitable for writing high concurrency programs , Simple , Efficient , Cannot do without Go Language native support coroutines (go routine).
Different from traditional multithreading development ,Go Language makes development more convenient through a more lightweight collaborative process , At the same time, it avoids many difficulties that traditional multithreading development needs to face .
Go Concurrent programming of language , Understand two things —— Xiecheng and GMP Model
coroutines
stay Go In language , Coroutines are considered lightweight threads . Between the coroutine and the thread Go Scheduler Association of language . The relationship between coroutine and thread is M:N, Many to many .
Go The language scheduler schedules multiple coroutines to a thread , Or schedule a coroutine to multiple threads for execution .
If multiple coroutines are assigned to different threads , These threads are simultaneously used by different CPU Core processing , Then these coroutines are processed in parallel .
If a single core executes multiple threads , Threads occupy different time slices , obtain CPU Right to use , These processes are concurrent .

Introduction to simple collaborative process
This section will start with a simple program , Let's feel the synergy .
There is a program to check whether some websites can be accessed , Construct a links As url list .
package main
import (
"fmt"
"net/http"
)
// Sequential execution
func main() {
links := []string{
"http://www.baidu.com",
"http://www.jd.com/",
"https://www.taobao.com/",
"https://www.163.com/",
"https://www.sohu.com/",
}
for _, link := range links {
checkLink(link)
}
}
func checkLink(link string) {
_, err := http.Get(link)
if err != nil {
fmt.Println(link, "might be down!")
return
}
fmt.Println(link, "is up!")
}
The execution result is :
http://www.baidu.com is up!
http://www.jd.com/ is up!
https://www.taobao.com/ is up!
https://www.163.com/ is up!
https://www.sohu.com/ is up!
The current program can run normally , But there are serious performance problems . Network request is a time-consuming operation , Check one by one url, The previous request has been executed , It's the next request .
If several of the websites respond slowly , The overall time consumption is very high . This situation occurs in network access , Disk file access , Very common scenes .
Actually url There is no sequential dependency between , There is no stipulation to check first baidu, Re examination jd. If you can check concurrently , Can reduce the time .
GMP Model introduction
To be continued
ByteDance autumn trick is officially opened in advance , There is no written examination for all posts , This year is better early than late
My push code : YZSSR9U
Post links : https://jobs.toutiao.com/s/YEmNcK5
And good people , Do something challenging , Details are suddenly stamped -> Bytes to beat 2023 Campus recruitment research and development was officially launched in advance !
边栏推荐
- Histone research -- Characteristics and literature references of histones in Worthington calf thymus
- LAN SDN technology hard core insider 10 cloud converged matchmaker evpn
- 6-13 vulnerability exploitation -smtp brute force cracking
- Method sharing of saving data to CSV file in MATLAB
- Sqlserver backup restore
- SLAAC stateless address automatic configuration
- Extend the connection boundary, expand the business scope, and comprehensively move towards the era of Intelligent Cloud network 2.0
- Remember an online sql deadlock accident: how to avoid deadlock?
- iPhone手机绑定163邮箱解决方案
- postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint
猜你喜欢

Codeforces Round #807 (Div. 2) A - D

Avoid mistakes, common appium related problems and Solutions

PAT甲级 1041 Be Unique

【C语言】程序环境和预处理操作

mysql服务1主2从,主主,MHA配置详细步骤

直播课堂系统04-创建service模块

Machine learning notes - image homography estimation based on deep learning (homographynet)

Live classroom system 04 create service module

Worthington lysozyme technical description and literature reference

Solution to the problem of "out of sight, out of mind, out of order" in the training competition
随机推荐
Master chip csu18m92 develops intelligent scale scheme
Histone research -- Characteristics and literature references of histones in Worthington calf thymus
值为 0 流程,另一部分看括但不限于如下这题是
组合数(阶乘的质因子的个数,组合数的计算)
Machine learning notes - image homography estimation based on deep learning (homographynet)
postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint
May be a little useful cold knowledge
Baidu search cracking down on pirated websites: why Internet content infringement continues despite repeated prohibitions
Redis sentinel mode, master node check script
What if Adobe pr2022 doesn't have open subtitles?
[C language] program environment and preprocessing operation
Ship test / IMO a.799 (19) incombustibility test of marine structural materials
The impact of Patrick mchardy incident on the open source community
Combinatorial number (number of prime factors of factorials, calculation of combinatorial number)
会话技术相关
Hardware knowledge 3 -- IIC protocol
Matlab sound signal processing frequency diagram signal filtering and playing sound
mysql服务1主2从,主主,MHA配置详细步骤
1.7.1 right and wrong problem (infix expression)
MOS cameraization and digitization "includes designation (contro. skilled