I'm running django application using apache+mod_wsgi, I have setup 6 medium ubuntu servers on Amazon ec2 in which 2 for mongo and 4 for django and apache, using ebs for postgresql and configured a load balancer around all apache servers, each server is having 4 GB RAM, but during heavy load the system get slow, I saw using top command that apache is using 7 processes and eating approx 2.4 GB of RAM. Below is the apache MPM prefork module config

2 Answers
2

The configuration you use really depends on the specifics of your particular Python web application. Without proper monitoring it will be very hard for you to optimally tune your Apache and mod_wsgi configuration.

In just what you have explained so far I can see various potential issues.

The first is that you are aiming to use mod_wsgi daemon mode, but are you? You don't give the full configuration and WSGIDaemonProcess directive alone doesn't mean you are actually using daemon mode. If you have not setup daemon mode properly, you will consume lots of memory very quickly with that configuration, as the web application could well be running in the Apache child worker processes and not in mod_wsgi daemon mode processes.

A second issue if you aren't using daemon mode properly is that you min/max settings will cause process churn. This will cause higher CPU load from constant reloading of your application as traffic volume goes up and down in short order.

A third is that even if you are using daemon mode properly, have you disabled Python from running in the Apache child worker processes to save on memory and CPU? Why are you even using prefork MPM and not worker MPM which is much better if you are using mod_wsgi daemon mode.

A fourth is that depending on balance between CPU bound and I/O bound tasks in your web application, a 2 processes and 25 threads could be quite bad. Using just 3 processes with 5 threads each may well be better, but not knowing what you application does, is really hard to say, monitoring is really needed.

Anyway, I could keep going on as that isn't all the potential issues I can see, but one is really guessing without real performance data to gauge what you should do.

The StackOverflow sites may be okay for simple answers pandering to the TLDR crowd, but they are a useless forum for a proper discussion of a topic like this as there is no simple answer one can give in two sentences.