-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_request.py
39 lines (30 loc) · 1.23 KB
/
api_request.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
import requests
import json
from concurrent.futures import ThreadPoolExecutor
def send_test_message():
print("in send_test_msg")
url = 'http://0.0.0.0:5000/send_message'
headers = {'Content-Type': 'application/json'}
payload = json.dumps({"user_input": "this is the best food"})
response = requests.post(url, headers=headers, data=payload)
if response.status_code == 200:
print(f"Server response: {response.json()}")
else:
print(f"Failed to send message, status code: {response.status_code}")
def stress_test_serial():
url = 'http://0.0.0.0:5000/send_message'
headers = {'Content-Type': 'application/json'}
payload = json.dumps({"user_input": "this is the best food"})
for i in range(1000):
response = requests.post(url, headers=headers, data=payload)
if response.status_code == 200:
print(f"Server response: {response.json()}")
else:
print(f"Failed to send message, status code: {response.status_code}")
def stress_test_parallel():
with ThreadPoolExecutor() as executor:
executor.map(send_test_message, range(100))
if __name__ == '__main__':
#send_test_message()
stress_test_serial()
#stress_test_parallel()