Search code examples
pythonwsgiuwsgi

What are uwsgi threads used for?


I see in a uwsgi.ini file there is a configuration

[uwsgi]
socket = 127.0.0.1:3031
chdir = /home/foobar/myproject/
wsgi-file = myproject/wsgi.py
processes = 4
threads = 2
stats = 127.0.0.1:9191

I understand that each request is served in a different process. Then what are threads used for ?


Solution

  • Both processes and threads can be used for increasing concurrency. Threads are cheaper than processes and use less resources, but may not always run in parallel because of Python GIL.

    Also, quoting the uWSGI documentation:

    There is no magic rule for setting the number of processes or threads to use. It is very much application and system dependent. Simple math like processes = 2 * cpucores will not be enough. You need to experiment with various setups and be prepared to constantly monitor your apps. uwsgitop could be a great tool to find the best values.