PaddleNLP icon indicating copy to clipboard operation
PaddleNLP copied to clipboard

[Question]: 请教下UIE 用 flask部署如何多进程?

Open YYGe01 opened this issue 3 years ago • 2 comments

请提出你的问题

您好: 我用flask部署了uie模型,代码如下:

from flask import request, jsonify, Flask
from src.parser import DocParser
import threading
lock = threading.Lock()
server = Flask(__name__)

# 调用uie模型
parser = DocParser(model_path_prefix="src/uie/export/building/inference")


@server.route('/docParser', methods=['get', 'post'])
def parser_server():
    file = request.files.get('file')  # 接受上传文件
    lock.acquire()
    result = parser.parser_passage(file)
    if isinstance(result, dict):
        lock.release()
        return jsonify(result), 200
    else:
        lock.release()
        return jsonify({"msg": result}), 500


if __name__ == '__main__':
    server.run(port=9092, host='0.0.0.0', debug=False, threaded=True) 

服务启动后,我为了测试预测速度,同时请求这个接口好几次,发现都是按顺序等待访问的,很耗时间。 然后我把lock.acquire()和lock.release()去掉,又同时请求,发现只有一个请求成功,其他都报错。

我对并发编程用的不多,问下这个uie能否支持多个用户同时访问,并同时出来结果嘛,谢谢。

我看uie 的taskflow好像支持了并发,但是我对uie内部做了一些改造,所以没法用封装好的taskflow,所以按照 uie部署教程 做了自己的封装,不知道我这种情况应该如何支持并发,谢谢。

YYGe01 avatar Oct 14 '22 03:10 YYGe01

不知道是不是需要更新下uie/deploy/python/uie_predictor.py文件,才可以支持并发。

YYGe01 avatar Oct 14 '22 03:10 YYGe01

您好,paddle inference不是线程安全的,不能被同时调用,所以这里需要加锁

linjieccc avatar Oct 17 '22 02:10 linjieccc

This issue is stale because it has been open for 60 days with no activity. 当前issue 60天内无活动,被标记为stale。

github-actions[bot] avatar Dec 17 '22 00:12 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale. 当前issue 被标记为stale已有14天,即将关闭。

github-actions[bot] avatar Dec 31 '22 00:12 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale. 当前issue 被标记为stale已有14天,即将关闭。

@sijunhe 即使issue已经关闭了,这里也还会触发。

wj-Mcat avatar Dec 31 '22 05:12 wj-Mcat