i am trying to simulatie multiple user requests in parallel on a flask server to measure its responsetimes. i thought multiprocessing would be the right module for it. Here is my code:
import multiprocessing as mp
import requests
import datetime
from multiprocessing.pool import Pool
HOST = 'http://127.0.0.1:5000'
API_PATH = '/'
ENDPOINT = [HOST + API_PATH]
MAX_Processes = 10
def send_api_request(ENDPOINT):
r = requests.get(ENDPOINT)
print(mp.current_process())
statuscode = r.status_code
elapsedtime = r.elapsed
return statuscode, elapsedtime
def main():
with Pool() as pool:
try:
#define poolsize
pool = mp.Pool(mp.cpu_count())
print(pool)
results= pool.map(send_api_request, ENDPOINT)
print(results)
except KeyboardInterrupt:
pool.terminate()
if __name__ == '__main__':
main()
when i run this code in cli i only get one result printed and i dont know if the 8 processes are being processed. here is the output:
<multiprocessing.pool.Pool state=RUN pool_size=8>
<SpawnProcess name='SpawnPoolWorker-10' parent=19536 started daemon>
200 0:00:00.013491
the target is to run 100 or more requests in parallel on the flask server to get the responsetime of every single requests and put them in an csv sheet.
anyone knows how i can get every result from the processes?
Thank you!