PaddleOCR 多线程并发问题
机器狗调试 ocr 服务发现服务挂掉了,查看错误日志:
(paddle_env) [root@iZ2ze17ubu754nk7lbead6Z iuyun-vision-base]# tail -f iuyun_vision_service.err.logFile "/usr/local/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2224, in __init__for frame in traceback.extract_stack():NotFoundError: Variable Id 146596816 is not registered.[Hint: Expected it != Instance().id_to_type_map_.end(), but received it == Instance().id_to_type_map_.end().] (at /paddle/paddle/fluid/framework/var_type_traits.cc:98)[operator < fused_conv2d > error],耗时: 0.014 秒
[2025-08-06 17:51:26,587] [ INFO] _internal.py:97 - 127.0.0.1 - - [06/Aug/2025 17:51:26] "POST /ocr/number_recognize HTTP/1.1" 500 -
[2025-08-06 17:51:26,596] [ ERROR] controller.py:72 - OCR 处理失败: could not execute a primitive,耗时: 0.022 秒
[2025-08-06 17:51:26,596] [ INFO] _internal.py:97 - 127.0.0.1 - - [06/Aug/2025 17:51:26] "POST /ocr/number_recognize HTTP/1.1" 500 -
[2025-08-06 17:51:26,612] [ INFO] _internal.py:97 - 127.0.0.1 - - [06/Aug/2025 17:51:26] "POST /ocr/number_recognize HTTP/1.1" 200 -
这意味着多线程并发访问模型时可能导致变量注册冲突,修改线程池为单线程:
executor = ThreadPoolExecutor(max_workers=1)
# executor = ThreadPoolExecutor(max_workers=config.SERVICE_CONFIG["max_workers"]["ocr"])
再次启动服务并查看输出日志:
(paddle_env) [root@iZ2ze17ubu754nk7lbead6Z iuyun-vision-base]# tail -f iuyun_vision_service.log
[2025/08/06 18:11:10] ppocr DEBUG: rec_res num : 1, elapse : 0.03553628921508789
[2025/08/06 18:11:20] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:20] ppocr DEBUG: dt_boxes num : 1, elapse : 0.010322809219360352
[2025/08/06 18:11:20] ppocr DEBUG: rec_res num : 1, elapse : 0.03722119331359863
[2025/08/06 18:11:20] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:20] ppocr DEBUG: dt_boxes num : 1, elapse : 0.00933527946472168
[2025/08/06 18:11:20] ppocr DEBUG: rec_res num : 1, elapse : 0.03775501251220703
[2025/08/06 18:11:20] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:20] ppocr DEBUG: dt_boxes num : 1, elapse : 0.010746955871582031
[2025/08/06 18:11:20] ppocr DEBUG: rec_res num : 1, elapse : 0.03646540641784668
[2025/08/06 18:11:34] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:34] ppocr DEBUG: dt_boxes num : 1, elapse : 0.03401660919189453
[2025/08/06 18:11:34] ppocr DEBUG: rec_res num : 1, elapse : 0.03658294677734375
[2025/08/06 18:11:34] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:34] ppocr DEBUG: dt_boxes num : 1, elapse : 0.009592294692993164
[2025/08/06 18:11:34] ppocr DEBUG: rec_res num : 1, elapse : 0.03547239303588867
[2025/08/06 18:11:34] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:34] ppocr DEBUG: dt_boxes num : 1, elapse : 0.009001493453979492
[2025/08/06 18:11:34] ppocr DEBUG: rec_res num : 1, elapse : 0.0348973274230957
[2025/08/06 18:11:48] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2025/08/06 18:11:48] ppocr DEBUG: dt_boxes num : 0, elapse : 0.01165628433227539
[2025/08/06 18:11:48] ppocr DEBUG: rec_res num : 0, elapse : 1.9073486328125e-06
[2025/08/06 18:11:48] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
服务暂时可以正常用,但是后续需要考虑多线程并发问题。