• flask-profiler的使用


    使用 profiler测量在你的Flask 应用程序中定义的端点;并通过web界面提供细粒度的报告。

    它给出了这些问题的答案:

    • 应用程序中的瓶颈在哪里?
    • 应用程序中最慢的终结点?
    • 哪些是最常被调用的终结点?
    • 什么导致我的慢速端点? 在哪个上下文中,什么是 ARGS 和 kwargs?
    • 特定请求花费了多少时间?

    简而言之,如果你对端点正在做什么和接收的请求进行了了解,请尝试打瓶探查器。

    通过使用烧瓶分析器接口,你可以监视所有端点的性能,并通过向下钻取过滤器来调查端点和接收的请求。

    1.安装 flask_profiler

    pip install flask_profiler

    2.在创建 Flask 应用程序时编辑你的代码。

    from flask import Flask
    import flask_profiler
    
    app = Flask(__name__)
    app.config["DEBUG"] = True
    # 您需要声明必要的配置才能初始化
    app.config["flask_profiler"] = {
        "enabled": app.config["DEBUG"],
        "storage": {
            "engine": "sqlite"},
        "basicAuth": {
            "enabled": True,
            "username": "admin",
            "password": "admin"},
        "ignore": [
            "^/static/.*"]
    }
    # 为了激活flask-profiler,您必须通过flask
    # app作为flask-profiler的参数。
    # 到目前为止,flask-profiler将跟踪所有已声明的端点。
    flask_profiler.init_app(app)
    
    
    @app.route('/helloworld')
    @flask_profiler.profile()  #  来明确指定此端点()
    def hello_world():
        return 'Hello World!'
    
    @app.route('/welcome', methods=['GET'])
    @flask_profiler.profile()
    def doSomethingImportant():
        return "welcome"
    
    
    
    if __name__ == '__main__':
        app.run(host="0.0.0.0", port=5000)
    访问url 确保接口可以成功调用
    # http://127.0.0.1:5000/helloworld
    # http://127.0.0.1:5000/welcome
    # 如果一切可以,Flask-profiler会衡量这些请求。你可以看到结果前往http://127.0.0.1:5000/flask-profiler/
    ##使用与不同的数据库系统当前支持** Sqlite **和** Mongodb **数据库系统。但是,很容易支持其他数据库系统。如果您想要其他人,请转到贡献文档。(这确实很容易。)

  • 相关阅读:
    MySql 5.6以下版本自定义函数返回VARCHAR的中文问题
    解决Tomcat的java.lang.IllegalStateException: Cannot create a session after the response has been committed问题
    Lucene自定义规则范围查询
    JS吊炸天的代码
    又是正则
    JS显示指定字符数,避免一个中文两个字符的情况
    PostgreSql查看当前表的主外键关系
    java基础(个人学习笔记) A
    Elasticsearch5.5.1插件开发指南
    ElasticSearch5.5.1插件分类
  • 原文地址:https://www.cnblogs.com/zlel/p/11676571.html
Copyright © 2020-2023  润新知