每个UWSGI进程运行多个线程有什么优势? [英] What's the advantage of running multiple threads per UWSGI process?

查看:1132
本文介绍了每个UWSGI进程运行多个线程有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在执行诸如查询数据库之类的阻止操作,那有什么好处?如何增加额外的有价值的容量?

If I'm performing blocking operations like querying a database, then what is the advantage? How does this add extra worthwhile capacity?

推荐答案

Python的本机多线程受GIL限制的影响.简而言之,一次只执行一个Python线程.例外情况是阻止IO调用(例如DB查询),该调用让其他Python线程接管,这可能会提高IO绑定操作的性能.

Python's native multithreading is affected by GIL limitations. Simply put, only one Python thread at a time is physically executed. An exception to this are blocking IO calls (e. g. DB query) that let other Python threads take over, which may increase performance of IO-bound operations.

因此,只有在您的应用程序大部分受IO限制的情况下,才有可能实现真正的性能提升.但是,在这种情况下,您应该考虑使应用程序异步化,uWSGI也支持该应用程序.

So the real performance gain would only be possible if your application is mostly IO-bound. However, in this case you should consider making the app asynchronous, which uWSGI also supports.

否则,您应保持应用程序为单线程,并使用多进程uWSGI进行扩展.

Otherwise you should keep your app single-threaded and use multiprocess uWSGI to scale up.

这篇关于每个UWSGI进程运行多个线程有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