admin管理员组文章数量:1336293
I have a Flask service that receives GET
requests, and I want to scale the QPS on that endpoint (on a single machine/container). Should I use a python ThreadPoolExecutor
or ProcessPoolExecutor
, or something else? The GET
request just retrieves small pieces of data from a cache backed by a DB. Is there anything specific to Flask that should be taken into account?
I have a Flask service that receives GET
requests, and I want to scale the QPS on that endpoint (on a single machine/container). Should I use a python ThreadPoolExecutor
or ProcessPoolExecutor
, or something else? The GET
request just retrieves small pieces of data from a cache backed by a DB. Is there anything specific to Flask that should be taken into account?
1 Answer
Reset to default 2Neither.
Flask will serve one request per worker (or more, but depending on the worker type) - the way you set-it up, either with gunicorn, wsgi or awsgi is what is responsible for the number of parallel requests your app can process.
Inside your app, you don't change anything - your views will be called as independent processes, independent threads or independent async tasks, depending on how you setup your server - that is where you have to tinker with the configurations.
Using another concurrency strategy would only make sense if each request would have calculations and data fetching which could themselves be parallelized, inside the same request.
Check how is your deployment configured, and pick the best option for you (all things being equal, pick the easiest one): https://flask.palletsprojects/en/stable/deploying/ (also, I would not recomend "mod_wsgi" among those options - it is super complex and old tech)
本文标签: pythonCorrect way to parallelize request processing in FlaskStack Overflow
版权声明:本文标题:python - Correct way to parallelize request processing in Flask - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742406638a2468954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ProcessPoolExecutor
requires non-trivial state synchronization, it really depends on how much state is being shared and how much work is being done in the workers. – Ahmed AEK Commented Nov 19, 2024 at 18:31select ... from db where user_id = xyz
each time the/GET
endpoint is reached. – Frank Commented Nov 19, 2024 at 18:34