mirror of https://github.com/ivanch/tcc.git
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
|
import requests
|
||
|
import concurrent.futures
|
||
|
import time
|
||
|
|
||
|
URL_BASE = 'http://localhost:5100'
|
||
|
|
||
|
num_requests = [1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000]
|
||
|
|
||
|
def send_request(session, url):
|
||
|
response = session.get(url)
|
||
|
return response.status_code
|
||
|
|
||
|
def main():
|
||
|
for num_request in num_requests:
|
||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
||
|
url = f'{URL_BASE}/status/ok'
|
||
|
|
||
|
start_time = time.time()
|
||
|
|
||
|
futures = []
|
||
|
with requests.Session() as session:
|
||
|
futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
||
|
|
||
|
concurrent.futures.wait(futures)
|
||
|
|
||
|
elapsed_time = time.time() - start_time
|
||
|
|
||
|
successful_responses = sum(1 for future in futures if future.result() == 200)
|
||
|
|
||
|
print(f"All requests completed in {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second.")
|
||
|
print(f"Successful responses: {successful_responses}/{num_request}")
|
||
|
|
||
|
main()
|