Find the number of jobs running

We must simulate the starting and stopping of a job. Lets assume that:

  1. The stage-in time for a job is 2 minutes.
  2. The stage-out time for a job is instant.
  3. The processing time for a job is 5 hours (300 minutes)
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
runningjobs = [] # the array of running jobs
numrunning = []
timestamp = 0
In [3]:
stagein = 2
processingtime = 300
stageout = 0
In [4]:
nextstart = timestamp + stagein
In [5]:
for i in range(0, 1000):
    if timestamp == nextstart:
        runningjobs.append(timestamp+300)
        nextstart = timestamp + stagein
        
    if len(runningjobs) > 0 and runningjobs[0] <= timestamp:
        runningjobs.pop(0)
        
    numrunning.append(len(runningjobs))
    timestamp += 1
In [6]:
plt.plot(numrunning)
plt.ylabel("Running Jobs")
plt.xlabel("Time (m)")
Out[6]:
<matplotlib.text.Text at 0x108420090>

As you can see from the plot above, the number of running jobs never reaches above 150.