logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Eliminating Bloat and Optimizing Apache Performance

 
Post new topic   Reply to topic    Apache Forum Index -> How-to's & Documentation & Tips



View previous topic :: View next topic  
Author Message
CanUuRead



Joined: 18 Sep 2006
Posts: 38

PostPosted: Fri 06 Oct '06 22:16    Post subject: Eliminating Bloat and Optimizing Apache Performance Reply with quote

I thought I would share some experience.

Discovering the Bloat

Apache can really start hogging and hooking memory in a hurry. Try opening your Task Manager (in Windows), look on the Processes Tab. For ease sort the Image Name alphabetical (click on Image Name).

Now start Apache and you will note the TWO instances of HTTPD.EXE will appear. Once Apache has stabilized (memory consuption levels off), open a browser and navigate to your local web.

First, just go to a HTML page and watch the HTTPD.EXE instances in Task Manager. Depending on what you have on that page and how Apache is configured you will note one of the instances grow.

Now, go to a PHP page (especially if you run PHP as a module). Watch that instance grow some more.

Finally, do the same for Perl or Python if you use them and especially as modules loaded by Apache.

Grows amazingly doesn't it? That is what people refer to as BLOAT. If you have the patience watch it for 5 minutes and 1 second. By default, Apache is set to Timeout after 300 second (5 minutes). Did it all clear out - probably not.

Controlling Apache

Here are some Directives I use to control some of how Apache handles itself:

MaxMemFree
ThreadLimit
ThreadStackSize
ThreadsPerChild
MaxRequestsPerChild
KeepAliveTimeout
MaxKeepAliveRequests

DO YOURSELF A FAVOR - At least do some cursory reading on the above links before you start trying to implement. Make a Copy of your HTTPD.CONF and store it in another location in case things get screwed up and out of hand. You have been warned.

Below are VALUES I use for a LOW-VOLUME site (try to be honest with yourself - either you get a lot of traffic or you don't - there's no shame in having low traffic - it is what it is):

MaxMemFree 16
ThreadLimit 32
ThreadStackSize 8192
ThreadsPerChild 32
MaxRequestsPerChild 100
KeepAliveTimeout 2
MaxKeepAliveRequests 10

If you have medium to large amount of traffic, it's best to stick with the defaults.

If you have large to extremely heavy amount of traffic, you have probably already figured out that you needed to tweak Apache.

Again, if you're running a low traffic and maybe even a medium traffic web give the example above a shot.

Putting Apache on a Diet

Finally, do some LoadModule clean up. If you are not using a module, then comment out the line. Consider the following:

Download Apache Documentation - I suggest the CHM file if you are a Windows User. Find out what you need and cut out the rest. How? Simple but tedious. Use the Manual, in the CHM file when you execute it it will display a Table of Contents. Look in the Right Pane | Middle Left for Reference Manual. Click on the Modules link. Once there each modules a link for detailed information and there's also a short description of what each module does. Cut the FAT - You'll trim down your menory usuage and increase the performance of Apache.

Example:
Are you using ANY authenication besides Allow from in your configuration? If not, then you can comment out ALL of the Auth, Authn, and Authz LoadModule statements Except for authz_host_module.

If you want to dispute any of this, feel free. However, come with proof or save your keystrokes. Mr. Green
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Fri 06 Oct '06 22:38    Post subject: Reply with quote

Good tips, I have an addition.

I am running php as Fastcgi here at the Apache Lounge and the memory usage of httpd.exe is now after some time ~100M and two php precesses of ~10M each, when I runned php as module it was far over 400M.

So running as Fastcgi memory usage of Apache is far less en the Speed is on par when running as module. There are advantages to running PHP with FCGI. Separating the PHP code from the web server removes 'bloat' from the main server, and improves the performance of non-PHP requests. Secondly, having one permanent PHP process as opposed to one per apache process means that shared resources like persistent MySQL connections are used more efficiently. And maybe even more important is stability, since I run FCGI my server never crashed caused by php (extension) errors.


Steffen

ps.
I move this post to the forum How-to's & Documentation & Tips.
Back to top
CanUuRead



Joined: 18 Sep 2006
Posts: 38

PostPosted: Fri 06 Oct '06 22:44    Post subject: Reply with quote

Steffen,

Can you share your PHP FCGI setup with us? In other word, how you configure Apache and PHP for the FCGI setup. I'm sure others will be interested.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Sat 07 Oct '06 13:18    Post subject: Reply with quote

It is on the download page here and the author site has the documentation, see http://fastcgi.coremail.cn/ .

Steffen
Back to top
CanUuRead



Joined: 18 Sep 2006
Posts: 38

PostPosted: Mon 09 Oct '06 19:34    Post subject: Reply with quote

Now you delete post...hmmm...
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Mon 09 Oct '06 20:08    Post subject: Reply with quote

Nope,

I split the post, because this forum is not ment for issues. Your post is in the "Apache third-party Modules" forum.
Back to top
chrisd



Joined: 10 Sep 2006
Posts: 9
Location: Colorado

PostPosted: Wed 29 Nov '06 13:41    Post subject: Thanks for the tip on FCGI, I'm now running it ... Reply with quote

Hi Steffen,

Thanks for the tip on FCGI, I'm now running it with eAccelerator.

I took me some time to get this working, so to help others here is a quick article:
http://www.sitebuddy.com/php/php_apache_fast_cgi_install

One of my problems was that the following did not work:
FCGIWrapper "c:/php/php.exe" .php
but this did:
FCGIWrapper "c:/php/php-cgi.exe" .php

I didn't have the time yet to play around with the FCGI Directives, let me know if you found the good tweaks that make this software stack even faster.

Cheers,
Chris

PS: Thanks for compiling this Apache module!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Wed 29 Nov '06 14:36    Post subject: Reply with quote

Thanks for the nice words.

ApacheLougne is also running eAccelerator with mod_fcgid

Advised is to set:

MaxRequestsPerProcess 500

This is because a possible race condition. Namely php has hard coded that after 500 requests it spawns a new process. This they have done because they know Smile that several PHP functions are known to have memory leaks. If the PHP processes were left around forever, they would be become very inefficient.


For the rest the dafault values are fine here, only I set:

IPCCommTimeout 64
IPCConnectTimeout 16

Steffen
Back to top
chrisd



Joined: 10 Sep 2006
Posts: 9
Location: Colorado

PostPosted: Thu 30 Nov '06 1:33    Post subject: Reply with quote

Thanks again Steffen.

Today I'm seeing a few of these in my Apache log (I got LogLevel to warn):
Code:

[Wed Nov 29 09:35:11 2006] [warn] mod_fcgid: process 2880 graceful kill fail, sending SIGKILL
[Wed Nov 29 09:47:29 2006] [warn] mod_fcgid: process 6616 graceful kill fail, sending SIGKILL
[Wed Nov 29 09:50:20 2006] [warn] mod_fcgid: read timeout from pipe

I'm assuming this is normal or that your timeout values will help.

The only thing I think is noticeable is that some graphics appear a little slower then with the "in-process" (ie none-cgi) PHP EA stack.
For example the random image in the top right corner here:
http://www.anciensducaire.com
You can actually see (in FireFox) the "img alt" content for a second or two.

I use Gallery2 for my graphics on a number of sites. If someone has a tweak to accelerate the display of grahics with G2, it would be welcome.

But heck, if this stack is stable it's gold to me...

Cheers,
Chris
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2581
Location: Hilversum, NL, EU

PostPosted: Thu 30 Nov '06 13:14    Post subject: Reply with quote

It's not an issue Smile mod_fcgid try to stop php process with sending an event first, if php process do not quit in time, mod_fcgid just kill the process. It's OK, with MaxRequestsPerProcess 500 it happens not so often here.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> How-to's & Documentation & Tips
Page 1 of 1