Reputation: 56
I have dedicate server with 3.1GHz single quad core CPU with 32 GB RAM. It works as a web server and configured to: Apache 2.4 + MPM Worker + Mod_fcgid
When I run top command, I see high CPU usage by PHP processes of website. Below is a snapshot
Tasks: 193 total, 1 running, 112 sleeping, 1 stopped, 79 zombie
Cpu(s): 84.0%us, 1.4%sy, 0.0%ni, 12.3%id, 2.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 33554432k total, 26637508k used, 6916924k free, 0k buffers
Swap: 0k total, 0k used, 0k free, 10471152k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8415 mysql 20 0 12.5g 4.1g 6348 S 115.1 12.8 5107:00 mysqld
18687 domainus 20 0 303m 110m 44m S 64.5 0.3 1:05.51 php
18728 domainus 20 0 311m 118m 46m S 42.7 0.4 1:00.57 php
18732 domainus 20 0 333m 140m 45m S 40.3 0.4 1:19.61 php
17371 domainus 20 0 306m 114m 46m S 32.5 0.3 0:57.16 php
18726 domainus 20 0 278m 87m 47m S 24.8 0.3 1:48.62 php
14765 domainus 20 0 324m 133m 47m S 17.7 0.4 4:00.94 php
I want to be sure that, my Apache configuration is right and the problem is with the PHP code, any suggestions on how to drill down the issue?
Upvotes: 1
Views: 12728
Reputation: 126
I think the bottleneck here is your MySQL as its consuming most of cpu and php most probability is making those querying. The issue could be due to poor php code.
Correct way to drill down the problem so make use of php profiler and see which function is taking time and then dealing with appropriately. Like db interaction is taking time then try to cache queries, batch queries to avoid concurrency issues.
Upvotes: 1
Reputation: 1548
My suggestion would be to run the PHP from the command line and see what happens. If possible turn off Apache beforehand. Also try running the same site/PHP on a different server. If you have no other server available you can use a Vagrant box. One can easily create a box with PHP and Apache using Puphpet.
If no problems arise while running these tests try disabling PHP in Apache and request some plain HTML pages.
Upvotes: 1