uwsgi worker not distributing evenly

1.8k Views Asked by At

I have a Django project configured with nginx and uwsgi. There isn't much cpu processing involved in the website. There is mostly simple read, but we expect lot of hits. I have used apache bench mark for load testing. Giving a simple ab -n 200 -c 200 <url> is making the website slower (while the benchmark test is on, not able to open the website in any browser even from a different ip address). I have given number of processes as 16 and threads as 8. my uwsgi.ini file is given below.

[uwsgi]
 master          = true 
 socket          = /tmp/uwsgi.sock
 chmod-socket    = 666
 chdir           = <directory>
 wsgi-file       = <wsgi file path>
 processes       = 16
 threads         = 8
 virtualenv      = <virtualenv path>
 vacuum          = true
 enable-threads  = true
 daemonize= <log path>
 stats= /tmp/stats.sock

enter image description here when i check the uwsgitop, what is seen that workers 7 and 8 are handling most of the requests, rest of them are processing less number of requests compared to them. Could this be the reason why i cannot load the website in a browser while benchmark is run ? How can i efficiently use uwsgi processes to serve maximum number of concurrent requests ?

enter image description here

this the result of htop. Not much memory or processor is used during the benchmark testing. Can somebody help me to set up the server efficiently ?

2

There are 2 best solutions below

0
tuergeist On

As far as I can see, there are only 2 cores. You cannot span a massive amount of processes and threads over just two cores. You'll get advantages if your threads have to wait for other IO processes. Then they go to sleep and others can work.

Always max two (=number of cores) at the same time.

You do not provide much information about your app except that it's "mostly simple read, but we expect lot of hits". This is not the sound of a lot of IO waits. I guess the database is running on the same host as well (will need some CPU time as well)

Try to lower your threads/processes to 4 at first. Then play around with +/- 1 and test accordingly.

Read https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html You'll find sentences like:

There is no magic rule for setting the number of processes or threads to use. It is very much application and system dependent.

By default the Python plugin does not initialize the GIL. This means your app-generated threads will not run. If you need threads, remember to enable them with enable-threads. Running uWSGI in multithreading mode (with the threads options) will automatically enable threading support. This “strange” default behaviour is for performance reasons, no shame in that.

0
Hadisur Rahman On

If you have enough money change your processor according to your motherboard requirements. Better go for core i3 or above.

This is because you have only two core processor which is easily got hotted when you run a multi-thread software. You can,t make very task on it. Sometimes it runs so fast and then stopped some massive multi-thread software.