Optimize apache for WP use

时间:2011-04-05 作者:Souljacker

您好,

我有一个WP网站,每天浏览量超过15万次。

它运行在Intel Core i5 CPU [email protected]、Centos和4 GB RAM上。

问题是WP消耗了太多的RAM,过了一段时间,serve就会过载,RAM就会耗尽。我尝试了很多Apache tweeks,但似乎没有任何效果。在我重新启动Apache站点后,它将平稳运行,但一两个小时后,它将再次超载。

你们有什么可以帮我的小费吗?

顺便说一句,我正在使用WP超级缓存。

UPDATE: Aditional info

以下是我的插件列表:

Akismet联系方式7域镜像更快的图像插入更具目的性的eBate角色管理器至于tweeks我试过一些技巧from here

我的设置是:

 <IfModule prefork.c> 
  StartServers       8
  MinSpareServers    5 
  MaxSpareServers   20 
  ServerLimit      256 
  MaxClients       200 
  MaxRequestsPerChild  1000
 </IfModule>




<IfModule worker.c> 
  StartServers       2 
  MaxClients         150
  MinSpareThreads     25 
  MaxSpareThreads    75
  ThreadsPerChild     25
  MaxRequestsPerChild  1000 
</IfModule>




 Timeout 120 KeepAlive On
 MaxKeepAliveRequests 100
 KeepAliveTimeout 2
这也是我的。cnf公司

[mysqld]
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

UPDATE

这是我当前的内存使用情况

ps -ylC httpd --sort:rss

