Title: Event Based Simulation of The Backfilling Algorithm
1Event Based Simulationof The Backfilling
Algorithm
2Outline
- The CPU allocation task revisited
- The Backfilling algorithm
- Simulation implementation issues
3The CPU Allocation Task
- Task components
- Parallel computing machine with N CPUs
- A stream of request for running jobs
- Input for each job
- Id, arrival time, num of CPUSestimated run time
- The task
- Continuously decide which jobs to start and when
to start
4First Come First Served Revisited
- Simple algorithm
- Non optimal resource usage
processors
time
now
5Exploiting Free Resources
- Start small tasks right now
- Do not delay tasks ahead in the queue
processors
time
now
6Aggressive Backfilling (EASY)
- Start small tasks right now
- Do not delay the first task in the queue
- Runs on real parallel machines
processors
time
now
7EASY Scheduler - Overview
- Main data structures
- waitQueue a queue of waiting jobs
- runList a list of running jobs
- Calculate status parameters
- shadow time
- free CPUs
- Find a backfill job
8Data Structures
- WaitQueue
- Sorted according to arrival time
- For each job maintain
- Number of requested CPUs
- Estimated run time
- RunList sorted by termination time
processors
time
now
1st
2nd
3rd
4th
9The Status Parameters
- shadow timeThe expected time in which the first
job in the queue can run assuming no delays - free CPUsThe minimum of
- number of expected free CPUs after 1st job in
queue starts - the CPUs that are currently free
Shadow time
free CPUs (in the initial stage)
processors
time
now
1st
2nd
3rd
4th
10Calculating Status Parameters
- set expCapacity capacity // current free CPUs
- while expCapacity lt firstJob.numCPUs
- currJob next job in runList
- expCapacity expCapacity currJob.numCPUs
- shadowTime currJob.ExpectedFinishTime
- freeCPUs min ( expCapacity-firstJob.numCPUs ,
- capacity )
Shadow time
free CPUs (in the initial stage)
processors
time
now
1st
2nd
3rd
4th
11Decision to Run a New Job Including Backfilling
- Loop on jobs in waitQueue in arrival order
- if ( job.numCPUs gt capacity)
- continue
- else
- if ( job is 1st in waitQueue
- estTermTimeIfStartsNow lt shadow
- job.numCPUs lt freeCPUs )
- start job and update freeCPUs
Shadow time
free CPUs (in the initial stage)
processors
time
now
1st
2nd
3rd
4th
12Simulation of a Scheduler
- Goal
- analyze different schedulers
- Use records of running processes
- Input for each job
- Traces (log file) of real processes running on
real machines - Id, arrival time, num of CPUSestimated run time,
actual runtime - Output
- Various statistics on waiting time for each
algorithm (average wait time and slow down in our
exercise)
13Log File - Example
14Implementation
- Using event based simulation principles
- Main modules
- Simulator
- Maintains a priority queue of events
- Types of events job arrival, job termination
- Scheduler
- Maintains status of currently running jobs
- Maintains the wait queue
- Schedules jobs instructs the simulator when to
start
15Scheduler Implementation Issues
- Two types of schedulers
- Consider common and distinct features
- Simulator should work with different schedulers
- Note scheduler can instruct initiation of
several processes simultaneously - See Strategy pattern in design patterns
16Parsing Log Files
- Scanner is too slow for reading complete large
files - Solution
- Use BufferedReader and FileReader
- Read each line using Scanner
- Integers can be read using nextInt method of
Scanner
17Implementing a Priority Queue
- Can be implemented using a heap (required in the
exercise) - Assume heap size is not known in advance
- Handle memory allocation carefully
- Initialize an array with a reasonable size
- Inserting a new element to a full heap
- How do we expand the heap?