Program #2 CS 402

University of Bridgeport

General Instructions: Write a program which will use (1) a FIFO queue and (2) a Max Heap to create a priority queue and simulate a multi-priority job scheduling system. There will be four job priorities: system, administrative, normal, and batch. Computer jobs are submitted at an average rate (probability). For example the probability vector could be [0.02, 0.035, 0.11, 0.08], for example. In this example, each simulated second there is a probability of 2% that a system job arrives, 11% that a normal job arrives, etc. Each submitted job will take a certain amount of time, according to a user-entered distribution. You should use the exponential distribution for the tme the job will require in the CPU. For example, for an exponential distribution with parameter lambda = 0.3 the mean time would be 3 1/3 seconds – the mean on the exponential distribution is one over the lambda parameter. As a job arrives it is placed in the priority queue and its time required at the CPU is computed using the exponential distribution. Each job class should have a different lambda value for its exponential distribution. For example the lambda vector might look like this: [1.0, 0.2, 0.25, 0.1]. From the vector we see that an average system job requires 1 second of CPU time, while an administrative job requires 5 seconds. The object of the program is to calculate statistics for the average queue waiting time for all four types of jobs. We will run our simulation for 24 hours. Remember that the time spent in the CPU is not waiting time. In addition to computing waiting time, we would like to know the time that the program runs using implementation (1) versus implementation (2). The efficiency of the two priority queues implementations will make a difference there. You should keep comparative times for the same probability and lambda vectors and present your findings in a two-page summary.

Specific Instructions: The CPU will start with no jobs, and the priority queue empty. In fact, the toll station itself is an ADT with ten queues and the toll station statistics - arrival rate, duration of service. The program will have a global "clock" which will be initialized to zero and increment by one for each simulated second. For each second, there will be a probability (from the probability vector - of an arrival of each type of job. That is, there is a probability, say 0.20, (between 0 and 1.0) of a car arriving at any one second. So for each clock "tic", a random number will be generated. A value < 0.20 can be interpreted as an arrival, none otherwise. In short, you can have anywhere between zero to four arrivals of jobs at any second, although multi-arrivals will not be very common. Given an arrival has occurred, we need to compute its service duration. For example if a normal job arrives, then we would use its lambda value (from the lambda vector) to compute a random value form its exponential distribution. The program then involves the following:

Initialize the clock, the priority queue, and priority queue statistics

Repeat

Advance the clock

Continue to service the current job in the CPU

Check for new arrival: if arrival then set all parameters and enqueue

Until 24 "hours" pass

 

In order to have a feel for your system, it would be helpful to display a snapshot state of the priority queue.

CPU – 3 sec

#1 2sec, 4sec, 3sec

#2 1 sec, 4 sec

#3 3 sec, 2 sec, 1 sec

#4 empty

We see above that there is a job in the CPU with 3 seconds remaining, and there are three jobs in the system level, two in the administrative level, etc. If you find that the #1 queue is never empty, then other jobs, at lower levels, may not get a chance at the CPU time. Thus the waiting time for all other levels may be too high. Therefore it is up to you to adjust the probability and lambda vectors so that you get reasonable results. Once you have set reasonable values for your vectors, your program run should display the priority queue state, say every 15 minutes (of simulated time). This will give you (and me) a view of the dynamics of your system. For one set of vector parameters, run 3 or 4 times with implementation (1) and 3 or 4 times with implementation (2). Then compare how long it took to run the program on average. Then change you parameters in your vectors and repeat the comparison.