I want to test how much http request an easy ping-pong service can handle in a certain amount of time. I have already implemented it in Java and Go and it works fine. But when testing it with python one single ping-pong cycle needs a bit more than 2s on my machine and that's enormously long. In the other languages I have nearly 1 per each milliseconds. More than 2000 times what I get with python... how can that be? I think the http server needs to be build up each time again with python, but is it really that and how could I fix it?
And of course the code to my little python scripts is down below:
import requests add = 'aaaaaaaaaa' sum = '' def getTime(i): site_request = requests.post("http://localhost:8082/ping", data=i) site_response = str(site_request.content) return site_response def printToFile(): return for x in range(5): print(getTime(sum)) sum += add from flask import Flask from flask import request import requests import time app = Flask(__name__) @app.route("/ping", methods=['POST']) def region(): data = request.get_data() start = time.time() site_request = requests.post("http://localhost:8080/pong", data=data) site_response = str(site_request.content) end = time.time() cl = int(site_request.headers['content-length']) if cl != len(data): return end - start + ", " + cl + "," + 500 return str(end - start) + "," + str(cl) + "," + str(200) app.run(host='127.0.0.1', port= 8082) from flask import Flask from flask import request app = Flask(__name__) @app.route("/pong", methods=['POST']) def region(): data = request.get_data() return data app.run(host='127.0.0.1', port= 8080)