我正在为我的应用程序使用Flask REST API,我注意到当我从自己的网络外部发送请求时,有时会非常非常慢。大多数通话在150毫秒内完成,但有些通话需要8秒钟。数据库连接是使用DBUtils.PersistentDB
到MySQL数据库的端点的代码:
@app.route("/name", methods=["POST"])
@jwt_refresh_token_required
def get_name_and_company():
user = get_jwt_identity()
response_object = server_functions.get_name_and_company(user)
return response_object
它使用的功能:
def get_name_and_company(user):
sql = "SELECT fysios.firstname, fysios.lastname, companies.name FROM
fysios " +\
"INNER JOIN companies ON fysios.companyID = companies.id WHERE fysios.email = %s"
cursor = flask_server.get_db().cursor()
cursor.execute(sql, user)
data = cursor.fetchall()
first_name = data[0]['firstname']
last_name = data[0]['lastname']
company = data[0]['name']
response_object = name_and_company(first_name, last_name, company)
return make_response(jsonify(response_object)), 200
以下是Flask服务器上的时间戳(它是内部开发服务器,但我正在使用threaded = True运行它):
[08/Mar/2019 22:16:54] "OPTIONS /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "POST /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "OPTIONS /name HTTP/1.1" 200 -
[08/Mar/2019 22:16:58] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:17:05] "POST /name HTTP/1.1" 200 -
如您所见,/ name总共需要8秒钟,我不知道为什么。对/ name的此调用仅是示例,它可以在任何调用中发生。有没有办法找出Flask应用程序实际卡在哪里?
答案 0 :(得分:0)
部署到AWS Beanstalk解决了该问题。我不知道是否应该责怪内置dev服务器的局限性,但这就是我的目的。