예제 #1
0
 def test_is_busy_after_proc_finish(self):
     p = Processor('test', 10)
     work_time = p.add_process(12313)
     for w in range(work_time - 1):
         p.process()
         #  self.assertEqual(p.is_busy(), True)
     self.assertEqual(p.is_busy(), False)
예제 #2
0
    def test_queue_empting(self):
        p = Processor('test', 10, Buffer(1))
        work_time = p.add_process(14)
        p.add_process(789)
        self.assertEqual(1, p.get_queue_len())
        # the queue length should stay 1 after additinal push
        p.add_process(444)
        self.assertEqual(1, p.get_queue_len())

        # this is one more `work` than needed to finish process
        for i in range(work_time):
            p.process()

        # the process should take the next element from the buffer
        self.assertEqual(p.get_queue_len(), 0)
        # the process should take the next element from buffer
        # and continue working
        self.assertNotEqual(p.process(), 0)
예제 #3
0
 def test_buffer_limit(self):
     ''' Adds more processes than process can handle till buffer overflow '''
     b = Buffer(2)
     p = Processor('rtt', 40, b)
     p.add_process(123)
     p.add_process(1231231)
     p.add_process(87)
     self.assertEqual(0, p.add_process(666))
예제 #4
0
    def test_processing_flow(self):
        # create a process
        p = Processor('tt', 40)
        till_free = p.add_process(123)
        current_state = till_free

        # check if process reduces till free timer with each call
        # to process method
        for i in range(till_free):
            self.assertEqual(p.process(), current_state - 1)
            current_state -= 1

        # check that in the end of process till free is set to 0
        self.assertEqual(0, p.process())
예제 #5
0
# In[5]:

requests = get_requests_timings(LAMBDA)
print(requests[:10])
rejected_requests = []

for i in range(TIME_LIMIT):
    if i % 5000 == 0:
        print(i, end=' => ')
    if i in requests:
        # define in which arm request should be processed
        arm_check = random.random()
        # check if the arm can process request (either processor or buffer)
        attachment_result = 0
        if arm_check < 0.33:
            attachment_result = p1.add_process(i)
        else:
            attachment_result = p2.add_process(i)
        
        if attachment_result == 0:
            # the processor was not able to take request
            rejected_requests.append(i)

    p1.process()
    p2.process()


# In[6]:

intervals = count_intervals(rejected_requests)
print("Workload of System1: ", 1/(sum(intervals)/len(intervals)))