YARN scheduling policies decide how computer resources are shared among tasks. This helps run many jobs smoothly without waiting too long.
YARN scheduling policies in Hadoop
scheduler-type: <policy_name> Common policies: - FIFO - Capacity - Fair
Set the scheduler type in YARN configuration files like yarn-site.xml.
Each policy has different rules for allocating resources.
scheduler-type: FIFO
scheduler-type: Capacity
scheduler-type: Fair
This example shows how to check and change the YARN scheduler using a Python client library. It prints the current scheduler, changes it to Fair Scheduler, then prints the new scheduler.
from pyhadoop import YarnClient # Connect to YARN cluster client = YarnClient() # Check current scheduler current_scheduler = client.get_scheduler() print(f"Current scheduler: {current_scheduler}") # Change scheduler to Fair Scheduler client.set_scheduler('Fair') # Verify change new_scheduler = client.get_scheduler() print(f"Scheduler changed to: {new_scheduler}")
FIFO is simple but can cause long waits if big jobs run first.
Capacity Scheduler is good for multi-tenant clusters with fixed resource shares.
Fair Scheduler tries to balance resource use so no job waits too long.
YARN scheduling policies control how cluster resources are shared.
Common policies are FIFO, Capacity, and Fair Scheduler.
Choosing the right policy helps run jobs efficiently and fairly.
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
