I am running a wordpress site and each PHP process usage about 200mb to 250mb resident size memory. With 16GB of ram, the server can only handle about 70 processes. By increasing the virtual memory to 16GB it can handle 140. After that the load keeps rising. If there are 200 connections in 10 minutes, the server load reaches 20 on a 3Ghz quad-core xeon processor!
I have tried deactivating all the plugins, but this only reduces the PHP memory usage of each process by less than 10%. suPHP tells me which user is using so much memory, but not what part of the wordpress code.
Any suggestion on how to reduce the memory usage? Or is my only option to upgrade to 32GB of ram?
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10585 nobody 16 0 2266m 237m 199m S 21.3 1.5 1:09.17 /usr/bin/php
10597 nobody 16 0 2257m 255m 226m S 15.3 1.6 0:17.56 /usr/bin/php
Biggest outputs from pmap -d
000000000e8b8000 27580 rw--- 000000000e8b8000 000:00000 [ anon ]
00002b3772850000 2097152 rw-s- 0000000000000000 000:00009 [ shmid=0x2d1b803a ]
00002b37f2a62000 55108 r---- 0000000000000000 0fd:00000 locale-archive
mapped: 2320852K writeable/private: 30012K shared: 2097152K
ipcs output
------ Semaphore Arrays --------
key semid owner perms nsems
0x000000a7 0 root 600 1
0x00000000 162529281 nobody 600 1
0x00000000 162562050 nobody 600 1
0x00000000 162594819 nobody 600 1
0x00000000 162627588 nobody 600 1
------ Message Queues --------
key msqid owner perms used-bytes messages`
I’ll summarize what Lisa did to find the problem:
pmap -d <pid>
. The output showed that there’s a huge amount of shared memory used by the process:ipcs -m
. It showed that there are a lot of shared memory regions created by user nobody (the web server), here are just a few of them:Rasmus Lerdorf did a conference about PHP performance at Confoo in 2010 and he used a WordPress blog as an example, this should give you great tools to answer your question:
http://talks.php.net/show/confoo10/1
To sum up:
phpinfo()
and disable PHP extensions that you don’t use. They can take a lot of memory (imagick, curl, …)siege
. Sometimes, tiny optimisations have great impact on performance, so make sure you have metrics, to help you make your decisions.md5()
to hash my SQL queries and cache them. Themd5()
calls where using 20% of the CPU time.I would definitely start by disabling PHP extensions if possible.