Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uwsgi: What defines the number of workers/process that a django app needs?

Tags:

I have a question for sysadmins and developers. I see that uWSGI allows me to set the number or workers or processes when running uWSGI and I had read that it depends on the installed machine, so I have the next questions:

  1. What are the rules that define the number of workers for the machine?
  2. When used with nginx, does the config worker_processes in nginx.conf affects this?
  3. When used with Celery and Redis, is the concurrency related to this?
  4. What about the thread safety in this setup? (I have seen cases in my app where 1 request executes 1 task and the result is 2 calls to celery with this task.)
like image 554
panchicore Avatar asked Oct 11 '12 14:10

panchicore


People also ask

How many processes does uWSGI have?

The threads option is used to tell uWSGI to start our application in prethreaded mode. That essentially means it is launching the application across multiple threads, making our four processes essentially eight processes.

How many employees does uWSGI have?

This configuration will tell uWSGI to run up to 10 workers under load. If the app is idle uWSGI will stop workers but it will always leave at least 2 of them running. With cheaper-initial you can control how many workers should be spawned at startup.

How many requests can uWSGI handle?

Running uWSGI in Async mode Each async core can manage a request, so with this setup you can accept 10 concurrent requests with only one process.


1 Answers

  • What are the rules that define the number of workers for the machine?

    From the uWsgi docs:

    There is no magic rule for setting the number of processes or threads. It is application and system dependent. Do not think using simple math like 2*cpucores will be enough. You need to experiment with various setup an constantly monitor your app. uwsgitop could be a great tool to find the best value.

  • When using with nginx, the config "worker_processes" in nginx.conf afects this?

    That setting is only related to nginx and doesn't directly affect uwsgi. However, you will probably need to tinker with this setting because you don't want to have twenty nginx worker_processes and only one uwsgi worker.

  • When using with celery+redis the "concurrency" is related with this?

    I usually spin up the Celery daemon with django's manage.py, so this will operate outside of uwsgi.

  • What about the thread safety in this setup?

    I'd have to know more details/specifics to comment.

like image 186
Scott Woodall Avatar answered Sep 30 '22 19:09

Scott Woodall