The Corporate Office Inside Your CPU: A Visual Guide to Go’s GMP Model
Goroutines under the hood ( GMP Model )

Advertisements
Why go func() is so much faster than spawning a Thread?
If you write Go, you know the feeling of power. You type go func(), and suddenly, you have concurrency. You can spawn 10,000 of these "goroutines," and your laptop doesn’t even blink. But if you tried to spawn 10,000 Threads in Java or C++, your computer would likely crash.
Why? What makes Go different?
The answer lies in a clever piece of engineering called the GMP Model. Usually, explaining this involves complex diagrams of registers and schedulers. But today, we are going to explain it using something we all understand: A Corporate Office.
⚠️ The Problem: Humans are Expensive
To understand Go, we first have to understand the computer hardware. Imagine your CPU Core is a physical Office Desk. It’s just furniture. It can’t do work by itself. To get work done, you need a worker to sit at that desk.
In the Operating System world, this worker is called a Kernel Thread.
Here is the problem with standard Threads: They are heavy. Imagine every Worker (Thread) carries a massive backpack containing their lunch, gym clothes, and entire life history (Memory Stack).
Creating a Worker takes time (hiring/paperwork).
Switching Workers is slow. If Worker A needs a break, they have to pack up their bag, leave the room, and Worker B has to come in and unpack. This is called a Context Switch, and it wastes precious CPU time.
If you have 10,000 tasks, you do not want 10,000 heavy workers trying to share 4 desks. You’d spend all your time swapping seats and no time working
💡The Solution: The Go Way (The GMP Model):
Go solved this by changing the rules. Instead of hiring more Humans (Threads), Go focuses on managing the Tasks.
Let’s look at the diagram below. This is exactly how the Go Runtime looks under the hood.

Let’s meet the cast of characters:
1. The M (Machine) — The Human Worker
The M is the heavy Kernel Thread we talked about.
Role: This is the actual person doing the work.
Constraint: The OS manages them. We want as few of these as possible because they are expensive.
In Go: We usually only have one M per CPU Core. If you have a 4-core laptop, Go creates 4 Ms.
2. The G (Goroutine) — The Sticky Note
The G is your code.
Role: These are the tasks you want to run.
The Secret: Unlike the Human Worker (M), a Goroutine is tiny. It’s not a human; it’s just a Sticky Note (2KB of memory).
Benefit: You can create millions of sticky notes. They cost almost nothing.
3. The P (Processor) — The Inbox Tray
This is the magic sauce of Go. The P is a local context — think of it as a specific Inbox Tray full of sticky notes.
Role: It manages the queue of Goroutines (Gs) waiting to be run.
The Rule: A Human (M) cannot work without an Inbox (P).
Goroutines → Queue (P) → Worker (M) → CPU Core
1. The Local Queue (The Inbox Tray) Every Human Worker (M) has their own private Inbox Tray (P).
Speed: Because it is right on their desk, they can grab a note, finish it, and grab the next one instantly. No one else touches this tray. There are no “locks” required. It is lightning fast.
2. The Global Queue (The Community Notice Board) But what happens if a Worker generates too many Sticky Notes? Or what if a system-wide task comes in? It goes to the Global Queue.
Analogy: Think of this as a bulletin board in the hallway.
The Downside: To take a note from the hallway, the Worker has to stand up, walk out, and check the board. This is slower than using their own desk tray.
The Balance: Go Workers prefer their own Inbox (Local Queue). They only check the Global Queue if their own desk is empty.
⚡ The Overachiever (Work Stealing)
There is one final rule in this office: Nobody sits idle.
Imagine Worker A finishes all the sticky notes in their Inbox. They check the Global Queue (Notice Board), and it is empty too. Do they go home?
No. They turn to their neighbor, Worker B. If Worker B has a huge stack of notes, Worker A will literally steal half of the stack and start working on them. This ensures that all CPU cores stay busy 100% of the time, even if the work wasn’t distributed perfectly at the start.
🚨The Danger Zone: Blocking vs. Non-Blocking
This is where the magic really happens. What happens when your code needs to wait?
In the programming world, there are two ways to wait: Network Calls (web requests) and System Calls (file I/O). Go handles them very differently.
Scenario A: The “Network” Wait (Non-Blocking)
Your code says: “Fetch data from https://www.google.com/search?q=Google.com." In a normal language, the Worker would sit there waiting for the internet to respond.
In Go (The Netpoller): The Worker sees the Sticky Note needs internet. He doesn’t wait.
He takes that Sticky Note and moves it to a special “Pending” pile (The Netpoller).
He immediately grabs the next note from his Inbox and keeps working.
When the internet responds 50ms later, the Netpoller moves the note back to the Global Queue to be finished.
Result: The Human Worker never stops working. 1 Thread can handle 10,000 web requests.
Scenario B: The “File” Wait (Blocking Syscall)
Your code says: “Read this massive file from the Hard Drive.” This is a System Call. The Operating System forces the Worker to stop and wait for the disk. The Worker freezes.
In Go (The Handoff): If the Worker (M1) freezes, he is holding the Inbox (P) hostage! The other notes in the tray are stuck!
The Detach: The Go Runtime realizes M1 is frozen. It physically detaches the Inbox (P) from M1.
The Recruit: It wakes up a sleeping Worker (M2) from the break room.
The Handoff: It gives the Inbox (P) to M2.
M2 continues working on the other notes. M1 stays frozen until the file is read, then he goes to sleep in the break room.
The next time you type go func(), picture that Sticky Note. You aren’t spawning a heavy, expensive OS process. You are simply adding a tiny piece of paper to an Inbox. The Go Runtime (that hardworking Human M) will get to it instantly, processing your tasks with an efficiency that heavy OS threads could only dream of. 🤓☝️
Author's Note
Chamath P.
DevOps Engineer
DevOps Engineer writing practical guides on Kubernetes, CI/CD, IaC, and SRE — based on real production experience.
This article was written with AI assistance. All technical claims and code examples have been personally verified before publishing.
Advertisements