forked from alexwafula/Customizable_Load_Balancerr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment_a1.py
27 lines (23 loc) · 946 Bytes
/
experiment_a1.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
import asyncio
import requests
import matplotlib.pyplot as plt
async def make_requests():
responses = []
for _ in range(10000):
response = requests.get('http://127.0.0.1:5000/rep')
responses.append(response.json()['message']['replicas']) # Access 'replicas' key
return responses
async def main():
response = await make_requests()
server_counts = {'Server 1': 0, 'Server 2': 0, 'Server 3': 0}
for servers in response: # Iterate over each list of servers
for server in servers: # Iterate over each server in the list
server_counts[server] += 1
plt.bar(server_counts.keys(), server_counts.values())
plt.xlabel('Server Instance')
plt.ylabel('Request Count')
plt.title('Request Distribution Among Server Instances (N=3)')
plt.savefig('experiment_A1_results.png') # Save the plot as an image file
plt.show()
if __name__ == '_main_':
asyncio.run(main())