S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S   504  8446  8444  0  78   0  7884 59507 554050 ?        00:00:00 httpd
S   504 29164  8444  0  78   0 13380 87043 -      ?        00:00:00 httpd
S   504 29268  8444  0  75   0 13396 87043 429493 ?        00:00:00 httpd
S   504 29294  8444  0  75   0 13396 87043 -      ?        00:00:00 httpd
S   504 29255  8444  0  75   0 13400 87043 -      ?        00:00:00 httpd
S   504 29269  8444  0  76   0 13400 87043 387946 ?        00:00:00 httpd
S   504 29256  8444  0  75   0 13404 87043 -      ?        00:00:00 httpd
S   504 29265  8444  0  75   0 13404 87043 -      ?        00:00:00 httpd
S   504 29288  8444  0  75   0 13404 87043 429493 ?        00:00:00 httpd
S   504 28644  8444  0  75   0 13484 87043 -      ?        00:00:00 httpd
S   504 29293  8444  0  75   0 13484 87043 semtim ?        00:00:00 httpd
S   504 27280  8444  0  75   0 13496 87043 -      ?        00:00:00 httpd
S   504 28332  8444  0  75   0 13500 87043 -      ?        00:00:00 httpd
S   504 27762  8444  0  75   0 13504 87043 -      ?        00:00:00 httpd
S   504 28645  8444  0  75   0 13504 87043 -      ?        00:00:00 httpd
S   504 29242  8444  0  75   0 13508 87043 -      ?        00:00:00 httpd
S   504 28199  8444  0  75   0 13512 87043 429493 ?        00:00:00 httpd
S   504 28195  8444  0  75   0 13528 87043 -      ?        00:00:00 httpd
S   504 28197  8444  0  75   0 13528 87043 429493 ?        00:00:00 httpd
S   504 27245  8444  0  75   0 13536 87043 -      ?        00:00:00 httpd
S   504 28196  8444  0  75   0 13536 87043 -      ?        00:00:00 httpd
S   504 27756  8444  0  75   0 13540 87043 -      ?        00:00:00 httpd
S   504 27969  8444  0  75   0 13540 87043 -      ?        00:00:00 httpd
S   504 27074  8444  0  75   0 13544 87043 -      ?        00:00:00 httpd
S   504 27279  8444  0  75   0 13544 87043 -      ?        00:00:00 httpd
S   504 27926  8444  0  75   0 13548 87043 -      ?        00:00:00 httpd
S   504 28191  8444  0  75   0 13548 87043 semtim ?        00:00:00 httpd
S   504 28673  8444  0  75   0 13548 87043 -      ?        00:00:00 httpd
S   504 27089  8444  0  75   0 13552 87043 -      ?        00:00:00 httpd
S   504 27825  8444  0  75   0 13552 87043 -      ?        00:00:00 httpd
S   504 27974  8444  0  75   0 13552 87043 -      ?        00:00:00 httpd
S   504 28330  8444  0  75   0 13552 87043 -      ?        00:00:00 httpd
S   504 26051  8444  0  75   0 13556 87043 -      ?        00:00:00 httpd
S   504 28343  8444  0  75   0 13556 87043 -      ?        00:00:00 httpd
S   504 26822  8444  0  75   0 13560 87043 -      ?        00:00:00 httpd
S   504 27975  8444  0  75   0 13560 87043 -      ?        00:00:00 httpd
S   504 28662  8444  0  75   0 13560 87043 -      ?        00:00:00 httpd
S   504 24949  8444  0  75   0 13564 87043 -      ?        00:00:00 httpd
S   504 28639  8444  0  75   0 13564 87043 -      ?        00:00:00 httpd
S   504 24924  8444  0  75   0 13572 87043 -      ?        00:00:00 httpd
S   504 27826  8444  0  75   0 13572 87043 -      ?        00:00:00 httpd
S   504 28192  8444  0  75   0 13572 87043 -      ?        00:00:00 httpd
S   504 28683  8444  0  76   0 13572 87043 -      ?        00:00:00 httpd
S   504 19032  8444  0  75   0 13576 87043 -      ?        00:00:00 httpd
S   504 26832  8444  0  75   0 13576 87043 -      ?        00:00:00 httpd
S   504 28186  8444  0  75   0 13580 87043 -      ?        00:00:00 httpd
S   504 24940  8444  0  75   0 13584 87043 -      ?        00:00:00 httpd
S   504 27883  8444  0  75   0 13584 87043 -      ?        00:00:00 httpd
S   504 27962  8444  0  75   0 13588 87043 -      ?        00:00:00 httpd
S   504 28331  8444  0  75   0 13588 87043 -      ?        00:00:00 httpd
S   504 18521  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 24291  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 24307  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 26503  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 26510  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 27100  8444  0  75   0 13592 87043 -      ?        00:00:00 httpd
S   504 27248  8444  0  75   0 13592 87043 429493 ?        00:00:00 httpd
S   504 28344  8444  0  75   0 13592 87043 429493 ?        00:00:00 httpd
S   504 24952  8444  0  75   0 13596 87043 -      ?        00:00:00 httpd
S   504 26588  8444  0  75   0 13596 87043 -      ?        00:00:00 httpd
S   504 27065  8444  0  75   0 13596 87043 -      ?        00:00:00 httpd
S   504 27102  8444  0  75   0 13600 87043 -      ?        00:00:00 httpd
S   504 27104  8444  0  75   0 13600 87043 429493 ?        00:00:00 httpd
S   504 27474  8444  0  75   0 13600 87043 429493 ?        00:00:00 httpd
S   504 27763  8444  0  75   0 13600 87043 -      ?        00:00:00 httpd
S   504 23657  8444  0  75   0 13604 87043 -      ?        00:00:00 httpd
S   504 24311  8444  0  75   0 13604 87043 -      ?        00:00:00 httpd
S   504 24790  8444  0  75   0 13604 87043 -      ?        00:00:00 httpd
S   504 25731  8444  0  75   0 13604 87043 -      ?        00:00:00 httpd
S   504 27087  8444  0  75   0 13604 87043 -      ?        00:00:00 httpd
S   504 24473  8444  0  75   0 13608 87043 -      ?        00:00:00 httpd
S   504 27976  8444  0  75   0 13612 87043 -      ?        00:00:00 httpd
S   504 28163  8444  0  75   0 13620 87043 -      ?        00:00:00 httpd
S   504 29266  8444  0  75   0 14204 87043 -      ?        00:00:00 httpd
S   504 17701  8444  0  75   0 14392 87043 -      ?        00:00:00 httpd
S   504 27881  8444  0  75   0 14408 87043 -      ?        00:00:00 httpd
S   504 26593  8444  0  75   0 14412 87043 -      ?        00:00:00 httpd
S   504 27072  8444  0  76   0 14428 87043 -      ?        00:00:00 httpd
S   504 17704  8444  0  75   0 15028 87043 -      ?        00:00:00 httpd
S   504 28674  8444  0  75   0 17076 87299 -      ?        00:00:00 httpd
S   504 23649  8444  0  75   0 17180 87299 -      ?        00:00:00 httpd
S   504 21484  8444  0  75   0 17232 87299 429493 ?        00:00:00 httpd
S   504 24034  8444  0  75   0 17240 87299 -      ?        00:00:00 httpd
S   504 24941  8444  0  75   0 17248 87299 -      ?        00:00:00 httpd
S   504 27058  8444  0  75   0 17256 87299 -      ?        00:00:00 httpd
S   504 24766  8444  0  75   0 17272 87299 -      ?        00:00:00 httpd
S   504 28333  8444  0  75   0 17284 87299 semtim ?        00:00:00 httpd
S   504 20565  8444  0  75   0 17296 87299 semtim ?        00:00:00 httpd
S   504 25462  8444  0  75   0 17296 87299 -      ?        00:00:00 httpd
S   504 28201  8444  0  75   0 17296 87299 -      ?        00:00:00 httpd
S   504 28202  8444  0  75   0 17316 87299 -      ?        00:00:00 httpd
S   504 27968  8444  0  75   0 17328 87299 -      ?        00:00:00 httpd
S   504 27973  8444  0  75   0 17328 87299 -      ?        00:00:00 httpd
S   504 24091  8444  0  75   0 17336 87299 429493 ?        00:00:00 httpd
S   504 28329  8444  0  75   0 17344 87299 -      ?        00:00:00 httpd
S   504 27885  8444  0  75   0 17352 87299 -      ?        00:00:00 httpd
S   504 21556  8444  0  75   0 17356 87299 semtim ?        00:00:00 httpd
S   504 24121  8444  0  75   0 17356 87299 429493 ?        00:00:00 httpd
S   504 24929  8444  0  75   0 17356 87299 -      ?        00:00:00 httpd
S   504 27918  8444  0  75   0 17356 87299 -      ?        00:00:00 httpd
S   504 24778  8444  0  75   0 17360 87299 -      ?        00:00:00 httpd
S   504 27075  8444  0  75   0 17360 87299 -      ?        00:00:00 httpd
S   504 20603  8444  0  75   0 17364 87299 -      ?        00:00:00 httpd
S   504 24031  8444  0  75   0 17364 87299 429493 ?        00:00:00 httpd
S   504 24791  8444  0  75   0 17364 87299 -      ?        00:00:00 httpd
S   504 26509  8444  0  75   0 17364 87299 -      ?        00:00:00 httpd
S   504 27249  8444  0  75   0 17364 87299 -      ?        00:00:00 httpd
S   504 24148  8444  0  75   0 17372 87299 -      ?        00:00:00 httpd
S   504 24777  8444  0  75   0 17372 87299 -      ?        00:00:00 httpd
S   504 24472  8444  0  75   0 17392 87299 semtim ?        00:00:00 httpd
S   504 24789  8444  0  75   0 17432 87299 429493 ?        00:00:00 httpd
S   504 27066  8444  0  75   0 17432 87299 429493 ?        00:00:00 httpd
S   504 27106  8444  0  75   0 17452 87299 -      ?        00:00:00 httpd
S   504 26508  8444  0  75   0 17472 87299 -      ?        00:00:00 httpd
S   504 24168  8444  0  75   0 17488 87299 -      ?        00:00:00 httpd
S   504 22355  8444  0  75   0 17492 87299 -      ?        00:00:00 httpd
S   504 23656  8444  0  75   0 17844 87555 -      ?        00:00:00 httpd
S   504 27088  8444  0  75   0 17888 87555 -      ?        00:00:00 httpd
S   504 28198  8444  0  75   0 17900 87555 -      ?        00:00:00 httpd
S   504 26694  8444  0  75   0 17960 87555 -      ?        00:00:00 httpd
S     0  8444     1  0  78   0 20276 87043 -      ?        00:00:00 httpd
S   504 27271  8444  0  75   0 28796 90883 -      ?        00:00:00 httpd
S   504 19949  8444  0  75   0 28888 90883 -      ?        00:00:00 httpd
S   504 25736  8444  0  75   0 29840 91395 -      ?        00:00:00 httpd
S   504 27086  8444  0  75   0 29848 91395 -      ?        00:00:00 httpd
S   504 26606  8444  0  75   0 29856 91395 429493 ?        00:00:00 httpd
S   504 24159  8444  0  75   0 29876 91395 -      ?        00:00:00 httpd
S   504 26821  8444  0  75   0 29876 91395 -      ?        00:00:00 httpd
S   504 26815  8444  0  75   0 29932 91395 -      ?        00:00:00 httpd
S   504 27418  8444  0  75   0 29940 91395 -      ?        00:00:00 httpd
S   504 27426  8444  0  75   0 29944 91395 semtim ?        00:00:00 httpd
S   504 27468  8444  0  75   0 29948 91395 -      ?        00:00:00 httpd
S   504 26587  8444  0  75   0 29952 91395 -      ?        00:00:00 httpd
S   504 24486  8444  0  75   0 29956 91395 semtim ?        00:00:00 httpd
S   504 24951  8444  0  75   0 29956 91395 429493 ?        00:00:00 httpd
S   504 24180  8444  0  75   0 29960 91395 -      ?        00:00:00 httpd
S   504 24305  8444  0  75   0 29972 91395 -      ?        00:00:00 httpd
S   504 24467  8444  0  75   0 30008 91395 -      ?        00:00:00 httpd
S   504 26507  8444  0  75   0 30032 91395 semtim ?        00:00:00 httpd
S   504 24460  8444  0  75   0 30056 91651 -      ?        00:00:00 httpd
S   504 23669  8444  0  75   0 30076 91395 -      ?        00:00:00 httpd
S   504 26580  8444  0  75   0 30088 91651 -      ?        00:00:00 httpd
S   504 23112  8444  0  75   0 30172 91395 -      ?        00:00:00 httpd
S   504 26607  8444  0  75   0 30192 91395 -      ?        00:00:00 httpd
S   504 24772  8444  0  75   0 30212 91395 -      ?        00:00:00 httpd
S   504 24942  8444  0  75   0 30216 91395 -      ?        00:00:00 httpd
S   504 24167  8444  0  75   0 30220 91395 -      ?        00:00:00 httpd
S   504 26478  8444  0  75   0 30228 91395 -      ?        00:00:00 httpd
S   504 24184  8444  0  75   0 30260 91395 429493 ?        00:00:00 httpd
S   504 27425  8444  0  75   0 30292 91395 -      ?        00:00:00 httpd
S   504 22348  8444  0  75   0 30388 91651 -      ?        00:00:00 httpd
S   504 26605  8444  0  75   0 30396 91651 -      ?        00:00:00 httpd
S   504 22678  8444  0  75   0 30420 91395 -      ?        00:00:00 httpd
S   504 24489  8444  0  75   0 30452 91395 153384 ?        00:00:00 httpd
S   504 24296  8444  0  75   0 30480 91395 -      ?        00:00:00 httpd
S   504 24095  8444  0  75   0 30600 91651 -      ?        00:00:00 httpd
S   504 23085  8444  0  75   0 30688 91651 -      ?        00:00:00 httpd
S   504 19586  8444  0  75   0 30768 91395 -      ?        00:00:00 httpd
S   504 24182  8444  0  75   0 30768 91395 -      ?        00:00:00 httpd
S   504 18511  8444  0  75   0 30820 91395 -      ?        00:00:00 httpd
S   504 26594  8444  0  75   0 30836 91395 -      ?        00:00:00 httpd
S   504 13358  8444  0  75   0 30856 91651 -      ?        00:00:00 httpd
S   504 17681  8444  0  75   0 30988 91395 -      ?        00:00:00 httpd
S   504 22336  8444  0  75   0 31016 91651 -      ?        00:00:00 httpd
S   504 15690  8444  0  75   0 31040 91395 -      ?        00:00:00 httpd
S   504 22718  8444  0  75   0 31072 91651 -      ?        00:00:00 httpd
S   504 19043  8444  0  75   0 31080 91395 -      ?        00:00:00 httpd
S   504 12815  8444  0  75   0 31108 91651 -      ?        00:00:00 httpd
S   504 23301  8444  0  75   0 31112 91395 -      ?        00:00:00 httpd
S   504 24183  8444  0  75   0 31164 91395 -      ?        00:00:00 httpd
S   504 22670  8444  0  75   0 31180 91395 -      ?        00:00:00 httpd
S   504 22327  8444  0  75   0 31216 91651 -      ?        00:00:00 httpd
S   504 21489  8444  0  75   0 31220 91395 -      ?        00:00:00 httpd
S   504 21474  8444  0  75   0 31284 91395 -      ?        00:00:00 httpd
S   504 21596  8444  0  75   0 31296 91651 -      ?        00:00:00 httpd
S   504 22690  8444  0  75   0 31448 91395 -      ?        00:00:00 httpd
S   504 26595  8444  0  75   0 31452 91651 429493 ?        00:00:00 httpd
S   504 20312  8444  0  75   0 31476 91651 429493 ?        00:00:00 httpd
S   504 24313  8444  0  75   0 31592 91397 -      ?        00:00:00 httpd
S   504 24179  8444  0  75   0 31696 91395 -      ?        00:00:00 httpd
S   504 22369  8444  0  76   0 31732 88329 -      ?        00:00:00 httpd
S   504 13373  8444  0  75   0 31768 91395 429493 ?        00:00:00 httpd
S   504 17667  8444  0  75   0 31960 91651 429493 ?        00:00:00 httpd
S   504 18517  8444  0  75   0 32012 91651 -      ?        00:00:00 httpd
S   504  7793  8444  0  75   0 32040 91651 -      ?        00:00:00 httpd
S   504 17658  8444  0  75   0 32116 91395 -      ?        00:00:00 httpd
S   504 27272  8444  0  75   0 32224 91395 -      ?        00:00:00 httpd
S   504 13901  8444  0  75   0 32784 91395 -      ?        00:00:00 httpd
S   504 15366  8444  0  75   0 33168 91651 -      ?        00:00:00 httpd
S   504 24577  8444  0  75   0 33256 88085 -      ?        00:00:00 httpd
S   504 14330  8444  0  75   0 34192 91651 -      ?        00:00:00 httpd
S   504 15155  8444  0  75   0 34296 91395 -      ?        00:00:00 httpd
S   504 16312  8444  0  75   0 34496 91395 -      ?        00:00:00 httpd
S   504 28194  8444  0  75   0 36996 88848 -      ?        00:00:00 httpd
S   504 24776  8444  0  75   0 43720 92169 429493 ?        00:00:00 httpd
S   504 20584  8444  0  75   0 44224 92169 -      ?        00:00:00 httpd
S   504 22331  8444  0  75   0 44636 91913 -      ?        00:00:00 httpd
S   504 24033  8444  0  75   0 45496 91664 -      ?        00:00:00 httpd
S   504 22375  8444  0  75   0 46320 91664 -      ?        00:00:00 httpd
S   504 22378  8444  0  75   0 50064 91664 -      ?        00:00:00 httpd
S   504 24481  8444  0  75   0 53836 93968 -      ?        00:00:00 httpd
S   504 22354  8444  0  75   0 62124 93962 -      ?        00:00:00 httpd
这会改变你给我的建议吗?

