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 ?
uwsgi (all lowercase) is the native binary protocol that uWSGI uses to communicate with other servers. uWSGI is often used in conjunction with web servers such as Cherokee and Nginx, which offer direct support for uWSGI's native uwsgi protocol, to serve Python web applications such as Django.
Running uWSGI in multithreading mode (with the threads options) will automatically enable threading support.
yes, every single thread can manage a single request, so if you have 3 processes and 5 threads you can manage 15 concurrent requests. Save this answer. Show activity on this post. when hosting python behind uWSGI, it can only run as many simultaneous requests as processes there are.
WSGI is a specification. uWSGI provides an implementation of the WSGI specification. You can't compare them. You can only compare different implementations.
Adding an additional answer here due to a huge GOTCHA I had today.
Shared memory works across threads, but not processes. That is, if you have some module level thing like:
# mymodule
mycache = {}
mycache[key] = value
del mycache[key]
...
Deletes in one process will NOT be reflected in the cache of another process. However, deletes in one thread, if only one process is used, will persist across threads.
So if you are using shared memory like this, you have two options:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With