Metadata-Version: 2.1
Name: fastml-engine
Version: 1.0.2
Summary: A web server for deploy ml/dl model
Home-page: UNKNOWN
Author: HaiTao Hou
Author-email: hou610433155@163.com
License: MIT
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/x-rst
License-File: LICENSE.txt
Requires-Dist: Flask
Requires-Dist: flasgger
Requires-Dist: numpy
Requires-Dist: six
Requires-Dist: gevent
Requires-Dist: Werkzeug
Requires-Dist: concurrent-log-handler (==0.9.16)
Requires-Dist: portalocker (==1.7.0)
Requires-Dist: click (>=7.0gunicorn) ; platform_system != "Windows"
Requires-Dist: waitress ; platform_system == "Windows"

Algorithm Model Service Engine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

介绍
^^^^

fastml-engine. 采用\ `Gunicorn <https://docs.gunicorn.org/>`__
Web服务框架搭建,以简化模型推理工程部署的工作内容

功能特性
^^^^^^^^

1. 集成Gunicorn Flask 服务组件,稳定可靠,可用于生产.
2. 统一推理服务接口,支持多种接口请求格式(text/json/octet-stream/form-data)
3. 搭配inference-template使用,支持自定义模型推理代码
4. 支持简便的启动命令

install
^^^^^^^

1. pip
    https://gitee.com/easy-ams/ams-processor-template.git
    ``pip install fastml-engine``

使用说明
^^^^^^^^

1. ams-processor-template\ `使用说明 <https://gitee.com/easy-ams/ams-processor-template/blob/master/README.md>`__
2. 启动服务

   ams\_engine安装完成,在python的bin目录下会产生ams-start.sh和ams-stop.sh两个脚本,linux环境下可直接使用.
    ``sh ams-start.sh <absolute path> <port> <workers> <timeout>``
    ``sh ams-start.sh /home/work_path/ams-processor-template 9000 2 60``
    port:端口号(可选,默认8088
    workers:进程wokers数(可选,默认1)
    timeout:请求响应超时,单位s(可选,默认60s)
3. 验证服务
    a)通过浏览器访问健康检查接口 ip:port/health
    b)查看启动日志,日志目录在代码根路径/logs目录下
4. 停止服务
    执行脚本指定进程占用端口
    ``sh ams-stop.sh 9000``

接口描述
^^^^^^^^

+----------------+--------------+------------+------------------------+
| 接口说明       | URI          | 请求协议   | 返回内容               |
+================+==============+============+========================+
| 健康检查       | /health      | GET        | ｛ status:UP｝         |
+----------------+--------------+------------+------------------------+
| 查询推理接口   | /endpoints   | GET        | 接口名称json报文       |
+----------------+--------------+------------+------------------------+
| 推理接口       | /algo/       | POST       | 返回推理预测结果报文   |
+----------------+--------------+------------+------------------------+

    健康检查接口响应报文

.. code:: json

    {
      "status": "UP"
    }

    endpoints接口响应报文

.. code:: json

    [
      {
        "processor_class_name": "Inference", 
        "processor_script_name": "customized_processor"
      }
    ]

    推理接口响应报文

.. code:: json

    {
         "result": true,  
         "data": {  
             "k": "v"  
         },  
         "metadata": {  
             "duration": 1.65576171875,  
             "content_type": "json"  
         }
     }

测试
^^^^

| 使用POSTMAN调用推理接口
| 注意：请求头需要添加Content-Type参数,用来指定请求报文格式

+----------------------------+-----------------+
| Content-Type               | 说明            |
+============================+=================+
| text/plain                 | 文本格式        |
+----------------------------+-----------------+
| application/json           | json格式        |
+----------------------------+-----------------+
| application/octet-stream   | 文件            |
+----------------------------+-----------------+
| multipart/form-data        | form-data格式   |
+----------------------------+-----------------+

请求发起后报文将作为入参传入推理算法主函数 > windows本地运行服务

ams\_engine包提供app.py脚本,可本地代码导入使用,启动flask

.. code:: python

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import os
    # 设置环境变量
    os.environ['PROCESSOR_PATH'] = 'D:/code/processor-customized/'
    os.environ['default_model_path'] = 'D:/code/processor-customized/model'
    import ams_engine.app as ams

    if __name__ == '__main__':
        # 启动运行,使用ams_engine的app模块直接启动flask程序
        ams.app.run('0.0.0.0', 8088, debug=False, threaded=True)

日志说明
^^^^^^^^

运行日志存放在推理引擎根目录logs文件夹下

1. access.log为请求调用日志
2. error-access.log为错误日志
3. app.log为业务日志,使用python logging模块打印

改进计划
^^^^^^^^

1. 实践优化,结合实际使用场景,不断发现缺陷并进行优化迭代
2. 提供更多推理引擎模版 ams-processor-xxx
3. 集成监控模块



