Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to effectively run Django with multi CPU cores

I'm developing a web application, and have a trouble that performance of Django doesn't improve when I increase number of CPU cores.
(actually 1 core does the highest performance and 2,4,8 cores don't differ much in their performance)
What my application does is to simply load static files(HTML, CSS, JS) and some data from database. I use Apache as a web server and mod_wsgi.

Is this Django's normal behavior?
If so how could I improve the performance with multi cores?
(I want to increase number of cores because CPU usage reaches about 90% with just 1 core)

▼ab -n 200 -c 200 for 1CPU core and 1GB memory enter image description here

▼ab -n 200 -c 200 for 2CPU cores and 1GB memory enter image description here

▼vmstat 1 for 1CPU core and 1GB memory enter image description here

▼vmstat 1 for 2CPU cores and 1GB memory enter image description here

like image 590
user2875308 Avatar asked Dec 11 '22 19:12

user2875308


1 Answers

I found that I just had to make some changes to Apache config file. I changed

WSGIDaemonProcess localhost

to

WSGIDaemonProcess localhost processes=2 threads=25

then response time decreased from 7 seconds to 2 seconds.
after that, I experimented with other number of CPU cores, and when I set the same number of processes as number of CPU cores, performance got better.

like image 137
user2875308 Avatar answered Jan 28 '23 16:01

user2875308