I have a simple test application for Windows - Tornado, which runs the Flask wsgi application. I can start the server just fine and connect through my web browser, and it's just awesome.
I can run my performance test, and on my machine I get ~ 900-1000 requests per second. However, after 20,000 requests, my server stops responding, and my test reports - 0 per second. I can try to connect through a web browser, but nothing. Usually ctrl + c also has some problems (you need to hit it several times before refreshing the page in the browser, as usual, the server will be terminated).
So why does my server choke and die when I clog it like that?
Well, therefore, trying to exclude various factors, I was able to hit the server from another machine, although my local machine was shut down, so it looks like my local machine is really running out of ports or something?
Anyway, here is my code:
server.py
from flask import Flask app = Flask(__name__) @app.route("/") def main(): return "Hey, it working" if __name__ == "__main__": app.run("0.0.0.0", port=5000, debug=True)
tornado_server.py
from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from server import app http_server = HTTPServer(WSGIContainer(app)) http_server.listen(5000) IOLoop.instance().start()
perftest.py
from socket import * import time n = 0 stop = False from threading import Thread def monitor(): global n, stop while not stop: time.sleep(1) print(n, 'reqs/sec') n = 0 if __name__ == "__main__": t = Thread(target=monitor).start() while True: try: sock = socket(AF_INET, SOCK_STREAM) sock.connect(('localhost', 5000)) sock.send(b'''GET / HTTP/1.1\n\n''') resp = sock.recv(4096) sock.close() n += 1 except KeyboardInterrupt: stop = True except: pass