Tuning PHP5 and FCGID on Debian etch4

Posted on 2008-06-23
Last Modified: 2013-12-20
Hi all,
it's first time i post here so i hope to respect rules of this board.

I have many server web apache2-mpm-worker with php5 as module.
I want increase performance and i want limit some websites trying mod_fcgid.

Now i have about 6000-8000 websites on each server (2 X AMD Opteron 275 Dual Core) and with php5 as module they work good ( load less than 5 score daily)
Problem is that, sometimes, one website cause high load web server.
I want to preview high load problem so i thought that with mod_fcgid or just fastcgi, i can limit processes for each website so that ONLY website that cause high load will have problem and not all others.

After some tuning I tried mod_fcgid with following options:

cat /etc/apache2/mods-enabled/fcgid.conf
AddHandler fcgid-script .fcgi .php
SocketPath /var/lib/apache2/fcgid/sock
IdleTimeout 30
BusyTimeout 30
ProcessLifeTime 360
SpawnScoreUpLimit 21000
MaxProcessCount 21000
DefaultMaxClassProcessCount 21000
IPCConnectTimeout 3
IPCCommTimeout 6

And php-cgi script as follow:
export PHPRC=/var/www/domain.ext/www/sys/conf
export TMP=/var/www/domain.ext/www/sys/tmp
exec /usr/bin/php5-cgi $@

This is not enough cause "looklikes" that process will never die

I reached about 1000-1200 sleeping process( most of them php5-cgi ) and 8GB DDR RAM were full and start swapping.
CPU is ok but RAM is full (on each php.ini memory limit is 24M)

If i stop apache2, php5-cgi still alive unless i kill them with kill command, manually.

With mod_php i do not have these probs so i would like to know how tuning fcgid with php5 to consume less memory and be sure that process are killed after timeout.

On error.log i can see these messages:

[notice] mod_fcgid: process /var/www/domain.ext/www/sys/env/php-cgi(13093) exit(idle timeout), terminated by calling exit(), return code: 0
[warn] mod_fcgid: process 13274 graceful shutdown timeouted, sending SIGKILL
[notice] mod_fcgid: process /var/www/domain.ext/www/sys/env/php-cgi(13274) exit(busy timeout), get stop signal 9

so looklikes that processes are killed but anyway there still be too many processes and after few hours websites are not visible anymore(apache2 and php5-cgi still running).

So i hope that someone can show me light

Sorry for this "long" question.
I hope to be clear.

Waiting for your answer

Question by:ReadyToGo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 57

Expert Comment

ID: 21852212
--> ( load less than 5 score daily)

What does this mean?  The load average on the server? If you load average is 5 for a 24 hour period, then the box is over utilized.

Author Comment

ID: 21852248
Yes it's load average and for "less than 5" i mean that server reach 5 score few times.
Mrtg reports that load has score around 2 all day(24h)

Anyway i do not think this is question
LVL 57

Expert Comment

ID: 21852353
I understand that is not the question.  However if your server load indicates how busy your system is.  Is the 2 the avg. over 24 hours or the actual number for each 5 minute interval?

With dual core CPU's I would say that anything over 3 or 3.5 would be bad.

What I am attempting to see if maybe you load is too much for a single computer with two dual-core CPU's.
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.


Author Comment

ID: 21853791
2 is load each 5 interval so i think is good enough.

Problem is that memory finish too fast (8GB DDR RAM) so it start swap.

I mean if it could be a hw problem, then problem is about memory and not CPU.

Also CPU is 70%-80% free instead of memory usage.

Anyway i think (and i hope ) that i can tune better config.

I notice for example that another hosting provider host on one single server ( Dual Xeon 3150 if i am not wrong, with 8GB RAM for sure) 12000 websites while i host 6000 websites.

This hosting provider did not finish RAM while i finish.

That's why i think that my config could be tune better.

Author Comment

ID: 21853797
2 is load each 5 minutes interval so i think is good enough.

I wrote wrong on my last comment without specify minutes.
LVL 57

Expert Comment

ID: 21854582
If the load is 2 for each 5 min. interval that is fine.  However, unless I am missing something a total system CPU avg. utilization 70-80%  should mean that your load avg. should be above 2.

With "4" CPU's a system CPU busy of 25% would mean that you are basically using 100% of 1 CPU, a system CPU busy of 50% would mean you are using 100% of 2 CPU's and a system CPU busy of 75% would mean 100% of 3 CPU's.

Since you are avg. 70-80% that means you are using 100% of 2 CPU's all of the time 80%+ of the 3rd CPU and sometimes 10% of the 4th.    If  you are using that much CPU I would expect your load to be higher.

Now you could be having memory issues.  If you are limting each PHP process to 24GB of memory and you only have 8GB of RAM, that means you are allowing each process to use 3 times the amount of physical memory.  Which will cause swaping and swaping is a BAD thing.  How much RAM is normally used?  How much of this is cache and how  much is buffers?

You can't necessary compare what somebody else is doing with what you are doing.  The other hosting provider may not have any PHP running, the PHP they are running may not be as complex, or they could have less traffic than you do.  Its like saying I can carry 10 boxes, but you can only carry 5.   Why?  Easy, each of my boxes way 1 pound, but each of your's weighs 3 pounds.

Do you control the PHP code?  If  not, then there may not be much you can do.  If you do control the code, you may want to look at it to verify that it is cleaning up properly.

How are you running Apache?  MPM or pre-fork?  How do you have these parameters coded?  It could be you are letting the child processes run for to many requests and they are chewing up too much memory.

Author Comment

ID: 21855099
I say that:
Also CPU is 70%-80% free <- then CPU usage is about 20%

So forget CPU.

I can and i must compare to other hosting provider cause php is same package version, os same version, apache2 worker same version and i can access to server-status and server-info about this other hosting provider.

PHP environment is the same and they do more traffic than me (i can see by mod_cband with public access on each server).
Apache environment is the same(StartServers and so on).

Configuration is different only about fcgid directives.

I know that you are trying to help me but please, believe me when i tell you that i replicate same environment of other hosting company, a part of fcgid directives.
LVL 57

Expert Comment

ID: 21857051
Sorry about the confusion on the CPU utilization, normally people put the CPU busy, not the CPU free.

As I do not know the exact setup of your enviroment or of the other hosting provider I want to make as few assumptions as possible.  You know the environments, I don't.  If you have ever tried to help somebody without knowing the details, then you should know that as soon as you  make an assumptions, you start making the wrong recommendations.

What is your RAM utilization?  How much is buffer and cache?

Just because you are using the same "everything" if the customers are writing PHP code, you don't control that and so what your customers may be doing may not be what the other customers are doing.

I don't know how many times I have been told "I have two things that are setup exactly the same."  To find out there was a list of 20 things that were different.

If the only difference (other than processor type) if the fcgid directives, have you tried using what they are using?

Are you using MPM or fork?  

Accepted Solution

ReadyToGo earned 0 total points
ID: 22775802
Anyway, only now i discovered that a company create a custom suexec module to let run apache (worker) with php as cgi and not fcgi and this module works like a charm.

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
remove computer from using logon script 17 45
PS call executable Files in Order 4 30
Install XRDP on Ubuntu Server 16.10 x64 3 59
Understanding ping command in Ubuntu 5 30
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. Once you open the link you will see …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question