-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalbqueue_test.py
More file actions
50 lines (31 loc) · 1 KB
/
albqueue_test.py
File metadata and controls
50 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
from collections import deque
import time
import threading
from client import Client
from client import Request
# ## Final ALBQueue
class ALBQueue(deque):
def __init__(self):
super()
def queue_length(self):
"""Current len of queue"""
return len(self)
def time_exp(self):
"""Time Taken to service Requests proportional to this"""
return sum([item.size for item in self])
def post_count(self):
"""Count of POST method Requests in Queue"""
return sum([item._method == 'POST' for item in self])
def get_count(self):
"""Count of GET method Requests in Queue"""
return sum([item._method == 'GET' for item in self])
x = ALBQueue()
c = Client(x)
c.fire('random', rtype = 'RAND', rps = 3)
time.sleep(10)
c.fire('uniform', rtype = 'RAND', rps = 10)
c.fire('single', rtype = 'POST')
c.fire('stop')
print(x.queue_length())
print(x.time_exp())