Event Based Simulation of The Backfilling Algorithm OOP

Event Based Simulation of The Backfilling Algorithm OOP tirgul No. 4 2006

Outline • The CPU allocation task – revisited • The Backfilling algorithm • Simulation – implementation issues

The 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 CPUS estimated run time • The task – Continuously decide which jobs to start and when to start

First Come First Served Revisited processors • Simple algorithm • Non optimal resource usage now time

Exploiting Free Resources processors • Start small tasks right now • Do not delay tasks ahead in the queue now time

Aggressive Backfilling (EASY) processors • Start small tasks right now • Do not delay the first task in the queue • Runs on real parallel machines now time

EASY Scheduler - Overview • Main data structures: – wait. Queue: a queue of waiting jobs – run. List: a list of running jobs • Calculate status parameters – shadow time – free CPUs • Find a backfill job

Data Structures • Wait. Queue – Sorted according to arrival time – For each job maintain • Number of requested CPUs • Estimated run time processors • Run. List – sorted by termination time now time 1 st 2 nd 3 rd 4 th

The Status Parameters • shadow time The expected time in which the first job in the queue can run – assuming no delays • free CPUs: The minimum of : processors – number of expected free CPUs after 1 st job in queue starts – the CPUs that are currently free Shadow time free CPUs (in the initial stage) now time 1 st 2 nd 3 rd 4 th

Calculating Status Parameters set exp. Capacity = capacity // current # free CPUs while exp. Capacity < first. Job. num. CPUs curr. Job = next job in run. List exp. Capacity = exp. Capacity + curr. Job. num. CPUs shadow. Time = curr. Job. Expected. Finish. Time free. CPUs = min ( exp. Capacity-first. Job. num. CPUs , capacity ) free CPUs (in the initial stage) processors Shadow time now time 1 st 2 nd 3 rd 4 th

Decision to Run a New Job – Including Backfilling Loop on jobs in wait. Queue in arrival order if ( job. num. CPUs > capacity) continue else if ( job is 1 st in wait. Queue || est. Term. Time. If. Starts. Now <= shadow || job. num. CPUs <= free. CPUs ) start job and update free. CPUs free CPUs (in the initial stage) processors Shadow time now time 1 st 2 nd 3 rd 4 th

Simulation 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 CPUS estimated run time, actual runtime • Output – Various statistics on waiting time for each algorithm (average wait time and slow down in our exercise)

Log File - Example Id Arrival time Run time # CPUs Expected Time

Implementation • 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

Scheduler – 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

Parsing Log Files • Scanner is too slow for reading complete large files • Solution – Use Buffered. Reader and File. Reader – Read each line using Scanner – Integers can be read using next. Int method of Scanner

Implementing 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?
- Slides: 17