def generateWorkload(self): W = [] logging.basicConfig(filename='example.log', level=logging.DEBUG) creation_Time = 0 i = 0 TotalCPUTime = np.random.normal(self.mean_job_time, self.sd_job_time) TotalCPUTime = round(TotalCPUTime * self.time_unit) logging.info('Task' + str(i) + ":Creation Time:" + str(creation_Time) + ":Total CPU time:" + str(TotalCPUTime)) IO = IOGenerator(self.rate_io, TotalCPUTime, self.mean_io_time, self.sd_io_time, self.time_unit) iolist = IOList(IO.generateIOEvent()) T = Task("Task 0", 0, np.abs(creation_Time), np.abs(TotalCPUTime), iolist) W.append(T) for i in xrange(self.num_jobs): creation_Time = round( random.expovariate(self.rate_jobs) * self.time_unit) + W[-1].creationTime TotalCPUTime = np.random.normal(self.mean_job_time, self.sd_job_time) TotalCPUTime = round(TotalCPUTime * self.time_unit) logging.info('Task' + str(i) + ":Creation Time:" + str(creation_Time) + ":Total CPU time:" + str(TotalCPUTime)) IO = IOGenerator(self.rate_io, TotalCPUTime, self.mean_io_time, self.sd_io_time, self.time_unit) iolist = IOList(IO.generateIOEvent()) T = Task("Task " + str(i), 0, np.abs(creation_Time), np.abs(TotalCPUTime), iolist) W.append(T) self.work_load_list = W w = Workload(W) return w
def dummyIOList(): io1 = IO(4, 10) io2 = IO(2, 10) io3 = IO(8, 30) io4 = IO(5, 40) io5 = IO(7, 19) return [io1, io2, io3, io4, io5]
def dummyGen(): ioList1 = IOList([IO(10, 5), IO(13, 7)]) ioList2 = IOList([]) # high priority IO instensive task t1 = Task("Task 1", 0, 3, 20, ioList1) # low priority CPU intensive task t2 = Task("Task 2", 10, 0, 15, ioList2) w = Workload([t1, t2]) return w
def testaddEvent(self): T = dummyTasks() q = EventQueue(T.getInitialEvents()) io = IO(10, 5) io_start = IOStartEvent(5, io, 5) q.addEvent(io_start) self.assertEqual(q.getSize(), 3) q.extractMin() self.assertEqual(q.getMin().getPriority(), 5)
def test_objFunction(self): ioList1 = IOList([IO(10, 5), IO(13, 7)]) ioList2 = IOList([IO(1, 3), IO(2, 6), IO(5, 8), IO(6, 8)]) t1 = Task("Task 1", 0, 3, 20, ioList1) t2 = Task("Task 1", 0, 5, 40, ioList2) t1.setUsedCpuTime(14) t1.setTimesBlocked(2) t1.setTotalReadyWait(4) t1.setTimesScheduled(2) t2.setUsedCpuTime(7) t2.setTimesBlocked(4) t2.setTotalReadyWait(4) t2.setTimesScheduled(2) tasks = [t1, t2] self.assertTrue(isclose(11.1428, Metric.objFunction(tasks, 10)))
def generateIOEvent(self): list_io = [] IOOffset = round(random.expovariate(self.rate) * self.time_unit) logging.basicConfig(filename='example.log', level=logging.DEBUG) i = 0 while (IOOffset <= self.total_time): IOcompletiontime = np.abs( round( np.random.normal(self.mean_io_time, self.sd_io_time) * self.time_unit)) iotask = IO(IOOffset, IOcompletiontime) logging.info('IO task'+str(i)+":Offset Time:"+ \ str(IOOffset)+":Completion Time:"+str(IOcompletiontime)) list_io.append(iotask) i = i + 1 IOOffset = IOOffset + np.abs( np.ceil(random.expovariate(self.rate) * self.time_unit)) return list_io
def testInteralState(self): io1 = IO(6, 2) io2 = IO(8, 3) ioList = IOList([io1, io2]) name = 'Task 1' priority = 1 creationTime = 0 totalCpuTime = 10 task = Task(name=name, priority=priority, creationTime=creationTime, totalCpuTime=totalCpuTime, ioList=ioList) ####################### # Test constructor ####################### self.assertEqual(task.getName(), name) self.assertEqual(task.getPriority(), priority) self.assertEqual(task.getCreationTime(), creationTime) self.assertEqual(task.getTotalCpuTime(), totalCpuTime) self.assertEqual(task.getIOList(), ioList) ########################## # Check Deafult Values ########################## self.assertEqual(task.getUsedCpuTime(), 0) self.assertEqual(task.getNice(), 0) self.assertEqual(task.getRecentCpu(), 0) self.assertEqual(task.getTimesBlocked(), 0) self.assertEqual(task.getAvgBlocking(), 0) self.assertEqual(task.getAvgReadyWait(), 0) self.assertTrue(task.stillHasIO()) self.assertEqual(task.getNextIO(), io1) self.assertEqual(task.popNextIO(), io1) self.assertTrue(task.stillHasIO()) self.assertEqual(task.getNextIO(), io2) self.assertEqual(task.popNextIO(), io2) self.assertFalse(task.stillHasIO()) self.assertEqual(task.popNextIO(), None) self.assertFalse(task.isInIO()) self.assertFalse(task.isIdleTask()) task.reset() ####################################### # After reset should revisit all IOs ####################################### self.assertTrue(task.stillHasIO()) self.assertEqual(task.getNextIO(), io1) self.assertEqual(task.popNextIO(), io1) self.assertTrue(task.stillHasIO()) self.assertEqual(task.getNextIO(), io2) self.assertEqual(task.popNextIO(), io2) self.assertFalse(task.stillHasIO()) self.assertEqual(task.popNextIO(), None) amount = 13 usedCpuTime = task.getUsedCpuTime() for i in xrange(5): task.incUsedCpuTime(amount) usedCpuTime += amount self.assertEqual(task.getUsedCpuTime(), usedCpuTime) ###################### # usedCpu increment ###################### usedCpuTime = 0 task.setUsedCpuTime(usedCpuTime) self.assertEqual(task.getUsedCpuTime(), usedCpuTime) task.incUsedCpuTime(1) usedCpuTime += 1 self.assertEqual(task.getUsedCpuTime(), usedCpuTime) task.incUsedCpuTime(1) usedCpuTime += 1 self.assertEqual(task.getUsedCpuTime(), usedCpuTime) ###################### # recentCpu increment ###################### recentCpu = 0 task.setRecentCpu(recentCpu) self.assertEqual(task.getRecentCpu(), recentCpu) task.incRecentCpu() recentCpu += 1 self.assertEqual(task.getRecentCpu(), recentCpu) task.incRecentCpu() recentCpu += 1 self.assertEqual(task.getRecentCpu(), recentCpu) ########################### # timesScheduled increment ########################### timesScheduled = 0 task.setTimesScheduled(timesScheduled) self.assertEqual(task.getTimesScheduled(), timesScheduled) task.incTimesScheduled() timesScheduled += 1 self.assertEqual(task.getTimesScheduled(), timesScheduled) task.incTimesScheduled() timesScheduled += 1 self.assertEqual(task.getTimesScheduled(), timesScheduled) priority = 10 task.setPriority(priority) self.assertEqual(task.getPriority(), priority) recentCpu = 15 task.setRecentCpu(recentCpu) self.assertEqual(task.getRecentCpu(), recentCpu) nice = -8 task.setNice(nice) self.assertEqual(task.getNice(), nice) usedCpuTime = 7 task.setUsedCpuTime(usedCpuTime) self.assertEqual(task.getUsedCpuTime(), usedCpuTime) self.assertEqual(task.getRemainingCpuTime(), task.getTotalCpuTime() - usedCpuTime) timesBlocked = 3 task.setTimesBlocked(timesBlocked) self.assertEqual(task.getTimesBlocked(), timesBlocked) totalReadyWait = 32 task.setTotalReadyWait(totalReadyWait) self.assertEqual(task.getTotalReadyWait(), totalReadyWait) timesScheduled = 4 task.setTimesScheduled(timesScheduled) self.assertEqual(task.getTimesScheduled(), timesScheduled) self.assertEqual(task.getAvgBlocking(), float(timesBlocked) / usedCpuTime) self.assertTrue( abs(task.getAvgReadyWait() - float(totalReadyWait) / timesScheduled) < 1e-3) amount = 5 task.incTotalReadyWait(amount) totalReadyWait += amount self.assertEqual(task.getTotalReadyWait(), totalReadyWait) self.assertTrue( abs(task.getAvgReadyWait() - float(totalReadyWait) / timesScheduled) < 1e-3)
def dummyTask(): ioList = IOList([IO(10, 5), IO(13, 7)]) t = Task("Task 2", 10, 5, 15, ioList) return t
def dummyIO( ): io = IO(4,10) return io