YARN scheduling policies in Hadoop - Time & Space Complexity
We want to understand how the time to schedule tasks grows as more jobs and resources are involved in YARN.
How does the scheduler handle more work and what affects its speed?
Analyze the time complexity of the YARN Capacity Scheduler's allocation loop.
for each queue in queues:
for each application in queue.applications:
for each container request in application.requests:
allocate container if resources available
This code tries to allocate containers to applications in each queue based on resource availability.
Look at the loops that repeat work:
- Primary operation: Nested loops over queues, applications, and container requests.
- How many times: Number of queues (q), times number of applications per queue (a), times container requests per application (r).
As the number of queues, applications, and requests grow, the scheduler does more work.
| Input Size (q, a, r) | Approx. Operations |
|---|---|
| 10 queues, 5 apps, 3 requests | 10 * 5 * 3 = 150 |
| 100 queues, 10 apps, 5 requests | 100 * 10 * 5 = 5,000 |
| 1000 queues, 20 apps, 10 requests | 1000 * 20 * 10 = 200,000 |
Pattern observation: The work grows quickly as more queues, applications, or requests are added.
Time Complexity: O(q * a * r)
This means the scheduling time grows proportionally to the number of queues, applications, and container requests.
[X] Wrong: "The scheduler time only depends on the number of applications."
[OK] Correct: The scheduler also loops over queues and container requests, so all three affect the time.
Understanding how scheduling time grows helps you design better resource managers and explain system behavior clearly.
"What if the scheduler used a priority queue to pick applications instead of looping over all? How would the time complexity change?"
Practice
Solution
Step 1: Understand FIFO Scheduler behavior
FIFO (First In First Out) scheduler assigns resources to jobs strictly by arrival time, ignoring job size or priority.Step 2: Compare with other schedulers
Capacity Scheduler and Fair Scheduler consider resource sharing and fairness, while Priority Scheduler uses job priority.Final Answer:
FIFO Scheduler -> Option CQuick Check:
FIFO = order by arrival [OK]
- Confusing FIFO with Fair Scheduler
- Thinking Capacity Scheduler ignores job order
- Assuming Priority Scheduler is default
capacity-scheduler.xml file?Solution
Step 1: Identify correct property prefix for Capacity Scheduler
The Capacity Scheduler uses properties starting withyarn.scheduler.capacity.Step 2: Verify queue configuration syntax
The propertyyarn.scheduler.capacity.root.queuesdefines queues like default and production.Final Answer:
<property><name>yarn.scheduler.capacity.root.queues</name><value>default,production</value></property> -> Option AQuick Check:
Capacity Scheduler uses yarn.scheduler.capacity prefix [OK]
- Using fifo or fair prefix for Capacity Scheduler
- Misspelling property names
- Confusing queue names with scheduler types
<pre>queueA: minResources=2GB, maxResources=10GB queueB: minResources=4GB, maxResources=8GB Currently, queueA is using 3GB and queueB is using 5GB.
Which queue can get more resources if a new job requests 3GB?
Solution
Step 1: Check current usage vs maxResources
queueA uses 3GB, max is 10GB, so it can get up to 7GB more. queueB uses 5GB, max is 8GB, so it can get 3GB more.Step 2: Assess if requested 3GB fits
queueA can allocate 3GB (3+3=6GB <= 10GB). queueB can allocate 3GB (5+3=8GB = max), so it can also get 3GB.Step 3: Consider Fair Scheduler policy
Fair Scheduler tries to balance usage. Since queueA is below queueB usage, it will prioritize queueA for extra resources, but queueB can also allocate the requested resources up to its max.Final Answer:
Both queueA and queueB -> Option BQuick Check:
Fair Scheduler favors less used queue but both can allocate requested resources [OK]
- Ignoring maxResources limits
- Assuming both queues get resources equally
- Not considering current usage in decision
Solution
Step 1: Understand Capacity Scheduler behavior
Capacity Scheduler allocates resources based on configured queue capacities.Step 2: Identify cause of starvation
If queue capacities are not set correctly, some queues may get more resources, starving others.Step 3: Rule out other options
Missing property would cause scheduler failure, not starvation. FIFO and Fair Scheduler are different policies, not overriding Capacity Scheduler if configured correctly.Final Answer:
Queue capacities are not properly set, causing imbalance -> Option AQuick Check:
Capacity settings control resource distribution [OK]
- Assuming missing property causes starvation
- Confusing scheduler types
- Ignoring capacity configuration importance
Solution
Step 1: Understand multi-tenant resource needs
Departments need guaranteed minimum resources but flexible usage if available.Step 2: Match policy features
Capacity Scheduler supports minimum and maximum queue capacities, ensuring guarantees and flexible sharing.Step 3: Rule out other policies
FIFO does not guarantee resources per tenant. Fair Scheduler can share fairly but may lack strict minimum guarantees. Priority Scheduler focuses on job priority, not resource guarantees per tenant.Final Answer:
Capacity Scheduler with minimum and maximum queue capacities set -> Option DQuick Check:
Capacity Scheduler = guaranteed min + flexible max [OK]
- Choosing FIFO for guaranteed resources
- Ignoring min capacity in Fair Scheduler
- Confusing priority with resource guarantees
Ready to prove it?
Pass the test and this pattern moves unknown
