What's the advantage of running multiple threa

2019-08-02 08:36发布

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

1条回答
冷血范
2楼-- · 2019-08-02 08:54

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.

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.

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

查看更多
登录 后发表回答