# 6.4 The Weight of the World In the warehouse, no two days are the same. Sometimes the elephants are sprinting, sometimes they are sleeping, and sometimes they are fighting. We call the overall pattern of this activity the **Workload**. To understand why your database is slow, you must identify the "Shape" of your workload. ## The Three Shapes of Workload ### 1. The Hamster Wheel (CPU-Bound) A **CPU-bound** workload is one where the soldiers (Chapter 3) are working as fast as they physically can. They aren't waiting for anyone; they are just overwhelmed by the math. This usually happens when: - You are performing a **[[Operations/Sort|Massive Sort]]** of millions of rows. - You are in a **[[Operations/NestedLoop|Nested Loop Join]]** (Chapter 3.3) where the elephant is checking every row against every other row, millions of times. - You are calculating complex **Regular Expressions** or doing heavy **JSON** parsing. In this state, the elephant is sweating. The CPU usage is 100%. The stopwatches (Wait Events) will be mostly empty, because the elephant isn't waiting—he's just *busy*. ### 2. The Elevator Queue (I/O-Bound) An **I/O-bound** workload is one where the soldiers are mostly standing still. They want to work, but the **[[Chapter 6/6.2 - Disk Wait|Elevator from the Basement]]** is too slow. This is the most common workload for databases that outgrow their snack pile ([[Resources/Memory|Memory]]). The soldiers spend their entire shift tapping their feet in front of the elevator doors. CPU usage will look low, but the query will still take forever. ### 3. The Traffic Jam (Wait-Bound) A **Wait-bound** (or Lock-bound) workload is one where the soldiers are blocked by each other. This isn't about the hardware; it's about **[[Chapter 6/6.3 - Locks & Latches|Coordination]]**. If one elephant is painting a suitcase (Locking a row), a hundred other elephants might be standing in line behind him, unable to move. This is a common problem in "High Concurrency" systems where everyone is trying to update the same "Hot Row" (like a bank balance or a stock count). ## Knowing the Shape As a database detective, your first job is to look at the warehouse and ask: **"Is everyone sweating, or is everyone standing still?"** Once you know the shape of the workload, you know whether to buy a faster brain (CPU), a bigger desk (RAM), or a better set of traffic rules (Query Refactoring). --- [[Chapter 6/6.3 - Locks & Latches|← 6.3 - Locks & Latches]] | [[Chapter 6/6.0 - The Waiting Game|↑ 6.0 - The Waiting Game]] | [[Chapter 7/7.0 - The Cloud Scales|7.0 - The Cloud Scales →]]