Tutorial :Django, mod-wsgi, and daemon mode; problem “bash:fork:cannot allocate memory”



Question:

I would appreciate if someone can provide feedback or point me in the correct direction. I am unable to execute any terminal commands on a remote server when three django sites are running in daemon mode. I do not have a problem when I use embedded mode on one or two sites. When I enter the commands I only get "-bash:fork:cannot allocate memory".

The system: Ubuntu 8:04 LTS remote on virtual cloud, no SWAP file but 512 RAM(free, top and pc aux indicating only 20% memory used), access with Putty, FTP with WINSCP, UFW firewall set up, Apache 2.2.8, pre-forked, mod-wsgi 2.3, sqlite db,

.conf file, as of now with daemons commented out;

NameVirtualHost *:80

Helme as follows

<VirtualHost *>      ServerAdmin webmaster@facts.com      ServerName helme.h1.net      DocumentRoot /home/helme/django/facts/apache/      DirectoryIndex index.html index.htm        ServerAlias  helme.h1.net www.helme.h1.net        <Directory /home/helme/django/facts/apache/>          Options Indexes FollowSymLinks          AllowOverride AuthConfig          Order allow,deny          Allow from all        </Directory>        ErrorLog /home/helme/django/facts/log/error.log      LogLevel info      CustomLog /home/helme/django/facts/log/access.log common        #WSGIDaemonProcess helme.h1.net user=www-data group=www-data processes=5 threads=1      #WSGIProcessGroup helme.h1.net          WSGIScriptAlias / /home/helme/django/facts/apache/django.wsgi        <Directory /home/helme/django/facts/apache/>          Order allow,deny          Allow from all      </Directory>      </VirtualHost>  

Charly as follows

<VirtualHost *>      ServerAdmin webmaster@facts-pte.com      ServerName facts-pte.h1.net      DocumentRoot /home/pte/django/facts/apache/      DirectoryIndex index.html index.htm        ServerAlias  facts-pte.h1.net www.facts-pte.h1.net        <Directory /home/pte/django/facts/apache/>          Options Indexes FollowSymLinks          AllowOverride AuthConfig          Order allow,deny          Allow from all        </Directory>        ErrorLog /home/pte/django/facts/log/error.log      LogLevel info      CustomLog /home/pte/django/facts/log/access.log common        #WSGIDaemonProcess facts-pte.h1.net user=www-data group=www-data processes=5 threads=1      #WSGIProcessGroup facts-pte.h1.net          WSGIScriptAlias / /home/pte/django/facts/apache/django.wsgi        <Directory /home/pte/django/facts/apache/apache/>          Order allow,deny          Allow from all      </Directory>    </VirtualHost>  

wuest as follows

<VirtualHost *>      ServerAdmin webmaster@facts.com      ServerName wuest.h1.net      DocumentRoot /home/wuest/django/wuest/apache/      DirectoryIndex index.html index.htm        ServerAlias  wuest.h1.net www.wuest.h1.net        <Directory /home/wuest/django/wuest/apache/>          Options Indexes FollowSymLinks          AllowOverride AuthConfig          Order allow,deny          Allow from all      </Directory>        ErrorLog /home/wuest/django/wuest/log/error.log      LogLevel info      CustomLog /home/wuest/django/wuest/log/access.log common        WSGIDaemonProcess wuest.h1.net user=www-data group=www-data processes=5 threads=1      WSGIProcessGroup wuest.h1.net          WSGIScriptAlias / /home/wuest/django/wuest/apache/django.wsgi        <Directory /home/wuest/django/wuest/apache/>          Order allow,deny          Allow from all      </Directory>      </VirtualHost>  

Which memory is full? If Apaceh was loaded as 'worker' mpm would I have the same problem? Is it as simple as adding a SWAP file? Will I have more memory probelms when I install postgresql?

Please note I am not an advanced programmer or administrator just managing the remote server for a freind who is working on the Django projects.

Any help would be appreciated. kind regards Michael


Solution:1

Well, running a server without a swap space (swap is usually not a file, but a hard disk partition on Linux) is a recipe for a disaster. Adding one would almost certainly fix your problem.

Basically, it's not uncommon for what ever you have running on your server to allocate all the RAM available. To have your server running as fast as possible, it's desirable to have all or as much as possible of the information your server needs to do its job available in RAM.

To explain the concept of virtual memory, a server with only 512 MB RAM might easily have its RAM used up, but the operating system's kernel will need to have some sort of reserve, so there will always be memory available for allocation, if for example (in your case) a new user logging in needing to start a shell like bash.

So if the server has swap available, you'll be allowed to allocate memory, even if all the physical memory is in use already. Usually, this will cause the kernel to move some of the seldom accessed information from RAM to swap, giving your new process a bit of real, physical memory.

But if the kernel has no virtual memory available (RAM is full and swap is full or missing), it has no other options than denying the request to allocate memory. Which will cause situations like this where you can't login.

To prevent this from happening, the current advise is to create a swapping space twice as large as your physical memory (1 GB in this case), although that would probably not need to exceed 4 GB in most cases.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »