Search code examples
timeprocessor

how to calculate the processing time?


Processing times for 5 processes were given. how will I find out the minimum average waiting time the processes have to wait in order to get executed if TWO PROCESSORS are given.


Solution

  • On any given processor, the total waiting time for an ordered set of processes taking time P1..PN to complete is the total of individual elapsed times multiplied by the number of waiting processes remaining:

        (N - 1)P1 + (N - 2)P2 + ... + PN-1.

    This reveals that waiting time is hit by a multiple of the cost of earlier processes, with the consequence that we need to get shorter-running jobs over with as early as possible and minimise queue length. Say we sort the process durations and call them A, B, C, D, and E (the longest-running job). If we contrast the following prioritorisation:

    Processor 1: A, B, C, D
    Processor 2: E
    Total waiting time: 3A + 2B + C
    

    ...with...

    Processor 1: A, B, D
    Processor 2: C, E
    Total waiting time: 2A + B + C
    

    We can clearly see the second configuration saves (A + B) total waiting time, and the benefit of distributing the jobs in a 3:2 split. Equally, the 2A + B + C formula can only be worse if we swapped D or E for any of A, B or C, as we know A <= B <= C <= D <= E.

    There are only two alternative 3:2 permutations given D and E don't partake in the waiting time calculation (they will be denoted with X hereafter).

    Processor 1: A, C, X
    Processor 2: B, X
    Total waiting time: 2A + C + B  [no change]
    
    Processor 1: A, X
    Processor 2: B, C, X
    Total waiting time: A + 2B + C  [maybe worse as B>=A]
    

    Thus, the optimal and equally satisfactory orderings are: ABX/CX and ACX/BX.