You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I built a flask application and use gevent monkey_patch() to support high concurrency, and use nginx upstream for reverse proxy. everything is ok but occurred lots of 499 http status code responses yesterday.
The 499 status code is returned by nginx because of connection closed by client with setting timeout=5, but all request's response time lte 1s in flask app request log, and CPU usage not full, only reach 60%, same as usual.
So I wrote a demo to test that scene as below:
importclickimportjsonfromgeventimportmonkeymonkey.patch_all()
fromtimeimportsleepfromflaskimportFlask, jsonify, requestfromgevent.pywsgiimportWSGIServerdefcreate_app():
flask_app=Flask(__name__)
@flask_app.route('/test/<q_id>', methods=['GET'])deftest(q_id):
# for timeout easilysleep(0.1)
# for high cpu usageforiinrange(1000):
json.dumps(request.cookies.to_dict())
returnjsonify(result='ok'), 200returnflask_app@click.command()@click.option('--port', help='port')defmain(port):
port=int(port)
app=create_app()
http_server=WSGIServer(('0.0.0.0', port), app)
http_server.serve_forever()
if__name__=='__main__':
main()
I run this app and send lost of concurrency requests with timeout=0.3 on another server. several minutes later, much 499 status code appeared in nginx log like below screenshot:
And this is flask app log, request with id=x-333:
And CPU usage is 60%, so why the response time in nginx is gte 0.3s, but only 0.146s in gevent + flask app?
The text was updated successfully, but these errors were encountered:
gevent==20.9.0
(pypi).Description:
I built a flask application and use gevent monkey_patch() to support high concurrency, and use nginx upstream for reverse proxy. everything is ok but occurred lots of
499
http status code responses yesterday.The
499
status code is returned by nginx because of connection closed by client with settingtimeout=5
, but all request's response time lte 1s in flask app request log, and CPU usage not full, only reach 60%, same as usual.So I wrote a demo to test that scene as below:
I run this app and send lost of concurrency requests with
timeout=0.3
on another server. several minutes later, much499
status code appeared in nginx log like below screenshot:And this is flask app log, request with
id=x-333
:And CPU usage is 60%, so why the response time in nginx is gte 0.3s, but only 0.146s in gevent + flask app?
The text was updated successfully, but these errors were encountered: