Solved

Tuning PHP5 and FCGID on Debian etch4

Posted on 2008-06-23
11
3,164 Views
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
#export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=300
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
or
[warn] mod_fcgid: process 13274 graceful shutdown timeouted, sending SIGKILL
or
[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

Regards
0
Comment
Question by:ReadyToGo
  • 5
  • 4
11 Comments
 
LVL 57

Expert Comment

by:giltjr
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.
0
 

Author Comment

by:ReadyToGo
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
0
 
LVL 57

Expert Comment

by:giltjr
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.
0
 

Author Comment

by:ReadyToGo
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ReadyToGo
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.
0
 
LVL 57

Expert Comment

by:giltjr
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.
0
 

Author Comment

by:ReadyToGo
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.
0
 
LVL 57

Expert Comment

by:giltjr
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?  
0
 

Accepted Solution

by:
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.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now