Tuning PHP with mod_fcgid (with screenshot)

7 posts / 0 new
Last post
#1 Fri, 02/06/2009 - 21:57
elvis.mcneely

Tuning PHP with mod_fcgid (with screenshot)

I am wondering why fastcgi isn't using more memory... My machine has 12gb of ram and two 3mhz dual core processors, with CentOS5.2 & Virtualmin Pro.

To tune I used the Apache Benchmark (AB) and the top command to watch what could be tuned. The AB tests were done on on a page that has several hundred mysql queries, another words no static files. The parameters I used for all tests were: ab -c20 -n1000 url

The first test results, with no tuning averaged out a measly 4.4 requests per second.

Then I modified httpd.conf and installed APC. That alone gave a 200% boost.

Running the test over. AB showed mysql was using a ton of the CPU and memory, so I added some parameters to my.cng, like query_cache_size and others that are commonly suggested. That gave an extra 30% boost. I was expecting more though.

Re-running the test, in the Top command there are several php-cgi threads. I then modified the PHP memory_limit in php.ini and /home/account/etc/php.ini. The memory_limit was set to 16M and I set it to 384M, just to see. That gave a small boost, still the Requests per second are slow compared to reports from other sysadmins who shared their tuning experience.

At this point I am not sure where to look further. It seems that php-cgi or fcgid somehow have a memory cap that php.ini files don't control. I would like to throw more memory at PHP if possible. Any ideas on what might be causing this? See the attached screenshot of Top during an AB run.

Any help would be appreciated.

Sun, 02/08/2009 - 14:10
andreychek

Hmm, well, first off, what does "uname -a" show?

Also, if you go into Server Configuration -> Website Options, what is "PHP FCGId sub-processes" set to?
-Eric

Sun, 02/08/2009 - 14:15 (Reply to #2)
elvis.mcneely

<div class='quote'>Hmm, well, first off, what does &quot;uname -a&quot; show?</div>

Linux myhostname.net 2.6.18-53.el5PAE #1 SMP Mon Nov 12 02:55:09 EST 2007 i686 i686 i386 GNU/Linux

<div class='quote'>Also, if you go into Server Configuration -&gt; Website Options, what is &quot;PHP FCGId sub-processes&quot; set to?</div>

It is set to none. Should it be set to something? If so how can I make this for all existing servers?

Thanks

Sun, 02/08/2009 - 14:52 (Reply to #3)
andreychek

Well, by increasing that, it should keep more PHP code in memory.

I'm not sure what number to tell you to try -- the best I can offer is to tinker with it :-)

I might start off by setting it to 10, then run some benchmarks against it.

If that help, you can change it for multiple domains using modify-web.pl (assuming you have the Pro version):

http://www.virtualmin.com/documentation/id,virtualmin_api_modify_web/

With that much RAM, I might also consider bumping up the StartServers and MaxClients directives in your Apache config (but again, make sure you test all that, what will work best on your server depends on your setup and what sort of apps you have there).
-Eric

Fri, 02/20/2009 - 05:56 (Reply to #4)
elvis.mcneely

<b>andreychek wrote:</b>
<div class='quote'>Hmm, well, first off, what does &quot;uname -a&quot; show?

Also, if you go into Server Configuration -&gt; Website Options, what is &quot;PHP FCGId sub-processes&quot; set to?
-Eric</div>

Thanks Eric, I did test some of your suggestions but they didn't really help. I found that my current setup seems to be running fine, I just wanted more memory to be used.

Tue, 03/03/2009 - 22:13 (Reply to #5)
fuerst

Some suggestions:

- the 384 MB you gave PHP will only be used if needed. So I guess your application just don't need more. I don't know about any memory limit by fcgid though.

- APC: Did you tune it to use a higher cache size? Don't know though if APC works across many PHP instances run by fcgid. Visiting apc.php after running your tests may give you a number about how to tune it.

Tue, 03/03/2009 - 08:03
bradleyjond

elvis.mcneely,

Have you figured anything else out? I am running a very similar system and have too noticed the CPU usage is higher than I'd like.

Seems like more RAM should be used.

Thanks for any updates.

Brad

Topic locked