在等待长时间的数据库查询(uWSGI)时释放工作人员进行处理?

Free up workers for processing while waiting for long DB queries (uWSGI)?

我正在为我的公司维护 API 服务器,其中 运行 是 python flask 应用程序 uwsginginx.

之上
...

@app.route('/getquick', methods=["GET"])
def GET_GET_IP_DATA():
    sp_final = "CALL sp_quick()"
    cursor.execute(sp_final)

@app.route('/get_massive_log', methods=["POST"])
def get_massive_log():
    sp_final = "CALL sp_slow()"
    cursor.execute(sp_final)
...

虽然第一个请求 /getquick 的处理速度非常快,但 /get_massive_log 最多可能需要五秒钟,因为相当 漫长而复杂的 mySQL 查询 。服务器可以处理这些查询中的少数几个,但在调用太多时开始创建管道错误。

问题是,其他 /getquick 请求被这些长 I/O 请求阻止。

我的经理建议我使用 gevent 以某种方式释放服务器以在等待 mySQL 查询时处理其他请求,但我不确定是否我正在寻找正确的方向。

我正在使用 pymysql 进行 运行 查询,google 似乎建议在 uwsgi[ 之上使用 gevent,但我没能用它产生更好的结果。

我已经 googled 好几天了,虽然我试图了解线程、并发、异步请求,但我不知道从哪里开始挖掘以找到解决方案。有可能吗?将不胜感激任何建议甚至指向研究地点的指示。

编辑: 也许我的问题不太清楚,所以我会尝试重述一下:

在使用 uwsgi 等待长时间的数据库查询时,什么是释放工作人员以处理其他请求的最佳方法?

您需要了解 Uwsgi offloading

Offloading is a way to optimize tiny tasks, delegating them to one or more threads.

These threads run such tasks in a non-blocking/evented way allowing for a huge amount of concurrency.

您可以在 docs

中阅读有关卸载子系统的信息