Httpd %2 mem/cpu, is that bad?

With httpd, I’m ranging anywhere from 2-5% in CPU usage per httpd, and an average of %2 memory usage.

We have an API we’ve developed on our site that is VERY OOP so it loads quite a few files every page load. I understand this may play a role. One of the big benefits of this API is that we can separate our SQL to a separate server by changing 2-3 lines of code and be done. We built the site with the perspective of server space is cheap, lets focus on outputting features quickly. Don’t get me wrong, we still use optimization techniques and do everything as efficiently as we can.

Our server specs aren’t anything special, the cheapest we could find at our host to be honest. Is it normal to have these kind of usage numbers?

Depends… what’s that a percentage of? 1% of the latest Opteron processor isn’t the same as 1% of a Pentium 4, and 1% of 8GB RAM isn’t the same as 1% of 256MB RAM.

Here’s one of my web servers, quad core Xeon with 2GB RAM:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
19219 apache    16   0 95588  16m 8448 S  1.3  0.9   0:00.13 httpd
18968 apache    15   0 96412  18m 9420 S  1.0  1.0   0:00.37 httpd
19074 apache    15   0 94548  17m  10m S  1.0  1.0   0:00.24 httpd
19087 apache    15   0 96400  20m  11m S  1.0  1.2   0:00.23 httpd
19227 apache    15   0 94828  11m 4640 S  1.0  0.7   0:00.12 httpd
18619 apache    15   0 94812  19m  12m S  0.7  1.1   0:00.51 httpd
18697 apache    15   0 94532  18m  11m S  0.7  1.1   0:00.44 httpd
18766 apache    18   0 94788  17m 9.9m S  0.7  1.0   0:00.46 httpd
18781 apache    15   0 95740  20m  12m S  0.7  1.2   0:00.82 httpd
18840 apache    17   0 94804  18m  11m S  0.7  1.1   0:00.57 httpd
18873 apache    15   0 96180  19m  11m S  0.7  1.1   0:00.40 httpd
18875 apache    15   0 94920  18m  10m S  0.7  1.1   0:00.37 httpd
18930 apache    15   0 95636  18m  10m S  0.7  1.1   0:00.23 httpd
18940 apache    15   0 95620  18m 9.8m S  0.7  1.0   0:00.27 httpd
18983 apache    15   0 94788  16m 9140 S  0.7  0.9   0:00.26 httpd
19019 apache    15   0 96144  19m  10m S  0.7  1.1   0:00.28 httpd
19020 apache    15   0 94836  11m 4340 S  0.7  0.6   0:00.18 httpd
19102 apache    15   0 95488  19m  11m S  0.7  1.1   0:00.31 httpd
19111 apache    16   0 94976  18m  10m S  0.7  1.1   0:00.25 httpd
19200 apache    15   0 94592  13m 6920 S  0.7  0.8   0:00.11 httpd
19236 apache    15   0 95216  14m 7592 S  0.7  0.9   0:00.10 httpd
19238 apache    20   0 94884  15m 8540 S  0.7  0.9   0:00.12 httpd
18534 apache    15   0 94728  19m  12m S  0.3  1.1   0:00.49 httpd
18699 apache    15   0 94812  18m  10m S  0.3  1.0   0:00.46 httpd
18755 apache    15   0 94740  19m  11m S  0.3  1.1   0:00.49 httpd
18773 apache    15   0 95744  20m  12m S  0.3  1.2   0:00.41 httpd
18938 apache    16   0 95876  19m  11m S  0.3  1.1   0:00.24 httpd
18955 apache    15   0 95628  18m  10m S  0.3  1.1   0:00.18 httpd
18962 apache    15   0 95884  19m  10m S  0.3  1.1   0:00.27 httpd
18989 apache    18   0 94916  19m  11m S  0.3  1.1   0:00.29 httpd
18994 apache    15   0 94556  14m 7376 S  0.3  0.8   0:00.24 httpd
19011 apache    15   0 94788  11m 4472 S  0.3  0.7   0:00.18 httpd
19026 apache    15   0 96152  19m  11m S  0.3  1.1   0:00.27 httpd
19035 apache    15   0 96400  18m 9456 S  0.3  1.0   0:00.22 httpd
19040 apache    15   0 94660  18m  10m S  0.3  1.0   0:00.29 httpd
19064 apache    15   0 94812  18m  11m S  0.3  1.1   0:00.53 httpd
19077 apache    15   0 95628  15m 7068 S  0.3  0.9   0:00.21 httpd

If your app is PHP, you should be running an opcode cache, like APC. Then it doesn’t really matter how many files are involved in your app, the precompiled code will be in memory rather than have to reinterpret it on each request.

I’m guessing your not wondering about the 2-5% percent, but what will happen if a lot of users visit your website at the same time.

You can test the server load with the ApacheBench application.

Type


ab --help

On a command prompt for help about ApacheBench.

Quick example:


ab -n 100 -c 20 http://www.mydomain.com/

This requests http://www.mydomain.com/ 100 times, using 20 concurrent threads (Simulating 20 users visiting your website at the exact same time).

When I run this on my local computer I get a about a 70% CPU usage for HTTPD for such a traffic spike. I think this is rather normal.

NOTE: When you have a floodfilter on your server you might very well get banned by the server if you use ApacheBench to benchmark it.

If you’re really wondering about 2-5%, it’s fine, wouldn’t do anything about it.

Thanks for the advice, I’ll surely test the server load.

Dan, I’ve looked at APC before and was hesitant to implement it because I was afraid if I applied on the fly changes to the site that it might not get updated or might be difficult to test changes made to the PHP. Is it a timed cache or does it use file modification time?

It checks the modification time, you won’t have to change anything you do currently, it’s all automatic.