-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (59 loc) · 2.29 KB
/
main.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This script is the main entry of the project
from load_balancer import LoadBalancer
import sys
if __name__ == "__main__":
if len(sys.argv) < 2:
print('Run format: python3 main.py <number of requests>')
else:
req_num = int(sys.argv[1])
if req_num >= 2499:
count = req_num // 2499
while req_num:
_req_num = 2499
if req_num < 2499:
_req_num = req_num
else:
req_num -= _req_num
# Create a config object for load balancer
policy = None
if 0 <= _req_num < 100:
policy = 'round robin'
elif 100 <= _req_num < 500:
policy = 'randomized static'
elif 500 <= _req_num < 1250:
policy = 'least connection'
elif 1250 <= _req_num < 2500:
policy = 'weighted least connection'
cfg = {
'host': 'http://host.docker.internal',
'main_endpoint': 'work',
'port': 5000,
'policy': policy,
'hosts_configuration': { 'emea': 1, 'us': 2, 'asia': 2},
'req_num': _req_num
}
load_balancer = LoadBalancer(cfg)
load_balancer.run()
print('Finished requests')
else:
# Create a config object for load balancer
policy = None
if 0 <= req_num < 100:
policy = 'round robin'
elif 100 <= req_num < 500:
policy = 'randomized static'
elif 500 <= req_num < 1250:
policy = 'least connection'
elif 1250 <= req_num < 2500:
policy = 'weighted least connection'
cfg = {
'host': 'http://host.docker.internal',
'main_endpoint': 'work',
'port': 5000,
'policy': policy,
'hosts_configuration': { 'emea': 1, 'us': 2, 'asia': 2},
'req_num': req_num
}
load_balancer = LoadBalancer(cfg)
load_balancer.run()
print('Finished requests')