Loading content...
Imagine a busy restaurant where new customers continuously arrive, and the host always seats the most recent arrivals first. Early customers, despite arriving on time and waiting patiently, watch helplessly as newcomers are seated before them. Hours pass. The early customers remain standing. They've been starved of service—not because resources are unavailable, but because the allocation policy systematically disadvantages them.
This scenario captures the essence of starvation in database systems: a condition where a transaction waits indefinitely for a resource that is repeatedly granted to other transactions. Unlike deadlock, where transactions are blocked in a cycle and cannot proceed, starvation occurs when transactions could proceed but are perpetually passed over by the scheduling algorithm.
By the end of this page, you will have a deep understanding of what starvation is, how it differs from deadlock, the conditions that cause it, and why it represents a critical challenge in the design of fair and efficient concurrency control systems. You'll be able to identify starvation-prone scenarios and understand the theoretical foundations for preventing them.
Starvation (also called indefinite postponement or livelock in some contexts) occurs when a transaction is perpetually denied access to a shared resource, despite the resource being repeatedly available and granted to other transactions.
Formal Definition:
A transaction T is said to suffer starvation if:
In essence, starvation violates the liveness property of a system—the guarantee that every request will eventually be satisfied. A system that permits starvation is unfair, even if it is deadlock-free and achieves high throughput.
Deadlock occurs when transactions are blocked in a circular wait—none can proceed. Starvation occurs when a transaction can proceed but isn't allowed to. A deadlock-free system can still suffer from starvation. This distinction is crucial: solving deadlock doesn't automatically solve starvation, and many deadlock prevention schemes can actually increase starvation risk.
| Property | Deadlock | Starvation |
|---|---|---|
| Nature | Circular blocking—no transaction can proceed | Indefinite waiting—transaction could proceed but doesn't |
| Detection | Wait-for graph contains a cycle | No structural pattern; requires analysis over time |
| Effect | Transactions halt permanently until intervention | Transaction waits indefinitely while others proceed |
| Resolution | Abort one or more transactions to break cycle | Modify scheduling policy to ensure fairness |
| System Progress | System makes no progress (stuck) | System makes progress, but unfairly |
| Cause | Resource allocation creates circular dependency | Scheduling policy systematically disadvantages some transactions |
| Recovery | Deterministic (abort and restart) | May require priority adjustment or policy change |
Starvation arises from the interaction between resource contention patterns and scheduling policies. Understanding the root causes is essential for designing systems that guarantee fairness. The primary causes can be categorized as follows:
The Reader-Writer Problem: A Classic Starvation Scenario
Consider a database system where:
Now imagine this sequence:
Transaction T₂ never gets access to R because new readers keep arriving before all existing readers release their locks. The writer is starved.
To rigorously analyze starvation, we can model it using queuing theory and probabilistic analysis. This mathematical framework helps us understand when starvation is likely and how severe it might be.
Model Assumptions:
Key Metrics:
| Metric | Symbol | Definition |
|---|---|---|
| Arrival Rate | λ | Number of lock requests per unit time |
| Service Rate | μ | Number of locks granted/released per unit time |
| Utilization | ρ = λ/μ | Fraction of time resource is locked |
| Expected Wait Time | W | Average time a transaction waits for lock |
| Queue Length | L | Average number of transactions waiting |
Starvation in Priority Queuing Systems:
Consider a system with k priority classes, where class 1 has the highest priority. The expected waiting time for a transaction in class i is:
W_i = W_0 / [(1 - σ_{i-1})(1 - σ_i)]
Where:
Critical Insight:
If σᵢ approaches 1 for any i, the waiting time for lower priority classes (i+1, i+2, ...) approaches infinity. This is the mathematical definition of starvation:
Starvation occurs when lim_{t→∞} P(Tᵢ completes) = 0 for transactions in priority class i.
In practical terms: if high-priority transactions consume all available system capacity (ρ ≥ 1), low-priority transactions will wait forever.
A scheduling system is starvation-free if and only if every transaction that enters the waiting queue is guaranteed to be serviced in finite time. Mathematically, this requires that the scheduling algorithm satisfies the bounded waiting condition: there exists a finite upper bound B such that no transaction waits longer than B time units before being granted access.
Starvation is not merely a theoretical concern—it manifests in production database systems with serious consequences. Understanding these real-world scenarios helps database administrators and developers identify and mitigate starvation risks.
Scenario: Inventory updates for popular items compete with order placement transactionsProblem: Continuous order placement holds shared locks on inventory table, preventing inventory updates from acquiring exclusive locks. Result: Inventory counts become stale, overselling occurs, and manual intervention is required to force inventory updates through.Symptoms of Starvation in Production:
Database administrators often misdiagnose starvation as deadlock or performance issues. The key diagnostic signal is differential wait times—when transactions of similar complexity have wildly different completion times due to lock acquisition patterns.
In distributed systems and concurrency theory, liveness is a fundamental correctness property that guarantees something good eventually happens. It contrasts with safety properties, which guarantee that something bad never happens.
Applied to Database Locking:
A lock manager that prevents deadlock may still violate liveness if it permits starvation. This is why fairness becomes a critical design requirement.
| Property Type | Example Property | Violation Consequence |
|---|---|---|
| Safety | Mutual exclusion | Data corruption |
| Safety | Deadlock-freedom | System hangs completely |
| Liveness | Starvation-freedom | Some transactions never complete |
| Liveness | Bounded waiting | Unpredictable transaction latencies |
| Liveness | Lock-freedom | Progress depends on scheduler fairness |
The Fairness Hierarchy:
Computer scientists have identified several levels of fairness guarantees:
No Starvation (Weak Fairness): Every continuously enabled transaction will eventually execute.
Bounded Waiting (Strong Fairness): Every transaction waiting for a lock will get it within a bounded number of steps.
Lock-Free: At least one transaction makes progress, but individual transactions may starve.
Wait-Free: Every transaction makes progress; no transaction can starve.
Database systems typically aim for bounded waiting fairness as a practical balance between performance and fairness guarantees.
Leslie Lamport's Bakery Algorithm (1974) was one of the first algorithms proven to be starvation-free. Like taking a number at a bakery counter, each transaction receives a ticket and is served in ticket order. This simple invariant—serve in ticket order—guarantees bounded waiting. Modern database lock managers often use similar ticket-based or timestamp-based approaches.
Different lock types create different starvation patterns. Understanding how starvation manifests across lock modes helps in designing more robust concurrency control mechanisms.
Shared Lock Starvation Pattern:
Shared locks rarely create starvation among readers because they are compatible with each other. However, they frequently cause writer starvation when:
Scenario:
Time 0: T1 acquires S-lock
Time 1: T2 (writer) requests X-lock → waits
Time 2: T3 acquires S-lock (compatible)
Time 3: T1 releases S-lock
Time 4: T4 acquires S-lock (compatible with T3)
... writer never gets lock ...
Solution Approaches:
Unlike deadlock, which has a clear structural signature (cycles in the wait-for graph), starvation is difficult to detect because it is defined by temporal rather than structural properties. A transaction is starved not because of its position in a graph, but because of how long it has waited relative to when it should have been served.
Detection Approaches:
123456789101112131415161718192021222324252627282930
-- SQL Server: Detect potential starvation-- Transactions waiting more than 10 seconds SELECT r.session_id, r.blocking_session_id, r.wait_type, r.wait_time / 1000.0 AS wait_time_seconds, t.text AS query_text, r.start_time, DATEDIFF(SECOND, r.start_time, GETDATE()) AS total_elapsed_secondsFROM sys.dm_exec_requests rCROSS APPLY sys.dm_exec_sql_text(r.sql_handle) tWHERE r.wait_type LIKE 'LCK%' -- Lock-related waits AND r.wait_time > 10000 -- More than 10 secondsORDER BY r.wait_time DESC; -- PostgreSQL: Long-running lock waitsSELECT pid, usename, query, state, wait_event_type, wait_event, NOW() - query_start AS durationFROM pg_stat_activityWHERE wait_event_type = 'Lock' AND NOW() - query_start > INTERVAL '10 seconds'ORDER BY duration DESC;Detecting starvation after it occurs allows for reactive intervention but doesn't prevent the business impact. Production systems should focus on starvation prevention through proper scheduling policies rather than relying solely on detection. Detection is valuable for monitoring and alerting, but prevention must be built into the concurrency control design.
We've established a comprehensive understanding of the starvation problem in database concurrency control. Let's consolidate the key concepts:
What's Next:
Now that we understand what starvation is and why it occurs, the next page examines fairness in depth—the formal property that prevents starvation. We'll explore different fairness guarantees, their mathematical definitions, and how database systems implement fairness policies.
You now have a deep understanding of the starvation problem—its definition, causes, manifestations, and detection methods. This foundation prepares you to understand fairness policies and prevention strategies in the subsequent pages.