我有一组用Python编写的网站(Django)。在一个站点,流量是其他站点的10倍。所有都在一个专用服务器上工作。为什么最大的网站比其他网站的工作速度慢?
配置:Ubuntu 12.04,Apache2,Django 1.3.1(通过mod_wsgi运行),PostgreSQL 9.1.3
答案 0 :(得分:1)
dpkg --get-selections | grep mpm
是否表明您使用的是apache2-mpm-worker
或apache2-mpm-prefork
?我使用 apache2-mpm-worker
并调整了apache2.conf
以更好地分配进程/线程。 prefork
工作者不适合Python / WSGI(虽然这只是我的意见)。
patrick@romulus:~$ sudo apt-get install apache2-mpm-worker
patrick@romulus:~$ sudo vim /etc/apache2/apache2.conf
# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
# graceful restart. ThreadLimit can only be changed by stopping
# and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
然后,在/etc/apache2/sites-available/site.conf
配置中:
<VirtualHost *:80>
# ...
# The following installs the Django WSGI app
WSGIDaemonProcess www.site.io threads=20 display-name=%{GROUP}
WSGIProcessGroup www.site.io
WSGIScriptAlias / /var/www/site.io/public/wsgi.py
</VirtualHost>
我相信这种调整可能会改善您的网站;但是,请确保在进行任何更改之前复制apache2.conf
和site.conf
,以便在网站性能下降时可以恢复。
patrick@romulus:~$ sudo cp /etc/apache2/apache2.conf ~/apache2.conf.bak
patrick@romulus:~$ sudo cp /etc/apache2/sites-available/site.conf ~/site.conf.bak
答案 1 :(得分:0)
没有足够的信息,我们需要一个非常好的水晶球才能猜到。去看看:
这至少可以为您提供一个起点,让您了解如何解决问题所在。