4 个回复
SO网友:Chris_O

灵魂杰克,

我想先看看你的插件。Star Ratings for Reviews 已经三年多没有更新了,看起来对db来说真的很沉重。我看到一些原始sql,其中包含一些看起来很麻烦的内部联接。

在服务器端,您应该实现一些对象缓存。APC是事实上的标准,会给你最好的结果。

安装APC后,切换到W3 Total CacheMark Jaquith\'s APC Object Cache Backend 充分利用它。

您的httpd。conf设置看起来不错。从你我的长相来看。cnf,您没有利用MySQL查询缓存、线程缓存或控制任何缓冲区大小。

您可以使用调整脚本来帮助您完成my。cnf配置。我喜欢使用mysqltunertuning primer 也很好。

Mysqltuner将输出建议,并根据您的数据库使用情况为您提供一些关于调整内容的指导。

在带有12G Ram的服务器上,我的设置如下所示。(Just an example don\'t use these settings!!!)

key_buffer              = 512M
max_allowed_packet      = 32M
thread_stack            = 1M
thread_cache_size   = 128M

myisam-recover         = BACKUP
max_connections        = 60
table_cache            = 5000
table_definition_cache = 1024
thread_concurrency     = 16

# * Query Cache Configuration

query_cache_type        = 1
query_cache_limit       = 4M
query_cache_size        = 48M
max_heap_table_size     = 512M
tmp_table_size          = 512M
join_buffer_size        = 3M
sort_buffer_size        = 8M
read_buffer_size        = 8M
read_rnd_buffer_size    = 8M
myisam_sort_buffer_size =16M


log_slow_queries        = /var/log/mysql/mysql-slow.log
long_query_time = 1
与其他人提到的一样,如果您能够进行配置等,那么运行Nginx将大大减少服务器上的负载。我写了一篇关于如何安装和设置的教程Apache with Nginx as a reverse proxy

希望这有帮助。

SO网友:anu

请看这里:Performance tips for a large user base - 这是一组非常有用的东西,它超越了Apache。

在寻求优化性能时,查看整个基础架构以了解可能存在的问题非常重要—例如,我的一个站点最终将一个最初看起来像Apache问题(Apache在中等负载下内存不足)的问题跟踪到一个缓慢的SQL查询,该查询通过向注释表添加额外索引来修复。

另外,安装APC或其他一些PHP操作代码缓存。

[更新]

很可能您的MaxClients设置太高了—如果所有200个进程都处于活动状态,并且每个进程的平均容量约为20MB,那么您的4GB就用完了,而不考虑MySQL和所有其他进程。减少MaxCients设置,继续调查实际问题所在。

您可以检查每个Apache进程使用的内存量:

ps -ylC httpd --sort:rss
(如果您使用的是Ubuntu,请将apache2替换为httpd)

SO网友:edelwater

比较Nginx和Apache并做出选择:

SO网友:Sharma

使用预工作和工作配置是一件棘手的事情,更改一些值肯定会有助于提高性能并减少RAM使用,同时请记住apache保留了一些RAM,这并不意味着您的RAM即将耗尽。检查this article 获取最佳优化建议。

结束