下面是我的代码的基本结构。目前,我的响应时间在 30-40 秒之间,这太可怕了。有没有办法让我大大改善响应时间。
from flask import Flask
from flask_restful import Resource, Api
(some more ML libraries)
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def __init__(self):
pass
def get(self):
Calling an external api to fetch data
Created Machine learning model for predictions
performed exploratory data analysis on the data retrieved through API
return {all the necessary parameters in json}
api.add_resource(HelloWorld,'/')
if __name__ == "__main__":
app.jinja_env.cache = {}
app.run(debug=True)
你可以从 Flask 调试工具栏尝试探查器:
https://flask-debugtoolbar.readthedocs.io/en/latest/
探查器显示每个进程需要多长时间:
https://flask-debugtoolbar.readthedocs.io/en/latest/panels.html#profiler