Simulating Process Scheduling Algorithms

Figuring out the best scheduling algorithm can be quite involved. In deterministic modeling throughputs, average wait time, CPU utilization, and response times are measured for a predetermined workload.

A simulation generates a random workload and uses the actual scheduling algorithm to run the simulated processes, tracking the important parameters as it goes.

A good simulator is a useful tool that can be used to answer many questions about sharing N resources among M consumers.

Use Cases

For example, the user might begin a simulation by creating a few processes with accompanying start times:

-> newProc 0
ok
-> newProc 0
ok
-> newProc 1
ok

The user can get a look at the system using the display statistics command:

-> display
clock = 0
schedule =
   <proc[0, {4, 3, 6, 9, 2}], proc[0, {1, 8}, proc[1, {2, 4, 9}]>

The user starts the simulation using the run command:

-> run

I imagine that the statistics are displayed automatically during this time. If the simulation is running in a separate thread from the UI (which happens automatically if we have a GUI) then the user can stop the simulation using the stop command:

-> stop

When the simulation ends, the schedule should be empty:

-> display
clock = 35
schedule = <>

Design

Implementation

1. Customize the Sim framework.

2. A process has two fields:

int[] bursts; // = CPU burst times
int next = 0;

The bursts array has random length and contains random positive integers.

burst[next++]

represents the amount of CPU time (as measured by the simulator's clock) that the process will consume the next time it runs. A process has terminated when:

bursts.length <= next

3. Every run event and ready event is associated with a process. Firing a ready event adds a process to the ready queue. Firing a run event removes a process from the ready queue.

4. When a ready event is fired, if the number of available processors is 0, then the associated process is added to the ready queue maintained by the scheduling simulator. Otherwise a running event is scheduled for the current time.

5. When a run event is fired, a new ready event is scheduled for

time + process.burst[next++]

Of course if the process has terminated, no event is created.

6. A switch determines if the scheduling simulator uses the First-Come, First-Served (FCFS) or the Shortest Job First (SJF) algorithm.

7. Either during or at the end of the simulation the user should be able to see:

1. The average wait time
2. The throughput time for each process

8. The user interface is a console. You can customize the Console and AppError classes in

http://www.cs.sjsu.edu/faculty/pearce/jutil/

Extra Credit

For up to 25% extra credit create a GUI for the simulator. You may use the AppWindow and AppModel classes in

http://www.cs.sjsu.edu/faculty/pearce/j2se/util/