VPS Memory Optimization - 20 php54.cgi procces 15MB each


#1

EDIT: I was able to figure out how to access each of the individual websites now and I am seeing the php54.cgi commands.

“Memory used” is stuck at a constant 250-350MB range, yet my sites are only handling 150 visitors per hour.

Using the “top -c” command, I’m seeing like five php54.cgi commands taking up 15MB of memory each (a few of them will jump up to 76MB each for a short time and sometimes 40 different php54.cgi tasks will start up out of nowhere). My heaviest traffic site has 12 php54.cgi processes running at around 15MB each. Does this sound right? This appears to be where most of the memory is being taken up.

Also when I enter the “ls” command, I see my regular website directories and files, but I also see HUNDREDS of duplicates of my cronjob files in there as well:

croncount.php.1
croncount.php.10
croncount.php.100
croncount.php.11

Is this natural?

Here is a copy of what I am seeing for my two big sites. How can I tell how long a process lasts, is the time in seconds or milliseconds? Most of the tasks are “Sleeping”? Please interpret what these mean:

Site 1 - (400 visits/day):
top - 12:39:31 up 57 min, 2 users, load average: 0.93, 0.71, 0.62
Tasks: 10 total, 1 running, 9 sleeping, 0 stopped, 0 zombie
Cpu(s): 77.2%us, 6.9%sy, 0.2%ni, 13.6%id, 1.7%wa, 0.0%hi, 0.4%si, 0.0%st
Mem: 512000k total, 290588k used, 221412k free, 0k buffers
Swap: 0k total, 0k used, 0k free, 114236k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2483 site1 20 0 239m 14m 9260 S 1 2.9 0:06.08 php54.cgi
2486 site1 20 0 240m 14m 9148 S 0 3.0 0:07.20 php54.cgi
7428 site1 20 0 240m 15m 9320 S 0 3.1 0:32.52 php54.cgi
7433 site1 20 0 241m 16m 9428 S 0 3.3 0:34.15 php54.cgi
22418 site1 20 0 18988 1208 916 R 0 0.2 0:00.09 top -c
23803 site1 20 0 70516 1496 780 S 0 0.3 0:00.14 sshd: site1@pts/2
23804 site1 20 0 17748 1852 1380 S 0 0.4 0:00.04 -bash
24937 site1 20 0 239m 15m 9332 S 0 3.1 0:22.50 php54.cgi
28030 site1 20 0 240m 15m 9412 S 0 3.2 0:40.97 php54.cgi
32121 site1 20 0 239m 15m 9328 S 0 3.0 0:45.44 php54.cgi

Site 2 - 5000 visits per day:
top - 12:39:42 up 57 min, 2 users, load average: 0.88, 0.71, 0.62
Tasks: 11 total, 2 running, 9 sleeping, 0 stopped, 0 zombie
Cpu(s): 53.0%us, 5.4%sy, 0.2%ni, 40.3%id, 0.7%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 512000k total, 307020k used, 204980k free, 0k buffers
Swap: 0k total, 0k used, 0k free, 114636k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21214 site2 20 0 266m 39m 9404 R 37 7.9 0:27.17 php54.cgi
25886 site2 20 0 247m 22m 9332 S 2 4.5 0:10.13 php54.cgi
25846 site2 20 0 241m 14m 9392 S 2 3.0 0:12.74 php54.cgi
16620 site2 20 0 240m 15m 9304 S 0 3.0 0:32.71 php54.cgi
22629 site2 20 0 239m 14m 9180 S 0 2.9 0:12.06 php54.cgi
25826 site2 20 0 239m 14m 9132 S 0 2.9 0:09.68 php54.cgi
25860 site2 20 0 239m 14m 9140 S 0 2.8 0:20.56 php54.cgi
25861 site2 20 0 239m 14m 9244 S 0 2.9 0:22.83 php54.cgi
29817 site2 20 0 70512 1496 784 S 0 0.3 0:00.12 sshd: site2@pts/3
29818 site2 20 0 17744 1836 1372 S 0 0.4 0:00.00 -bash
29960 site2 20 0 18988 1208 916 R 0 0.2 0:01.37 top -c

Some of the php54.cgi tasks jump up to 40M or so. The total memory used stays around 300MB but spikes up to the max at times and I’m not sure why.


#2

UPDATE
Here is some more statistics for one of my sites just before it maxed out the memory and crashed:

top - 17:05:30 up 24 min, 2 users, load average: 0.40, 0.43, 0.30
Tasks: 11 total, 1 running, 10 sleeping, 0 stopped, 0 zombie
Cpu(s): 12.3%us, 3.2%sy, 0.5%ni, 83.8%id, 0.1%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 640000k total, 640000k used, 0k free, 0k buffers
Swap: 0k total, 0k used, 0k free, 30360k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28833 site2 20 0 18988 1204 916 R 0 0.2 0:01.79 top -c
14586 site2 20 0 314m 73m 11m D 0 11.8 0:22.01 php54.cgi
15127 site2 20 0 287m 46m 10m D 0 7.4 0:13.67 php54.cgi
15148 site2 20 0 283m 42m 11m D 0 6.9 0:21.44 php54.cgi
15697 site2 20 0 322m 81m 10m D 0 13.0 0:08.28 php54.cgi
15700 site2 20 0 320m 79m 11m D 0 12.8 0:15.24 php54.cgi
16364 site2 20 0 326m 84m 10m D 0 13.6 0:02.52 php54.cgi
16365 site2 20 0 326m 85m 10m D 0 13.7 0:03.72 php54.cgi
16384 site2 20 0 259m 17m 10m D 0 2.8 0:05.55 php54.cgi
28793 site2 20 0 70516 1496 780 S 0 0.2 0:00.15 sshd: site2@p
28794 site2 20 0 17748 1804 1340 S 0 0.3 0:00.00 -bash

Note that there are 8 php54.cgi processes running between 17MB-85MB each. It’s also showing a “D” status meaning it’s in “Uninterruptible Sleep”, which I hear is bad?

Please let me know how I can fix this and get the server stable like it was on Shared Hosting. I am still new to Apache and VPS.

Thanks


#3

After doing more research, I found something about altering this variable:

DefaultMaxClassProcessCount

Supposedly I can limit the number of php54.cgi processes this way?

I’ve been messing around in the shell for one of my domain names and I’m not exactly sure where this variable and configuration file is found. The closest thing I found was located in this path:

/home/[username]/[domain]/cgi-bin/dispatch.fcgi

I tried editing this file and rebooting the server, but it didn’t work…


#4

Nevermind this question, I was able to figure this out!

Had to login to the shell using sudo and then edit the “mod_fcgid.c” module in the httpd.conf apache configuration file.

I’m trying to limit the processes to maybe 3 php54.cgi process to prevent the memory from maxing out? Seems like 4 was too much when some big scripts were executed at one time.

Not exactly sure if there are more things to watch out for here? Should I increase the “MaxRequestsPerProcess” from 500?

Thanks