# Apache2 - high CPU utilization [SOLVED]

## dfelicia

I'm building a new LAMP box to replace an older one that runs RedHat.  Using latest stable Apache, PHP5, MySQL, and MediaWiki.

```

cat /etc/portage/package.use

net-www/apache apache2 ssl mpm-prefork no-htdocs

dev-lang/php -ipv6 apache2 bzip2 cgi ctype curl curlwrappers force-cgi-redirect ftp iconv inifile mysql sockets truetype xml xmlrpc xsl zip zlib

net-proxy/squid customlog logrotate

```

Some settings from httpd.conf:

```

<IfModule prefork.c>

    StartServers         5

    MinSpareServers      5

    MaxSpareServers     10

    MaxClients         150

    MaxRequestsPerChild  0

</IfModule>

HostnameLookups Off

KeepAlive Off

```

I'm running a Mercury LoadRunner script for 50 users, using the following scenario:

 50 users ramp up, 1 every 5 seconds

 Users are requesting http://{HOSTNAME}/wiki/index.php?title=Special:Random

 There is a 5 second "think" time between each request for the URL

 Scenario runs for 25 minutes after all 50 users are ramped up

 Users ramp down, 1 every 5 seconds

So for 25 minutes I have 50 users each requesting a random Wiki page every 5 seconds.  That results in 7,200+ pages served.

Results Summary:

Total Duration (including Ramp Up/Down):       28 minutes and 17 seconds.

Maximum Running Vusers:                              50

Total Throughput (bytes):                                53,948,276

Total Hits:                                                      88,171

Total Passed Transactions:                              7,243

Measurement                 Min.      Ave.    Max.     SD

Open Random Page        0.266    4.989  27.548  2.195

Measurement	Min.	Ave.	Max.	SD

Average load (Unix Kernel Statistics):stweb	0.168	19.781	28.078	8.139

CPU Utilization (Unix Kernel Statistics):stweb	2.423	62.801	100	23.753

Disk Traffic (Unix Kernel Statistics):stweb	6.661	32.723	79.175	15.603

So what concerns me is the high CPU.  63% average, and hit 100% at times during test.  Looking at mpstat, vmstat, top, and ps, it's clear that Apache is using all the CPU.  MySQL is pretty idle for the duration.

Note that I have tried this test with and without memcached, and with and without squid as a transparent proxy.  Neither had any impact on CPU (or transaction time - average is always about 5 seconds).  I also tried the mpm_worker (threads) and it made no difference.

The box is a dual-core Xeon 1.8 GHz with hyper-threading enabled.  2GB RAM.  3 x 146GHz 15K RPM SCSI Ultra320 disks, using software RAID1.  (I actually have to of these machines - 1 running x86, once running x86_63 since chip supports EM64T.  Both setups exhibit same behavior.)

The questions: Is my test valid?  Are the results expected?Last edited by dfelicia on Mon Oct 02, 2006 4:56 pm; edited 1 time in total

----------

## Janne Pikkarainen

With that kind of workload I would expect that Apache itself is pretty idle, too, but it's PHP which is eating up the CPU. I don't have much experience with MediaWiki so I don't if it's a CPU hog or not - you might want to run couple of MediaWiki pages from CLI with valgrind + PHP and see the results with KCachegrind. That would show you where PHP is spending its time. Also using some opcode cache for PHP (eAccelerator, ZendAccelerator or whatever there are nowadays) could help a lot.

----------

## dfelicia

Wow.  Eaccelerator made a HUGE difference:

Maximum Running Vusers:  	50

Total Throughput (bytes): 	100,450,708

Average Throughput (bytes/second): 	59,228

Total Hits: 	171,232

Average Hits per Second: 	100.962

Transactions:  	Total Passed: 14,115

Transaction Name  	Minimum  	Average  	Maximum  	Std. Deviation  	90 Percent  	Pass  	Fail  	Stop

Open Random Page 	0.05 	0.129 	0.901 	0.069 	0.23 	14,115 	0 	0

Average load (Unix Kernel Statistics):stweb	0.0	1.267	2.359	0.438

CPU Utilization (Unix Kernel Statistics):stweb	0.586	29.058	42.005	9.286

Paging rate (Unix Kernel Statistics):stweb	29.325	354.091	597.342	145.51

----------

## Janne Pikkarainen

Great.   :Very Happy: 

----------

## mlaccetti

I'd suggest XCache...   :Smile: 

But otherwise, nice test.

----------

## Mad Merlin

IME, eAccelerator does indeed make for a massive performance difference, for Game! (see my sig), Apache ended up consuming about 1/10th the CPU time with eAccelerator as compared to without.

----------

## mlaccetti

In my case, PHP chews a lot of CPU because of the forums that I host.  XCache brought that down a fair bit, though I'm waiting for the next version of SMF with native memcached support.  That'll be sweet.  MySQL was consuming ~99% of CPU time, because of the whole 50 queries/second that was going on.  Now it is down to about 12, and with the new SMF hopefully that drops to about 4-5.

----------

