Estou executando meu aplicativo django no apache2 (com mpm prefork) com um banco de dados mysql. Ele funciona bem, exceto quando vários usuários o usam, e leva em torno de 40-45m RES para cada usuário.
link
WSGIScriptAlias / /home/myproject/apache/django.wsgi
Alias /blog /var/www/blog/
Alias /maintain_wp_database/phpmyadmin_secure /usr/share/phpmyadmin
django_wsgi:
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
path2 = '/home'
if path2 not in sys.path:
sys.path.append(path2)
path = '/home/myproject'
if path not in sys.path:
sys.path.append(path)
arquivo de configuração:
<VirtualHost *:80>
ServerName myproject.com
ServerAlias www.myproject.com
#
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.myproject\.com
RewriteRule (.*) http://myproject.com$1 [R=301,L]
#
DocumentRoot /home
WSGIScriptAlias / /home/myproject/apache/django.wsgi
<Directory /home/myproject/static>
Order deny,allow
Allow from all
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
Alias /static/ /home/myproject//static/
Alias /robots.txt /home/myproject/templates/robots.txt
Alias /favicon.ico /home/myproject/static/images/favicon.ico
AliasMatch ^/([^/]*\.css) /home/myproject/styles/$1
Alias /media/ /home/myproject/media/
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
<Directory /home/myproject/apache>
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
apache2.conf:
KeepAlive On
Timeout 300
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
saída do topo:
top - 11:24:10 up 3 days, 1:08, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 140 total, 1 running, 134 sleeping, 5 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1011248k total, 491532k used, 519716k free, 11380k buffers
Swap: 262140k total, 119884k used, 142256k free, 127244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7678 www-data 20 0 228m 42m 6812 S 0 4.3 0:01.16 apache2
7665 www-data 20 0 232m 41m 4956 S 0 4.2 0:00.75 apache2
7676 www-data 20 0 212m 40m 4628 S 0 4.1 0:00.27 apache2
7956 www-data 20 0 230m 39m 4416 S 0 4.0 0:00.65 apache2
7677 www-data 20 0 230m 39m 4452 S 0 4.0 0:00.69 apache2
7667 www-data 20 0 224m 36m 4836 S 0 3.7 0:00.48 apache2
2539 mysql 20 0 321m 28m 2584 S 0 2.9 0:12.32 mysqld
7661 root 20 0 181m 9772 4588 S 0 1.0 0:00.12 apache2
7724 www-data 20 0 183m 9412 2228 S 0 0.9 0:00.01 apache2
7666 www-data 20 0 183m 9360 2240 S 0 0.9 0:00.01 apache2
7668 www-data 20 0 183m 9108 2108 S 0 0.9 0:00.00 apache2
7981 www-data 20 0 183m 8596 1768 S 0 0.9 0:00.00 apache2
4645 root 20 0 71120 3580 2532 S 0 0.4 0:00.07 sshd
7993 root 20 0 70664 3296 2556 S 0 0.3 0:00.02 sshd
Preciso otimizar minhas configurações ou isso é um problema de vazamento de memória (algo errado no código talvez?). Por causa de cada usuário ter 40-45m (isso é normal ??) no apache, a maior parte da memória do meu linode de 1GB é consumida rapidamente. Qualquer ajuda nisso seria ótimo! Obrigado