6

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

3
  • Django is built on top of Python and CPython has the GIL problem which causes this problem. Remember the following Django is a web framework and your biggest enemy is IO not CPU. IO can be fixed by using smart techniques AKA caching, optimized queries and memory data bases for Sessions.
    – abdul
    Commented Dec 3, 2015 at 1:39
  • 1
    No, Abdul is wrong. This has nothing to do with Django or Python, but is due to how you configure Apache Commented Dec 3, 2015 at 8:31
  • Daniel, you're right. I changed WSGIDaemonProcess localhost to WSGIDaemonProcess localhost processes=2 threads=25, then performance got much better. Commented Dec 3, 2015 at 8:43

1 Answer 1

16

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.

2
  • This helped me more than anything! Thanks!
    – user984003
    Commented Jan 7, 2018 at 19:37
  • This saved me a lot of time - Thank yu!
    – gies0r
    Commented Jan 21, 2018 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.