Home > Backend Development > Golang > How to achieve high concurrency in golang?

How to achieve high concurrency in golang?

coldplay.xixi
Release: 2022-05-13 09:51:56
Original
7302 people have browsed it

Golang’s method of achieving high concurrency: First, M is associated with a kernel thread, and through the scheduling of scheduler P, it connects to one or more G; then based on the one-to-one relationship between M and P, through P Schedule N Gs; finally realize the many-to-many relationship between kernel threads and Gs [M:N].

How to achieve high concurrency in golang?

golang’s method of achieving high concurrency:

go language uses MPG mode to implement CSP

Video Course Recommendation →: "Concurrency Solution for Tens of Millions of Data (Theory and Practical Combat)"

has a lot to do with traditional concurrency Threads will only increase CPU and memory overhead. Too many threads will consume a large amount of computer hardware resources, causing a concurrency bottleneck.

  • M refers to Machine. An M is directly associated with a kernel thread.

  • P refers to "processor", which represents the context environment required by M and is also the processor that handles user-level code logic.

  • #G refers to Goroutine, which is actually a lightweight thread in nature.

How to achieve high concurrency in golang?

My personal understanding: M is associated with a kernel thread, and through the scheduling of scheduler P (context), one or more can be connected G is equivalent to dividing a kernel thread into N user threads. M and P have a one-to-one relationship (but the relationship changes in actual scheduling). N Gs are scheduled through P (P and G have a one-to-many relationship). ), realizing the many-to-many relationship (M:N) between the kernel thread and G. In this way, one kernel thread can start N Goroutines, and the number of user threads available for machines with the same hardware configuration will increase geometrically, and the concurrency will be greatly increased. improve.

Related learning recommendations: Go language tutorial

The above is the detailed content of How to achieve high concurrency in golang?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template